Skip to content

Commit

Permalink
Improve VCS url splits #755
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Oct 1, 2017
1 parent 8186fa1 commit 6741eaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/packagedcode/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2015 nexB Inc. and others. All rights reserved.
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
# http://nexb.com and https:/nexB/scancode-toolkit/
# The ScanCode software is licensed under the Apache License version 2.0.
# Data generated with ScanCode require an acknowledgment.
Expand Down Expand Up @@ -75,8 +75,12 @@ def parse_repo_url(repo_url):
return repo_url

if repo_url.startswith('git@'):
left, right = repo_url.split('@', 1)
host, repo = right.split(':', 1)
left, _, right = repo_url.partition('@')
if ':' in repo_url:
host, _, repo = right.partition(':')
else:
# [email protected]/Filirom1/npm2aur.git
host, _, repo = right.partition('/')
if any(h in host for h in ['github', 'bitbucket', 'gitlab']):
return 'https://%(host)s/%(repo)s' % locals()
else:
Expand All @@ -89,7 +93,7 @@ def parse_repo_url(repo_url):
'gitlab': 'https://gitlab.com/%(repo)s',
'gist': 'https://gist.github.com/%(repo)s',
}
hoster, repo = repo_url.split(':', 1)
hoster, _, repo = repo_url.partition(':')
return hoster_urls[hoster] % locals()
elif len(repo_url.split('/')) == 2:
# implicit github
Expand Down
5 changes: 5 additions & 0 deletions tests/packagedcode/test_package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ def test_parse_repo_url_13(self):
test = '[email protected]:foo/private.git'
expected = 'https://gitlab.com/foo/private.git'
assert expected == parse_repo_url(test)

def test_parse_git_repo_url_without_slash_slash(self):
test = '[email protected]/Filirom1/npm2aur.git'
expected = 'https:/Filirom1/npm2aur.git'
assert expected == parse_repo_url(test)

0 comments on commit 6741eaa

Please sign in to comment.