add error handling for release_id parsing
This commit is contained in:
parent
e0150e6fcc
commit
a876fdc799
3 changed files with 30 additions and 5 deletions
|
@ -62,7 +62,7 @@ class ReleaseService:
|
||||||
self.git_api.push_follow_tags()
|
self.git_api.push_follow_tags()
|
||||||
|
|
||||||
def publish_artifacts(self, release: Release):
|
def publish_artifacts(self, release: Release):
|
||||||
release_response = json.loads(
|
release_id = self.__parse_forgejo_release_id__(
|
||||||
self.artifact_deployment_api.create_forgejo_release(
|
self.artifact_deployment_api.create_forgejo_release(
|
||||||
release.forgejo_release_api_endpoint(),
|
release.forgejo_release_api_endpoint(),
|
||||||
release.version.to_string(),
|
release.version.to_string(),
|
||||||
|
@ -73,12 +73,16 @@ class ReleaseService:
|
||||||
self.artifact_deployment_api.calculate_checksums(artifact_path)
|
self.artifact_deployment_api.calculate_checksums(artifact_path)
|
||||||
self.artifact_deployment_api.add_asset_to_release(
|
self.artifact_deployment_api.add_asset_to_release(
|
||||||
"todo",
|
"todo",
|
||||||
release_response["id"],
|
release_id,
|
||||||
"todo",
|
"todo",
|
||||||
"todo",
|
"todo",
|
||||||
release.release_artifact_token,
|
release.release_artifact_token,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __parse_forgejo_release_id__(self, release_response: str) -> int:
|
||||||
|
parsed = json.loads(release_response)
|
||||||
|
return parsed["id"]
|
||||||
|
|
||||||
def __set_version_and_commit__(
|
def __set_version_and_commit__(
|
||||||
self, version: Version, build_file_ids: List[str], message: str
|
self, version: Version, build_file_ids: List[str], message: str
|
||||||
):
|
):
|
||||||
|
|
|
@ -218,13 +218,13 @@ class ArtifactDeploymentApi:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.execution_api = ExecutionApi()
|
self.execution_api = ExecutionApi()
|
||||||
|
|
||||||
def create_forgejo_release(self, target_url: str, tag: str, token: str):
|
def create_forgejo_release(self, api_endpoint_url: str, tag: str, token: str):
|
||||||
return self.execution_api.execute_secure(
|
return self.execution_api.execute_secure(
|
||||||
f'curl -X "POST" "{target_url}" '
|
f'curl -X "POST" "{api_endpoint_url}" '
|
||||||
+ '-H "accept: application/json" -H "Content-Type: application/json" '
|
+ '-H "accept: application/json" -H "Content-Type: application/json" '
|
||||||
+ f'-d "{{ "body": "Provides files for release {tag} Attention: The "Source Code"-files below are not up-to-date!", "tag_name": "{tag}"}}" ' # noqa: E501
|
+ f'-d "{{ "body": "Provides files for release {tag} Attention: The "Source Code"-files below are not up-to-date!", "tag_name": "{tag}"}}" ' # noqa: E501
|
||||||
+ f'-H "Authorization: token {token}"',
|
+ f'-H "Authorization: token {token}"',
|
||||||
sanitized_command=f'curl -X "POST" "{target_url}" '
|
sanitized_command=f'curl -X "POST" "{api_endpoint_url}" '
|
||||||
+ '-H "accept: application/json" -H "Content-Type: application/json" '
|
+ '-H "accept: application/json" -H "Content-Type: application/json" '
|
||||||
+ f'-d "{{ "body": "Provides files for release {tag} Attention: The "Source Code"-files below are not up-to-date!", "tag_name": "{tag}"}}" ',
|
+ f'-d "{{ "body": "Provides files for release {tag} Attention: The "Source Code"-files below are not up-to-date!", "tag_name": "{tag}"}}" ',
|
||||||
) # noqa: E501
|
) # noqa: E501
|
||||||
|
|
|
@ -40,3 +40,24 @@ def test_sould_publish_artifacts():
|
||||||
release = devops.mixins[MixinType.RELEASE]
|
release = devops.mixins[MixinType.RELEASE]
|
||||||
sut.publish_artifacts(release)
|
sut.publish_artifacts(release)
|
||||||
assert 2345 == mock.add_asset_to_release_id
|
assert 2345 == mock.add_asset_to_release_id
|
||||||
|
|
||||||
|
def test_sould_throw_exception_if_there_was_an_error_in_publish_artifacts():
|
||||||
|
devops = build_devops(
|
||||||
|
{
|
||||||
|
"release_artifacts": ["target/art"],
|
||||||
|
"release_artifact_server_url": "http://repo.test/",
|
||||||
|
"release_organisation": "orga",
|
||||||
|
"release_repository_name": "repo",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
release = devops.mixins[MixinType.RELEASE]
|
||||||
|
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
mock = ArtifactDeploymentApiMock(release='')
|
||||||
|
sut = ReleaseService(GitApiMock(), mock, BuildFileRepositoryMock())
|
||||||
|
sut.publish_artifacts(release)
|
||||||
|
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
mock = ArtifactDeploymentApiMock(release='{"message": "there was an error", "url":"some-url"}')
|
||||||
|
sut = ReleaseService(GitApiMock(), mock, BuildFileRepositoryMock())
|
||||||
|
sut.publish_artifacts(release)
|
||||||
|
|
Loading…
Reference in a new issue