Merge "Improve Pegleg repository name parsing"

This commit is contained in:
Zuul 2018-10-17 13:54:43 +00:00 committed by Gerrit Code Review
commit 920068260d
2 changed files with 31 additions and 2 deletions

View File

@ -376,7 +376,14 @@ def repo_name(repo_url_or_path):
if config_reader.has_section(section):
repo_url = config_reader.get_value(section, option)
try:
return repo_url.split('/')[-1].split('.git')[0]
# Support repos that end with or without '.git'
if repo_url.endswith('.git'):
return repo_url.split('/')[-1].split('.git')[0]
else:
if repo_url.endswith('/'):
return repo_url.split('/')[-2]
else:
return repo_url.split('/')[-1]
except Exception:
raise exceptions.GitConfigException(repo_url=repo_url_or_path)

View File

@ -540,7 +540,18 @@ def test_is_repository_negative():
@pytest.mark.skipif(
not is_connected(), reason='git clone requires network connectivity.')
def test_repo_name():
def test_repo_name_ending_in_git():
url = "http://github.com/openstack/airship-pegleg.git"
git_dir = git.git_handler(url, ref="master")
_validate_git_clone(git_dir)
name = git.repo_name(git_dir)
expected = "airship-pegleg"
assert name == expected
@pytest.mark.skipif(
not is_connected(), reason='git clone requires network connectivity.')
def test_repo_name_not_ending_in_git_and_no_fwd_slash_at_end():
url = "http://github.com/openstack/airship-pegleg"
git_dir = git.git_handler(url, ref="master")
_validate_git_clone(git_dir)
@ -549,6 +560,17 @@ def test_repo_name():
expected = "airship-pegleg"
assert name == expected
@pytest.mark.skipif(
not is_connected(), reason='git clone requires network connectivity.')
def test_repo_name_not_ending_in_git_with_fwd_slash_at_end():
url = "http://github.com/openstack/airship-pegleg/"
git_dir = git.git_handler(url, ref="master")
_validate_git_clone(git_dir)
name = git.repo_name(git_dir)
expected = "airship-pegleg"
assert name == expected
@pytest.mark.skipif(
not is_connected(), reason='git clone requires network connectivity.')