Skip to content

Commit

Permalink
TemplateRepository converts url into a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
nathandf committed Oct 18, 2023
1 parent 3d4a262 commit 5b8f966
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/engine/src/helpers/TemplateRepository.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
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

0 comments on commit 5b8f966

Please sign in to comment.