From 5b8f966d8bf8e92f4f0274d724cdfd2c6bdea4f8 Mon Sep 17 00:00:00 2001 From: Nathan Freeman Date: Wed, 18 Oct 2023 12:48:51 -0500 Subject: [PATCH] TemplateRepository converts url into a directory --- src/engine/src/helpers/TemplateRepository.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/engine/src/helpers/TemplateRepository.py b/src/engine/src/helpers/TemplateRepository.py index 6a634f3a..e8de861d 100644 --- a/src/engine/src/helpers/TemplateRepository.py +++ b/src/engine/src/helpers/TemplateRepository.py @@ -1,8 +1,11 @@ -import os,json +import os, json + +from urllib.parse import urlparse from .GitCacheService import GitCacheService from owe_python_sdk.schema import Uses + class TemplateRepository: def __init__(self, cache_dir: str): # Clone git repository specified on the pipeline.uses if exists @@ -12,8 +15,7 @@ def __init__(self, cache_dir: str): def get_by_uses(self, uses: Uses): self.git_cache_service.add_or_update( uses.source.url, - # NOTE Using the url as the directory to clone into is intentional - uses.source.url + self._url_to_directory(uses.source.url) ) template_root_dir = os.path.join(self.cache_dir, uses.source.url) @@ -34,4 +36,13 @@ def get_by_uses(self, uses: Uses): except Exception as e: raise Exception(f"Templating configuration Error (owe-config.json): {str(e)}") - return template \ No newline at end of file + return template + + def _url_to_directory(self, url): + parsed_url = urlparse(url) + directory = os.path.join( + parsed_url.hostname, + *[part.lstrip("/") for part in parsed_url.path.split("/")] + ) + + return directory \ No newline at end of file