Skip to content

Commit 451f648

Browse files
authored
Merge pull request #12 from TG1999/tags
Add tag support for GitHub URLs
2 parents 85f46ba + 83091f8 commit 451f648

File tree

3 files changed

+404
-0
lines changed

3 files changed

+404
-0
lines changed

package_registry/github_tags.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# fetchcode is a free software tool from nexB Inc. and others.
2+
# Visit https://github.com/nexB/fetchcode for support and download.
3+
#
4+
# Copyright (c) nexB Inc. and others. All rights reserved.
5+
# http://nexb.com and http://aboutcode.org
6+
#
7+
# This software is licensed under the Apache License version 2.0.
8+
#
9+
# You may not use this software except in compliance with the License.
10+
# You may obtain a copy of the License at:
11+
# http://apache.org/licenses/LICENSE-2.0
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations under the License.
16+
17+
import requests
18+
from urllib.parse import urlparse
19+
20+
21+
def build_url(url):
22+
"""
23+
Return a URL to access the list of tags using the GitHub API
24+
"""
25+
base_url='https://api.github.com/repos'
26+
url_parts = urlparse(url)
27+
path_parts = url_parts.path.split('/')
28+
namespace = path_parts[1]
29+
name = path_parts[2]
30+
return '{}/{}/{}/tags'.format(base_url, namespace, name)
31+
32+
33+
def get_tags(url):
34+
"""
35+
Return a list of git tags given the `url` to a Github repository
36+
"""
37+
38+
url_parts = urlparse(url)
39+
40+
if not(url_parts.netloc == 'github.com'):
41+
raise Exception('Not a GitHub URL')
42+
43+
else:
44+
final_url = build_url(url)
45+
resp = requests.get(final_url)
46+
tags = []
47+
for res in resp.json():
48+
if 'name' in res:
49+
tags.append(res['name'])
50+
return tags

tests/data/gh_tags_response.json

