From 1e581c05b2b5e706b91d9d2b2e4f50c92a4a0c7a Mon Sep 17 00:00:00 2001 From: Dragos0000 Date: Thu, 18 Apr 2024 12:57:52 +0100 Subject: [PATCH] removal of GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME variable --- ted_sws/__init__.py | 3 --- .../adapters/github_package_downloader.py | 10 +++++++++- .../test_github_mapping_suite_package_downloader.py | 10 +++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ted_sws/__init__.py b/ted_sws/__init__.py index a8895b01b..ac434fda8 100644 --- a/ted_sws/__init__.py +++ b/ted_sws/__init__.py @@ -145,9 +145,6 @@ class GitHubArtefacts: def GITHUB_TED_SWS_ARTEFACTS_URL(self, config_value: str) -> str: return config_value - @env_property(config_resolver_class=AirflowAndEnvConfigResolver, default_value="ted-rdf-mapping") - def GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME(self, config_value: str) -> str: - return config_value class API: diff --git a/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py b/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py index 51cb418a9..8d63c17f2 100644 --- a/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py +++ b/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py @@ -8,6 +8,14 @@ MAPPINGS_DIR_NAME = "mappings" +def get_repo_name_from_repo_url(repository_url: str) -> str: + """ + This method will extract the name of the repository from a repository URL + """ + url_path = pathlib.PurePosixPath(repository_url) + return url_path.stem + + class MappingSuitePackageDownloaderABC(abc.ABC): """ This class is intended to download mapping_suite_package from external resources. @@ -35,7 +43,7 @@ def __init__(self, github_repository_url: str, branch_or_tag_name: str): """ self.github_repository_url = github_repository_url self.branch_or_tag_name = branch_or_tag_name - self.repository_name = config.GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME + self.repository_name = get_repo_name_from_repo_url(repository_url=github_repository_url) def download(self, output_mapping_suite_package_path: pathlib.Path) -> str: """ diff --git a/tests/e2e/mapping_suite_processor/test_github_mapping_suite_package_downloader.py b/tests/e2e/mapping_suite_processor/test_github_mapping_suite_package_downloader.py index ca7f37aba..d339ddabc 100644 --- a/tests/e2e/mapping_suite_processor/test_github_mapping_suite_package_downloader.py +++ b/tests/e2e/mapping_suite_processor/test_github_mapping_suite_package_downloader.py @@ -1,6 +1,7 @@ import pathlib from ted_sws import config -from ted_sws.mapping_suite_processor.adapters.github_package_downloader import GitHubMappingSuitePackageDownloader +from ted_sws.mapping_suite_processor.adapters.github_package_downloader import GitHubMappingSuitePackageDownloader, \ + get_repo_name_from_repo_url from tests.e2e.mapping_suite_processor import MAPPING_SUITE_PACKAGE_NAME @@ -11,3 +12,10 @@ def test_github_mapping_suite_package_downloader(tmpdir): mapping_suite_package_downloader.download(output_mapping_suite_package_path=tmp_dir_path) mapping_suite_package_path = tmp_dir_path / MAPPING_SUITE_PACKAGE_NAME assert mapping_suite_package_path.is_dir() + + +def test_get_repo_name_from_repo_url(): + repo_url = "https://github.com/OP-TED/ted-rdf-mapping.git" + repo_name = get_repo_name_from_repo_url(repository_url=repo_url) + assert repo_name == "ted-rdf-mapping" + assert isinstance(repo_name, str)