Skip to content

Commit e04a266

Browse files
authored
Merge pull request #7 from sw360/develop
Develop to master
2 parents bb0a249 + 117a412 commit e04a266

5 files changed

Lines changed: 63 additions & 7 deletions

File tree

ChangeLog.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# SW360 Base Library for Python
22

3+
## NEXT
4+
* new method `update_project_release_relationship`.
5+
* original get_health_status() endpoint URL has been restored by the SW360 team.
6+
37
## 1.1.0
4-
* New method `dulicate_project` to create a copy of an exisiting project.
8+
* New method `duplicate_project` to create a copy of an existing project.
59

610
## 1.0.0
711
* **New Features**:
812
* `get_projects_by_tag` added.
913
* `get_releases_by_name` added.
1014
* `get_all_vendors` added.
11-
* We have covered nearly all of the possibel REST API calls.
15+
* We have covered nearly all of the possible REST API calls.
1216
The library is successfully being used by multiple projects.
1317
Time to release version 1.0.0.
1418

CreateCoverageReport.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# -----------------------------------------
2+
# Run tests and create code coverage report
3+
# -----------------------------------------
4+
5+
# 2021-12-20, T. Graf
6+
7+
poetry run coverage run -m pytest
8+
poetry run coverage report -m --omit "*/site-packages/*.py"
9+
poetry run coverage html --omit "*/site-packages/*.py"
10+
11+
12+
# -----------------------------------
13+
# -----------------------------------

sw360/sw360_api.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2019-2021 Siemens AG
2+
# (c) 2019-2022 Siemens AG
33
# All Rights Reserved.
44
# Authors: thomas.graf@siemens.com, gernot.hillier@siemens.com
55
#
@@ -360,7 +360,7 @@ def get_projects_by_tag(self, tag):
360360
:rtype: list of JSON project objects
361361
:raises SW360Error: if there is a negative HTTP response
362362
"""
363-
full_url = self.url + "resource/api/projects?tag=" + tag
363+
full_url = self.url + "resource/api/projects?tag=" + tag + "&luceneSearch=true"
364364
resp = self.api_get(full_url)
365365
if not resp:
366366
return None
@@ -608,6 +608,45 @@ def duplicate_project(self, project_id: str, new_version: str):
608608

609609
raise SW360Error(response, url)
610610

611+
def update_project_release_relationship(self, project_id: str, release_id: str, new_state: str,
612+
new_relation: str, comment: str):
613+
"""Update the relationship for a specific release of a project
614+
615+
API endpoint PATCH /projects/{pid}/release{rid}
616+
617+
:param project_id: the id of the exisiting project
618+
:type project_id: string
619+
:param release_id: the id of the release to be requested
620+
:type release_id: string
621+
:param new_state: the new mainline state of the release, one of
622+
(OPEN, MAINLINE, SPECIFIC, PHASEOUT, DENIED)
623+
:type new_state: string
624+
:param new_relation: the new relation of the release, one of
625+
(CONTAINED, REFERRED, UNKNOWN, DYNAMICALLY_LINKED, STATICALLY_LINKED, SIDE_BY_SIDE, STANDALONE,
626+
INTERNAL_USE, OPTIONAL, TO_BE_REPLACED, CODE_SNIPPET)
627+
:type new_relation: string
628+
:param comment: a comment
629+
:type comment: string
630+
"""
631+
if not project_id:
632+
raise SW360Error(message="No project id provided!")
633+
634+
if not release_id:
635+
raise SW360Error(message="No release id provided!")
636+
637+
relation = {}
638+
relation["releaseRelation"] = new_relation
639+
relation["mainlineState"] = new_state
640+
relation["comment"] = comment
641+
642+
url = self.url + "resource/api/projects/" + project_id + "/release/" + release_id
643+
response = requests.patch(url, json=relation, headers=self.api_headers)
644+
645+
if response.ok:
646+
return response.json()
647+
648+
raise SW360Error(response, url)
649+
611650
# ----- Releases ---------------------------------------------------------
612651

613652
def get_release(self, release_id):

tests/test_sw360_health.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -------------------------------------------------------------------------------
2-
# (c) 2020 Siemens AG
2+
# (c) 2020-2022 Siemens AG
33
# All Rights Reserved.
44
# Author: thomas.graf@siemens.com
55
#

tests/test_sw360_projects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def test_get_projects_by_tag(self):
409409

410410
responses.add(
411411
responses.GET,
412-
url=self.MYURL + "resource/api/projects?tag=SI BP",
412+
url=self.MYURL + "resource/api/projects?tag=SI BP&luceneSearch=true",
413413
body='{"_embedded": {"sw360:projects": [{"name": "My Testproject", "externalIds": {"com.siemens.code.project.id": "13171"}}]}}', # noqa
414414
status=200,
415415
content_type="application/json",
@@ -427,7 +427,7 @@ def test_get_projects_by_tag_no_result(self):
427427

428428
responses.add(
429429
responses.GET,
430-
url=self.MYURL + "resource/api/projects?tag=SI",
430+
url=self.MYURL + "resource/api/projects?tag=SI&luceneSearch=true",
431431
body='{}',
432432
status=200,
433433
content_type="application/json",

0 commit comments

Comments
 (0)