Skip to content

Commit

Permalink
fix: manage subgroups in git remote url
Browse files Browse the repository at this point in the history
This is a necessary fix for gitlab integration.
For an illustration of the need and use for this fix, test was edited.

Fixes #139
Fixes #140
  • Loading branch information
Benjamin Gras authored and relekang committed Aug 30, 2019
1 parent ef96209 commit 4b11875
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion semantic_release/vcs_helpers.py
Expand Up @@ -85,7 +85,7 @@ def get_repository_owner_and_name() -> Tuple[str, str]:

check_repo()
url = repo.remote('origin').url
parts = re.search(r'([^/:]+)/([^/]+).git$', url)
parts = re.search(r'[:/]([^\.:]+)/([^/]+).git$', url)
if not parts:
raise HvcsRepoParseError
debug('get_repository_owner_and_name', parts)
Expand Down
15 changes: 12 additions & 3 deletions tests/test_vcs_helpers.py
Expand Up @@ -48,9 +48,18 @@ def test_push_new_version_with_custom_branch(mock_git):
])


def test_get_repository_owner_and_name():
assert get_repository_owner_and_name()[0] == 'relekang'
assert get_repository_owner_and_name()[1] == 'python-semantic-release'
@pytest.mark.parametrize("origin_url,expected_result", [
("git@github.com:group/project.git", ("group", "project")),
("git@gitlab.example.com:group/project.git", ("group", "project")),
("git@gitlab.example.com:group/subgroup/project.git", ("group/subgroup", "project")),
("https://github.com/group/project.git", ("group", "project")),
("https://gitlab.example.com/group/subgroup/project.git", ("group/subgroup", "project")),
])
def test_get_repository_owner_and_name(mocker, origin_url, expected_result):
class FakeRemote:
url = origin_url
mocker.patch('git.repo.base.Repo.remote', return_value=FakeRemote())
assert get_repository_owner_and_name() == expected_result


def test_get_current_head_hash(mocker):
Expand Down

0 comments on commit 4b11875

Please sign in to comment.