Skip to content

Commit 1240512

Browse files
committed
Fix wrong handling of GitHub repository URLs with "git"
When you have a URL like 'https://github.com/suse-edge/suse-edge.github.io.git' the splitting mechanism splitted at `.git` which gave wrong results. Using `.rsplit('.git', 1)` instead of `.split('.git')` fixed the issue.
1 parent 0e72991 commit 1240512

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/docbuild/models/repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, value: str) -> None:
7979

8080
if 'https://' in value or 'http://' in value:
8181
parsed_original = urlparse(value)
82-
name = parsed_original.path.strip('/').lower().split('.git')[0]
82+
name = parsed_original.path.strip('/').lower().rsplit('.git', 1)[0]
8383
name = name.rstrip('/')
8484
url = f'{parsed_original.scheme}://{parsed_original.netloc}/{name}.git'
8585
host = f'{parsed_original.scheme}://{parsed_original.netloc}'
@@ -103,7 +103,7 @@ def __init__(self, value: str) -> None:
103103

104104
elif '/' in value:
105105
value = value.lower()
106-
name = value.split('.git')[0].rstrip('/')
106+
name = value.rsplit('.git', 1)[0].rstrip('/')
107107
url = f'{self.DEFAULT_HOST}/{name}.git'
108108
surl = f'gh://{name}'
109109

tests/models/test_repo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ def repo_url() -> str:
2323
('https://github.com/org/repo', 'org/repo', 'https://github.com/org/repo.git'),
2424
# 4
2525
('https://github.com/org/repo/', 'org/repo', 'https://github.com/org/repo.git'),
26+
# 5
27+
(
28+
'https://github.com/ORG/repo_git.git/',
29+
'org/repo_git',
30+
'https://github.com/org/repo_git.git',
31+
),
2632
],
2733
)
2834
def test_repo_https(input_value, name, url):
@@ -42,6 +48,8 @@ def test_repo_https(input_value, name, url):
4248
('[email protected]:org/repo', 'org/repo', 'https://github.com/org/repo.git'),
4349
# 4
4450
('[email protected]:org/repo/', 'org/repo', 'https://github.com/org/repo.git'),
51+
# 5
52+
('[email protected]:org/repo_git/', 'org/repo_git', 'https://github.com/org/repo_git.git'),
4553
],
4654
)
4755
def test_repo_ssh(input_value, name, url):
@@ -61,6 +69,8 @@ def test_repo_ssh(input_value, name, url):
6169
('gh://org/repo/', 'org/repo', 'https://github.com/org/repo.git'),
6270
# 4
6371
('gh://org/repo.git', 'org/repo', 'https://github.com/org/repo.git'),
72+
# 5
73+
('gh://ORG/repo_git.git', 'org/repo_git', 'https://github.com/org/repo_git.git'),
6474
],
6575
)
6676
def test_repo_abbreviation(input_value, name, url):
@@ -86,6 +96,8 @@ def test_repo_abbreviation(input_value, name, url):
8696
('gh://org/repo/', 'gh://org/repo'),
8797
# 7
8898
('gh://org/repo.git', 'gh://org/repo'),
99+
# 8
100+
('gh://ORG/repo_git.git', 'gh://org/repo_git'),
89101
],
90102
)
91103
def test_repo_with_surl(input_value, surl):
@@ -105,6 +117,9 @@ def test_repo_with_unknown_abbreviation():
105117
('org/repo', 'org/repo', 'https://github.com/org/repo.git'),
106118
# 2
107119
('ORG/repo', 'org/repo', 'https://github.com/org/repo.git'),
120+
# 3
121+
('org/repo_git.git', 'org/repo_git', 'https://github.com/org/repo_git.git'),
122+
# 4
108123
],
109124
)
110125
def test_repo_abbreviated(input_value, name, url):

0 commit comments

Comments
 (0)