Skip to content

Commit

Permalink
refactor(project CreateBom): make it unit-testable
Browse files Browse the repository at this point in the history
Split out bom conversion into own function so we can test it without
calling whole run() function.
  • Loading branch information
gernot-h committed Jul 12, 2023
1 parent 48b241c commit 7292828
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions capycli/project/create_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ def create_project_bom(self, project_id) -> list:

return bom

def create_project_cdx_bom(self, project_id) -> list:
bom = self.create_project_bom(project_id)

cdx_components = []
for item in bom:
cx_comp = LegacySupport.legacy_component_to_cdx(item)
cdx_components.append(cx_comp)

return cdx_components

def show_command_help(self):
print("\nusage: CaPyCli project createbom [options]")
print("Options:")
Expand Down Expand Up @@ -178,13 +188,7 @@ def run(self, args):
sys.exit(ResultCode.RESULT_COMMAND_ERROR)

if pid:
bom = self.create_project_bom(pid)

cdx_components = []
for item in bom:
cx_comp = LegacySupport.legacy_component_to_cdx(item)
cdx_components.append(cx_comp)

CaPyCliBom.write_simple_sbom(cdx_components, args.outputfile)
bom = self.create_project_cdx_bom(pid)
CaPyCliBom.write_simple_sbom(bom, args.outputfile)
else:
print_yellow(" No matching project found")

0 comments on commit 7292828

Please sign in to comment.