Skip to content

Commit df14210

Browse files
committed
Merge remote-tracking branch 'upstream/429-testcase-utils-packagedcode' into develop
2 parents 5aefc56 + 17dbefa commit df14210

File tree

2 files changed

+79
-10
lines changed

2 files changed

+79
-10
lines changed

src/packagedcode/utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,26 @@ def parse_repo_url(repo_url):
6868
[email protected]:foo/private.git
6969
"""
7070

71-
# TODO: Improve this and use outside of NPMs
7271
is_vcs_url = repo_url.startswith(VCS_URLS)
7372
if is_vcs_url:
74-
# TODO: ensure the .git suffix is present if needed
73+
# TODO: If we match http and https, we may should add more check in case if the url is not a repo one.
74+
# For example, check the domain name in the url...
7575
return repo_url
7676

7777
if repo_url.startswith('git@'):
7878
left, right = repo_url.split('@', 1)
7979
host, repo = right.split(':', 1)
80-
# may be we should
8180
if any(h in host for h in ['github', 'bitbucket', 'gitlab']):
8281
return 'https://%(host)s/%(repo)s' % locals()
8382
else:
8483
return repo_url
8584

86-
if repo_url.startswith('gist:'):
87-
return repo_url
88-
89-
elif repo_url.startswith(('bitbucket:', 'gitlab:', 'github:')):
85+
if repo_url.startswith(('bitbucket:', 'gitlab:', 'github:', 'gist:')):
9086
hoster_urls = {
91-
'bitbucket:': 'https://bitbucket.org/%(repo)s',
92-
'github:': 'https://github.com/%(repo)s',
93-
'gitlab:': 'https://gitlab.com/%(repo)s',
87+
'bitbucket': 'https://bitbucket.org/%(repo)s',
88+
'github': 'https://github.com/%(repo)s',
89+
'gitlab': 'https://gitlab.com/%(repo)s',
90+
'gist': 'https://gist.github.com/%(repo)s',
9491
}
9592
hoster, repo = repo_url.split(':', 1)
9693
return hoster_urls[hoster] % locals()

tests/packagedcode/test_utils.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
3+
# http://nexb.com and https://github.com/nexB/scancode-toolkit/
4+
# The ScanCode software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode require an acknowledgment.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# When you publish or redistribute any data created with ScanCode or any ScanCode
16+
# derivative work, you must accompany this data with the following acknowledgment:
17+
#
18+
# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
19+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
20+
# ScanCode should be considered or used as legal advice. Consult an Attorney
21+
# for any legal advice.
22+
# ScanCode is a free software code scanning tool from nexB Inc. and others.
23+
# Visit https://github.com/nexB/scancode-toolkit/ for support and download.
24+
25+
from __future__ import absolute_import
26+
from __future__ import print_function
27+
28+
import os.path
29+
30+
from commoncode.testcase import FileBasedTesting
31+
from packagedcode.utils import parse_repo_url
32+
33+
34+
class TestUtilsPi(FileBasedTesting):
35+
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
36+
37+
def test_parse_url(self):
38+
inputs = ['npm/npm',
39+
'gist:11081aaa281',
40+
'bitbucket:example/repo',
41+
'gitlab:another/repo',
42+
'expressjs/serve-static',
43+
'git://github.com/angular/di.js.git',
44+
'git://github.com/hapijs/boom',
45+
'[email protected]:balderdashy/waterline-criteria.git',
46+
'http://github.com/ariya/esprima.git',
47+
'http://github.com/isaacs/nopt',
48+
'https://github.com/chaijs/chai',
49+
'https://github.com/christkv/kerberos.git',
50+
'https://gitlab.com/foo/private.git',
51+
'[email protected]:foo/private.git'
52+
]
53+
results = []
54+
for input in inputs:
55+
results.append(parse_repo_url(input))
56+
expected = ['https://github.com/npm/npm',
57+
'https://gist.github.com/11081aaa281',
58+
'https://bitbucket.org/example/repo',
59+
'https://gitlab.com/another/repo',
60+
'https://github.com/expressjs/serve-static',
61+
'git://github.com/angular/di.js.git',
62+
'git://github.com/hapijs/boom',
63+
'https://github.com/balderdashy/waterline-criteria.git',
64+
'http://github.com/ariya/esprima.git',
65+
'http://github.com/isaacs/nopt',
66+
'https://github.com/chaijs/chai',
67+
'https://github.com/christkv/kerberos.git',
68+
'https://gitlab.com/foo/private.git',
69+
'https://gitlab.com/foo/private.git'
70+
]
71+
self.assertEquals(expected, results)
72+

0 commit comments

Comments
 (0)