parse the release_id from create response

This commit is contained in:
Michael Jerger 2023-08-14 08:59:45 +02:00
parent b861087e9d
commit e0150e6fcc
4 changed files with 48 additions and 16 deletions

View file

@ -1,3 +1,4 @@
import json
from typing import List
from pathlib import Path
from ..infrastructure import GitApi, ArtifactDeploymentApi, BuildFileRepository
@ -61,16 +62,22 @@ class ReleaseService:
self.git_api.push_follow_tags()
def publish_artifacts(self, release: Release):
release_response = json.loads(
self.artifact_deployment_api.create_forgejo_release(
release.forgejo_release_api_endpoint(),
release.version.to_string(),
release.release_artifact_token,
)
)
for artifact_path in release.release_artifacts:
self.artifact_deployment_api.calculate_checksums(artifact_path)
self.artifact_deployment_api.create_forgejo_release(
release.forgejo_release_api_endpoint(),
release.version.to_string(),
release.release_artifact_token
)
# create release
# add artifacts to release
pass
self.artifact_deployment_api.add_asset_to_release(
"todo",
release_response["id"],
"todo",
"todo",
release.release_artifact_token,
)
def __set_version_and_commit__(
self, version: Version, build_file_ids: List[str], message: str

View file

@ -229,7 +229,7 @@ class ArtifactDeploymentApi:
+ f'-d "{{ "body": "Provides files for release {tag} Attention: The "Source Code"-files below are not up-to-date!", "tag_name": "{tag}"}}" ',
) # noqa: E501
def post_asset(
def add_asset_to_release(
self,
target_url: str,
release_id: str,

View file

@ -1,7 +1,7 @@
import pytest
from pathlib import Path
from src.main.python.ddadevops.domain import (
ReleaseType,
ReleaseType,
MixinType,
)
from src.test.python.domain.helper import (
@ -12,8 +12,11 @@ from src.test.python.domain.helper import (
)
from src.main.python.ddadevops.application import ReleaseService
def test_sould_update_release_type():
sut = ReleaseService(GitApiMock(), ArtifactDeploymentApiMock(), BuildFileRepositoryMock("build.py"))
sut = ReleaseService(
GitApiMock(), ArtifactDeploymentApiMock(), BuildFileRepositoryMock("build.py")
)
devops = build_devops({})
release = devops.mixins[MixinType.RELEASE]
sut.update_release_type(release, "MAJOR")
@ -21,3 +24,19 @@ def test_sould_update_release_type():
with pytest.raises(Exception):
sut.update_release_type(release, "NOT_EXISTING")
def test_sould_publish_artifacts():
mock = ArtifactDeploymentApiMock(release='{"id": 2345}')
sut = ReleaseService(GitApiMock(), mock, BuildFileRepositoryMock())
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]
sut.publish_artifacts(release)
assert 2345 == mock.add_asset_to_release_id

View file

@ -158,13 +158,19 @@ class GitApiMock:
class ArtifactDeploymentApiMock:
def __init__(self):
pass
def __init__(self, release=""):
self.release = release
self.create_forgejo_release_count = 0
self.add_asset_to_release_count = 0
self.add_asset_to_release_id = ""
def post_release(self, target_url: str, tag: str, token: str):
pass
def create_forgejo_release(self, target_url: str, tag: str, token: str):
self.create_forgejo_release_count += 1
return self.release
def post_asset(self, target_url: str, release_id: str, attachment: str, attachment_type: str, token: str):
def add_asset_to_release(self, target_url: str, release_id: str, attachment: str, attachment_type: str, token: str):
self.add_asset_to_release_count += 1
self.add_asset_to_release_id = release_id
pass
def calculate_checksums(self, build_path: str):