Skip to content

Commit 6741eaa

Browse files
committed
Improve VCS url splits #755
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 8186fa1 commit 6741eaa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/packagedcode/utils.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015 nexB Inc. and others. All rights reserved.
2+
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
33
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
44
# The ScanCode software is licensed under the Apache License version 2.0.
55
# Data generated with ScanCode require an acknowledgment.
@@ -75,8 +75,12 @@ def parse_repo_url(repo_url):
7575
return repo_url
7676

7777
if repo_url.startswith('git@'):
78-
left, right = repo_url.split('@', 1)
79-
host, repo = right.split(':', 1)
78+
left, _, right = repo_url.partition('@')
79+
if ':' in repo_url:
80+
host, _, repo = right.partition(':')
81+
else:
82+
# [email protected]/Filirom1/npm2aur.git
83+
host, _, repo = right.partition('/')
8084
if any(h in host for h in ['github', 'bitbucket', 'gitlab']):
8185
return 'https://%(host)s/%(repo)s' % locals()
8286
else:
@@ -89,7 +93,7 @@ def parse_repo_url(repo_url):
8993
'gitlab': 'https://gitlab.com/%(repo)s',
9094
'gist': 'https://gist.github.com/%(repo)s',
9195
}
92-
hoster, repo = repo_url.split(':', 1)
96+
hoster, _, repo = repo_url.partition(':')
9397
return hoster_urls[hoster] % locals()
9498
elif len(repo_url.split('/')) == 2:
9599
# implicit github

tests/packagedcode/test_package_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ def test_parse_repo_url_13(self):
101101
test = '[email protected]:foo/private.git'
102102
expected = 'https://gitlab.com/foo/private.git'
103103
assert expected == parse_repo_url(test)
104+
105+
def test_parse_git_repo_url_without_slash_slash(self):
106+
test = '[email protected]/Filirom1/npm2aur.git'
107+
expected = 'https://github.com/Filirom1/npm2aur.git'
108+
assert expected == parse_repo_url(test)

0 commit comments

Comments
 (0)