From f71c2e38f8b7daee674a04f9abd32df233fcd489 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Wed, 26 Sep 2018 03:16:51 +0100 Subject: [PATCH] fix: Support cloning URLs that end in .git This patch set adds support for passing in URLs ending in .git via the --site-repository (-r) flag, e.g.: pegleg site -r https://github.com/openstack/project.git@foo [...] Unit test added to validate behavior. Change-Id: If822ed195f07dc25e0590e42d046730632fdaafd --- pegleg/engine/repository.py | 2 ++ tests/unit/test_cli.py | 23 +++++++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/pegleg/engine/repository.py b/pegleg/engine/repository.py index 25af8ac5..f60fba97 100644 --- a/pegleg/engine/repository.py +++ b/pegleg/engine/repository.py @@ -291,6 +291,8 @@ def _extract_repo_url_and_revision(repo_path_or_url): # extract revision from repo URL or path repo_url_or_path, revision = repo_path_or_url.rsplit('@', 1) revision = revision[:-1] if revision.endswith('/') else revision + if revision.endswith(".git"): + revision = revision[:-4] else: repo_url_or_path = repo_path_or_url except Exception: diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 1bd90412..de19e22d 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -82,6 +82,27 @@ class TestSiteCliActions(object): # are written out to sensibly named files like airship-treasuremap.yaml assert collected_files[0] == ("%s.yaml" % self.repo_name) + def test_collect_using_remote_repo_url_ending_with_dot_git(self): + """Validates collect action using a remote URL ending in .git.""" + # Scenario: + # + # 1) Create temporary save location + # 2) Collect into save location (should clone repo automatically) + # 3) Check that expected file name is there + + save_location = tempfile.mkdtemp() + repo_url = 'https://github.com/openstack/%s@%s.git' % (self.repo_name, + self.repo_rev) + result = self.runner.invoke( + cli.site, + ['-r', repo_url, 'collect', self.site_name, '-s', save_location]) + + collected_files = os.listdir(save_location) + + assert result.exit_code == 0 + assert len(collected_files) == 1 + assert collected_files[0] == ("%s.yaml" % self.repo_name) + def test_collect_using_local_path(self): """Validates collect action using a path to a local repo.""" # Scenario: @@ -101,6 +122,4 @@ class TestSiteCliActions(object): assert result.exit_code == 0 assert len(collected_files) == 1 - # Validates that site manifests collected from cloned repositories - # are written out to sensibly named files like airship-treasuremap.yaml assert collected_files[0] == ("%s.yaml" % self.repo_name)