Skip to content

Commit

Permalink
feat: new flag -pms or --project-mainline-state
Browse files Browse the repository at this point in the history
  • Loading branch information
t-graf committed Jul 19, 2024
1 parent ea98c5e commit 88dc948
Show file tree
Hide file tree
Showing 7 changed files with 807 additions and 789 deletions.
8 changes: 6 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

# CaPyCli - Clearing Automation Python Command Line Tool for SW360

## NEXT
## 2.5.0 (2024-07-19)

* Fixed an error when creating an SBOM from a project on SW360 when this project
contains a component with more than on package-url.
contains a component with more than one package-url.
* Fixed an issues when getting invalid package-urls.
* New flag `-pms` or `--project-mainline-state` to specify which project mainline state
should be used for releases of a new project created by `project create`.
* Dependency updates.

## 2.4.0 (2024-04-22)

Expand Down
9 changes: 8 additions & 1 deletion capycli/main/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def register_options(self) -> None:
self.parser.add_argument(
"-old-version",
dest="old_version",
help="previous version "
help="previous version"
)

self.parser.add_argument(
Expand Down Expand Up @@ -400,6 +400,13 @@ def register_options(self) -> None:
help="force an error exit code in case of visual errors",
)

self.parser.add_argument(
"-pms",
"--project-mainline-state",
dest="project_mainline_state",
help="project mainline state for releases in a newly created project",
)

def read_config(self, filename: str = "", config_string: str = "") -> Dict[str, Any]:
"""
Read configuration from string or config file.
Expand Down
29 changes: 19 additions & 10 deletions capycli/project/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreateProject(capycli.common.script_base.ScriptBase):

def __init__(self, onlyUpdateProject: bool = False) -> None:
self.onlyUpdateProject = onlyUpdateProject
self.project_mainline_state: str = ""

def bom_to_release_list(self, sbom: Bom) -> List[str]:
"""Creates a list with linked releases"""
Expand Down Expand Up @@ -144,6 +145,11 @@ def bom_to_release_list_new(self, sbom: Bom) -> Dict[str, Any]:
"""Creates a list with linked releases for a NEW project"""
linkedReleases: Dict[str, Any] = {}

target_state = "SPECIFIC"
if self.project_mainline_state:
target_state = self.project_mainline_state

print_text(f" New project releases will have state {target_state}")
for cx_comp in sbom.components:
rid = CycloneDxSupport.get_property_value(cx_comp, CycloneDxSupport.CDX_PROP_SW360ID)
if not rid:
Expand All @@ -153,7 +159,7 @@ def bom_to_release_list_new(self, sbom: Bom) -> Dict[str, Any]:
continue

linkedRelease: Dict[str, Any] = {}
linkedRelease["mainlineState"] = "SPECIFIC"
linkedRelease["mainlineState"] = target_state
linkedRelease["releaseRelation"] = "DYNAMICALLY_LINKED"
linkedRelease["setMainlineState"] = True
linkedRelease["setReleaseRelation"] = True
Expand Down Expand Up @@ -267,15 +273,16 @@ def run(self, args: Any) -> None:
print("usage: CaPyCli project create -i bom.json -o bom_created.json [-source <folder>]")
print("")
print("optional arguments:")
print(" -i INPUTFILE, bom file to read from (JSON)")
print(" -t SW360_TOKEN, use this token for access to SW360")
print(" -oa, --oauth2 this is an oauth2 token")
print(" -url SW360_URL use this URL for access to SW360")
print(" -name NAME, --name NAME name of the project")
print(" -version VERSION, version of the project")
print(" -id PROJECT_ID SW360 id of the project, supersedes name and version parameters")
print(" -old-version ")
print(" -source projectinfo.json additional information about the project to be created")
print(" -i INPUTFILE, bom file to read from (JSON)")
print(" -t SW360_TOKEN, use this token for access to SW360")
print(" -oa, --oauth2 this is an oauth2 token")
print(" -url SW360_URL use this URL for access to SW360")
print(" -name NAME, --name NAME name of the project")
print(" -version VERSION, version of the project")
print(" -id PROJECT_ID SW360 id of the project, supersedes name and version parameters")
print(" -old-version previous version")
print(" -source projectinfo.json additional information about the project to be created")
print(" -pms project mainline state for releases in a newly created project")
return

if not args.inputfile:
Expand Down Expand Up @@ -346,6 +353,8 @@ def run(self, args: Any) -> None:
attachments = info['_embedded']['sw360:attachments']
info.pop('_embedded')

self.project_mainline_state = args.project_mainline_state

if self.project_id:
print("Updating project...")
try:
Expand Down
Loading

0 comments on commit 88dc948

Please sign in to comment.