Skip to content

Commit

Permalink
Merge pull request #487 from OP-TED/feature/TED-1401
Browse files Browse the repository at this point in the history
Add repository_name param for github package downloader
  • Loading branch information
CaptainOfHacks authored Jul 4, 2023
2 parents c3a866a + 0ff927d commit 61f8d9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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}"
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down

0 comments on commit 61f8d9c

Please sign in to comment.