From 5f5743354ca34865be0228b1980c9e5566a64820 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 11 Aug 2023 15:08:21 +0200 Subject: [PATCH] wip: calculate forgejo_release_api_endpoint --- src/main/python/ddadevops/domain/release.py | 8 ++++ src/test/python/domain/helper.py | 4 ++ src/test/python/domain/test_release.py | 46 +++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/src/main/python/ddadevops/domain/release.py b/src/main/python/ddadevops/domain/release.py index ae3720b..b8c64ec 100644 --- a/src/main/python/ddadevops/domain/release.py +++ b/src/main/python/ddadevops/domain/release.py @@ -24,6 +24,9 @@ class Release(Validateable): "release_secondary_build_files", [] ) self.version = version + self.release_artifact_server_url = inp.get("release_artifact_server_url") + self.release_organisation = inp.get("release_organisation") + self.release_repository_name = inp.get("release_repository_name") def update_release_type(self, release_type: ReleaseType): self.release_type = release_type @@ -63,3 +66,8 @@ class Release(Validateable): result = [self.release_primary_build_file] result += self.release_secondary_build_files return result + + def forgejo_release_api_endpoint(self): + if self.release_artifact_server_url == None or self.release_organisation == None or self.release_repository_name == None: + raise RuntimeError("when doing artifact release, release_artifact_server_url, release_organisation, release_repository_name may not be None.") + return f"{self.release_artifact_server_url}/api/v1/repos/{self.release_organisation}/{self.release_repository_name}/releases" diff --git a/src/test/python/domain/helper.py b/src/test/python/domain/helper.py index 74a67d5..31a8911 100644 --- a/src/test/python/domain/helper.py +++ b/src/test/python/domain/helper.py @@ -53,6 +53,10 @@ def devops_config(overrides: dict) -> dict: "release_current_branch": "my_feature", "release_primary_build_file": "./package.json", "release_secondary_build_file": [], + "release_artifacts": [], + "release_artifact_server_url": None, + "release_organisation": None, + "release_repository_name": None, "credentials_mappings": [ { "gopass_path": "a/path", diff --git a/src/test/python/domain/test_release.py b/src/test/python/domain/test_release.py index c23bc39..48b520a 100644 --- a/src/test/python/domain/test_release.py +++ b/src/test/python/domain/test_release.py @@ -1,3 +1,4 @@ +import pytest from pybuilder.core import Project from pathlib import Path from src.main.python.ddadevops.domain import ( @@ -61,3 +62,48 @@ def test_sould_calculate_build_files(): Version.from_str("1.3.1-SNAPSHOT", "SNAPSHOT"), ) assert ["project.clj", "package.json"] == sut.build_files() + + +def test_should_calculate_forgejo_release_api_endpoint(): + sut = Release( + devops_config( + { + "release_artifact_server_url": "https://repo.prod.meissa.de", + "release_organisation": "meissa", + "release_repository_name": "provs", + } + ), + Version.from_str("1.3.1-SNAPSHOT", "SNAPSHOT"), + ) + assert ( + "https://repo.prod.meissa.de/api/v1/repos/meissa/provs/releases" + == sut.forgejo_release_api_endpoint() + ) + + sut = Release( + devops_config( + { + "release_artifact_server_url": "https://repo.prod.meissa.de/", + "release_organisation": "/meissa/", + "release_repository_name": "provs", + } + ), + Version.from_str("1.3.1-SNAPSHOT", "SNAPSHOT"), + ) + assert ( + "https://repo.prod.meissa.de/api/v1/repos/meissa/provs/releases" + == sut.forgejo_release_api_endpoint() + ) + + with pytest.raises(Exception): + sut = Release( + devops_config( + { + "release_artifact_server_url": "https://repo.prod.meissa.de", + "release_organisation": None, + "release_repository_name": "provs", + } + ), + Version.from_str("1.3.1-SNAPSHOT", "SNAPSHOT"), + ) + sut.forgejo_release_api_endpoint()