Lines changed: 302 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,302 @@
1+
[
2+
{
3+
"name": "v3.1.1",
4+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v3.1.1",
5+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v3.1.1",
6+
"commit": {
7+
"sha": "1af5ac8449cbb1ce98a0b461a6d9a5ad42a5d248",
8+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/1af5ac8449cbb1ce98a0b461a6d9a5ad42a5d248"
9+
},
10+
"node_id": "MDM6UmVmMzgzNzMzMzg6djMuMS4x"
11+
},
12+
{
13+
"name": "v3.1.0",
14+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v3.1.0",
15+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v3.1.0",
16+
"commit": {
17+
"sha": "c697222cec7b7ef5a122bf9f64eeef5a4ede11f9",
18+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/c697222cec7b7ef5a122bf9f64eeef5a4ede11f9"
19+
},
20+
"node_id": "MDM6UmVmMzgzNzMzMzg6djMuMS4w"
21+
},
22+
{
23+
"name": "v3.0.2",
24+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v3.0.2",
25+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v3.0.2",
26+
"commit": {
27+
"sha": "3f699d09f446a50a1021b5756df8b5c4485a55f0",
28+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/3f699d09f446a50a1021b5756df8b5c4485a55f0"
29+
},
30+
"node_id": "MDM6UmVmMzgzNzMzMzg6djMuMC4y"
31+
},
32+
{
33+
"name": "v3.0.1",
34+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v3.0.1",
35+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v3.0.1",
36+
"commit": {
37+
"sha": "12dee4a50acd489965a81a3051d6f15e930cd485",
38+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/12dee4a50acd489965a81a3051d6f15e930cd485"
39+
},
40+
"node_id": "MDM6UmVmMzgzNzMzMzg6djMuMC4x"
41+
},
42+
{
43+
"name": "v3.0.0",
44+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v3.0.0",
45+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v3.0.0",
46+
"commit": {
47+
"sha": "fba90b2f52361c2c099e1c2bed043d70b39d1743",
48+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/fba90b2f52361c2c099e1c2bed043d70b39d1743"
49+
},
50+
"node_id": "MDM6UmVmMzgzNzMzMzg6djMuMC4w"
51+
},
52+
{
53+
"name": "v2.9.9",
54+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.9",
55+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.9",
56+
"commit": {
57+
"sha": "fd04833e3e9a1eeacc8e9945d677a4998b18854b",
58+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/fd04833e3e9a1eeacc8e9945d677a4998b18854b"
59+
},
60+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS45"
61+
},
62+
{
63+
"name": "v2.9.8",
64+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.8",
65+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.8",
66+
"commit": {
67+
"sha": "a2fc22739372f6290499459f4843b2a9fe14952d",
68+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/a2fc22739372f6290499459f4843b2a9fe14952d"
69+
},
70+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS44"
71+
},
72+
{
73+
"name": "v2.9.7",
74+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.7",
75+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.7",
76+
"commit": {
77+
"sha": "f4a832378ee2e65f6319d671161a13e47ed06fb7",
78+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/f4a832378ee2e65f6319d671161a13e47ed06fb7"
79+
},
80+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS43"
81+
},
82+
{
83+
"name": "v2.9.6",
84+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.6",
85+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.6",
86+
"commit": {
87+
"sha": "f499e18ee62c28880b187670ffd1f9aefc51dc64",
88+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/f499e18ee62c28880b187670ffd1f9aefc51dc64"
89+
},
90+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS42"
91+
},
92+
{
93+
"name": "v2.9.5",
94+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.5",
95+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.5",
96+
"commit": {
97+
"sha": "3be6be88683fe906ea928f17bfcfa24d9607454d",
98+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/3be6be88683fe906ea928f17bfcfa24d9607454d"
99+
},
100+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS41"
101+
},
102+
{
103+
"name": "v2.9.4",
104+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.4",
105+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.4",
106+
"commit": {
107+
"sha": "d3bedeef80c03bb3fa486c262980eb108e49a342",
108+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/d3bedeef80c03bb3fa486c262980eb108e49a342"
109+
},
110+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS40"
111+
},
112+
{
113+
"name": "v2.9.3",
114+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.3",
115+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.3",
116+
"commit": {
117+
"sha": "3f970b1e156442b869663b22e27aa8f9637c2c9e",
118+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/3f970b1e156442b869663b22e27aa8f9637c2c9e"
119+
},
120+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS4z"
121+
},
122+
{
123+
"name": "v2.9.2",
124+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.2",
125+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.2",
126+
"commit": {
127+
"sha": "7e654ef927deed27334b15019254bf3b4be0efb4",
128+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/7e654ef927deed27334b15019254bf3b4be0efb4"
129+
},
130+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS4y"
131+
},
132+
{
133+
"name": "v2.9.1",
134+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.1",
135+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.1",
136+
"commit": {
137+
"sha": "96cf70dcec8fb1dd1908c1a355dc369f8617059f",
138+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/96cf70dcec8fb1dd1908c1a355dc369f8617059f"
139+
},
140+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS4x"
141+
},
142+
{
143+
"name": "v2.9.0b1",
144+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.9.0b1",
145+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.9.0b1",
146+
"commit": {
147+
"sha": "8ca9921f4be2c742926219348a1ef333a9d4304b",
148+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/8ca9921f4be2c742926219348a1ef333a9d4304b"
149+
},
150+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuOS4wYjE="
151+
},
152+
{
153+
"name": "v2.2.1",
154+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.2.1",
155+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.2.1",
156+
"commit": {
157+
"sha": "bd9a0c3e801d916a54ec77228ce1d0801cf7d374",
158+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/bd9a0c3e801d916a54ec77228ce1d0801cf7d374"
159+
},
160+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMi4x"
161+
},
162+
{
163+
"name": "v2.2.0",
164+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.2.0",
165+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.2.0",
166+
"commit": {
167+
"sha": "b981c3f912438b037a330a6f804e1935d1176c46",
168+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/b981c3f912438b037a330a6f804e1935d1176c46"
169+
},
170+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMi4w"
171+
},
172+
{
173+
"name": "v2.1.0",
174+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.1.0",
175+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.1.0",
176+
"commit": {
177+
"sha": "2d6d9045a4a87331835340d37bd63813c2f9dea6",
178+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/2d6d9045a4a87331835340d37bd63813c2f9dea6"
179+
},
180+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMS4w"
181+
},
182+
{
183+
"name": "v2.0.1",
184+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.0.1",
185+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.0.1",
186+
"commit": {
187+
"sha": "1960ffcf27e14f0f7163a4d541e377509a4092f8",
188+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/1960ffcf27e14f0f7163a4d541e377509a4092f8"
189+
},
190+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMC4x"
191+
},
192+
{
193+
"name": "v2.0.0",
194+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.0.0",
195+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.0.0",
196+
"commit": {
197+
"sha": "92e16663ced395af16a988c42cadebf4c738defa",
198+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/92e16663ced395af16a988c42cadebf4c738defa"
199+
},
200+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMC4w"
201+
},
202+
{
203+
"name": "v2.0.0.rc3",
204+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.0.0.rc3",
205+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.0.0.rc3",
206+
"commit": {
207+
"sha": "89f9dee91bbb377479681cb2cf22c7994c38ded5",
208+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/89f9dee91bbb377479681cb2cf22c7994c38ded5"
209+
},
210+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMC4wLnJjMw=="
211+
},
212+
{
213+
"name": "v2.0.0.rc2",
214+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.0.0.rc2",
215+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.0.0.rc2",
216+
"commit": {
217+
"sha": "eeb6f2734b8ec90956b675a13b23d90be9a8e312",
218+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/eeb6f2734b8ec90956b675a13b23d90be9a8e312"
219+
},
220+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMC4wLnJjMg=="
221+
},
222+
{
223+
"name": "v2.0.0.rc1",
224+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v2.0.0.rc1",
225+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v2.0.0.rc1",
226+
"commit": {
227+
"sha": "7a57e44bece5ad0385e6b84371be33e9674fd6ef",
228+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/7a57e44bece5ad0385e6b84371be33e9674fd6ef"
229+
},
230+
"node_id": "MDM6UmVmMzgzNzMzMzg6djIuMC4wLnJjMQ=="
231+
},
232+
{
233+
"name": "v1.6.3",
234+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.6.3",
235+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.6.3",
236+
"commit": {
237+
"sha": "2e271bab84ae787df9aa944cebf7ad945401e4c5",
238+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/2e271bab84ae787df9aa944cebf7ad945401e4c5"
239+
},
240+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNi4z"
241+
},
242+
{
243+
"name": "v1.6.2",
244+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.6.2",
245+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.6.2",
246+
"commit": {
247+
"sha": "91b8f0fd6f145468bd2ec573c1d38e23c29d2f3a",
248+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/91b8f0fd6f145468bd2ec573c1d38e23c29d2f3a"
249+
},
250+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNi4y"
251+
},
252+
{
253+
"name": "v1.6.1",
254+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.6.1",
255+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.6.1",
256+
"commit": {
257+
"sha": "10eea0cad9f6e389a54094e6cc77ec585ba9fa8a",
258+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/10eea0cad9f6e389a54094e6cc77ec585ba9fa8a"
259+
},
260+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNi4x"
261+
},
262+
{
263+
"name": "v1.6.0",
264+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.6.0",
265+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.6.0",
266+
"commit": {
267+
"sha": "d0926424ce9c31e240a96f4ef6a3c744c5b42c82",
268+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/d0926424ce9c31e240a96f4ef6a3c744c5b42c82"
269+
},
270+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNi4w"
271+
},
272+
{
273+
"name": "v1.5.0",
274+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.5.0",
275+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.5.0",
276+
"commit": {
277+
"sha": "070f611263154dec7ac000cb86257728d2fb5647",
278+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/070f611263154dec7ac000cb86257728d2fb5647"
279+
},
280+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNS4w"
281+
},
282+
{
283+
"name": "v1.4.3",
284+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.4.3",
285+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.4.3",
286+
"commit": {
287+
"sha": "0844aee2d6b4210d9c68d621e1a243837e167a87",
288+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/0844aee2d6b4210d9c68d621e1a243837e167a87"
289+
},
290+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNC4z"
291+
},
292+
{
293+
"name": "v1.4.2",
294+
"zipball_url": "https://api.github.com/repos/nexB/scancode-toolkit/zipball/v1.4.2",
295+
"tarball_url": "https://api.github.com/repos/nexB/scancode-toolkit/tarball/v1.4.2",
296+
"commit": {
297+
"sha": "0feda39a57f0d121302127411994e63b1db2bfa3",
298+
"url": "https://api.github.com/repos/nexB/scancode-toolkit/commits/0feda39a57f0d121302127411994e63b1db2bfa3"
299+
},
300+
"node_id": "MDM6UmVmMzgzNzMzMzg6djEuNC4y"
301+
}
302+
]

0 commit comments

Comments
 (0)