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 15d1edf1..b02a50a7 100644 --- a/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py +++ b/ted_sws/mapping_suite_processor/adapters/github_package_downloader.py @@ -6,7 +6,7 @@ from urllib.parse import urlparse GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME = "ted-rdf-mapping" -GITHUB_TED_SWS_ARTEFACTS_MAPPINGS_PATH = f"{GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME}/mappings" +MAPPINGS_DIR_NAME = "mappings" class MappingSuitePackageDownloaderABC(abc.ABC): @@ -29,16 +29,18 @@ class GitHubMappingSuitePackageDownloader(MappingSuitePackageDownloaderABC): """ def __init__(self, github_repository_url: str, branch_or_tag_name: str, - github_username: str = None, github_token: str = None): + github_username: str = None, github_token: str = None, github_repository_name: str = None): """ Option can be a branch or tag, not both :param github_repository_url: :param branch_or_tag_name: :param github_username: :param github_token: + :param github_repository_name: """ self.github_repository_url = github_repository_url self.branch_or_tag_name = branch_or_tag_name + self.github_repository_name = github_repository_name or GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME if github_username and github_token: parsed_url = urlparse(github_repository_url) self.github_repository_url = f"{parsed_url.scheme}://{github_username}:{github_token}@{parsed_url.netloc}{parsed_url.path}" @@ -70,7 +72,7 @@ def get_git_head_hash(git_repository_path: pathlib.Path) -> str: stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) git_last_commit_hash = get_git_head_hash( - git_repository_path=temp_dir_path / GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME) - downloaded_tmp_mapping_suite_path = temp_dir_path / GITHUB_TED_SWS_ARTEFACTS_MAPPINGS_PATH + git_repository_path=temp_dir_path / self.github_repository_name) + downloaded_tmp_mapping_suite_path = temp_dir_path / self.github_repository_name / MAPPINGS_DIR_NAME shutil.copytree(downloaded_tmp_mapping_suite_path, output_mapping_suite_package_path, dirs_exist_ok=True) return git_last_commit_hash diff --git a/ted_sws/mapping_suite_processor/services/conceptual_mapping_processor.py b/ted_sws/mapping_suite_processor/services/conceptual_mapping_processor.py index 49c41743..2655a8d4 100644 --- a/ted_sws/mapping_suite_processor/services/conceptual_mapping_processor.py +++ b/ted_sws/mapping_suite_processor/services/conceptual_mapping_processor.py @@ -75,7 +75,8 @@ def mapping_suite_processor_from_github_expand_and_load_package_in_mongo_db(mong branch_or_tag_name: str = None, github_repository_url: str = None, github_username: str = None, - github_token: str = None + github_token: str = None, + github_repository_name: str = None ) -> List[str]: """ This feature is intended to download a mapping_suite_package from GitHub and process it for upload to MongoDB. @@ -86,13 +87,14 @@ def mapping_suite_processor_from_github_expand_and_load_package_in_mongo_db(mong :param load_test_data: :param github_username: :param github_token: + :param github_repository_name: :return: """ branch_or_tag_name = branch_or_tag_name if branch_or_tag_name else DEFAULT_BRANCH_NAME github_repository_url = github_repository_url if github_repository_url else config.GITHUB_TED_SWS_ARTEFACTS_URL mapping_suite_package_downloader = GitHubMappingSuitePackageDownloader( github_repository_url=github_repository_url, branch_or_tag_name=branch_or_tag_name, - github_username=github_username, github_token=github_token) + github_username=github_username, github_token=github_token, github_repository_name=github_repository_name) with tempfile.TemporaryDirectory() as tmp_dir: tmp_dir_path = pathlib.Path(tmp_dir) git_last_commit_hash = mapping_suite_package_downloader.download(output_mapping_suite_package_path=tmp_dir_path)