Skip to content

Commit e048315

Browse files
committed
Adapt get_issues.py script for GitHub (instead of Bitbucket)
1 parent 3155d0c commit e048315

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

extra/get_issues.py

+40-30
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@
22
import py
33
import textwrap
44

5-
issues_url = "http://bitbucket.org/api/1.0/repositories/pytest-dev/pytest/issues"
5+
issues_url = "https://api.github.com/repos/pytest-dev/pytest/issues"
66

77
import requests
88

9+
910
def get_issues():
10-
chunksize = 50
11-
start = 0
1211
issues = []
12+
url = issues_url
1313
while 1:
14-
post_data = {"accountname": "pytest-dev",
15-
"repo_slug": "pytest",
16-
"start": start,
17-
"limit": chunksize}
18-
print ("getting from", start)
19-
r = requests.get(issues_url, params=post_data)
14+
get_data = {"state": "all"}
15+
r = requests.get(url, params=get_data)
2016
data = r.json()
21-
issues.extend(data["issues"])
22-
if start + chunksize >= data["count"]:
23-
return issues
24-
start += chunksize
17+
if r.status_code == 403:
18+
# API request limit exceeded
19+
print(data['message'])
20+
exit(1)
21+
issues.extend(data)
2522

26-
kind2num = "bug enhancement task proposal".split()
23+
# Look for next page
24+
links = requests.utils.parse_header_links(r.headers['Link'])
25+
another_page = False
26+
for link in links:
27+
if link['rel'] == 'next':
28+
url = link['url']
29+
another_page = True
30+
if not another_page:
31+
return issues
2732

28-
status2num = "new open resolved duplicate invalid wontfix".split()
2933

3034
def main(args):
3135
cachefile = py.path.local(args.cache)
@@ -35,33 +39,38 @@ def main(args):
3539
else:
3640
issues = json.loads(cachefile.read())
3741

38-
open_issues = [x for x in issues
39-
if x["status"] in ("new", "open")]
42+
open_issues = [x for x in issues if x["state"] == "open"]
4043

41-
def kind_and_id(x):
42-
kind = x["metadata"]["kind"]
43-
return kind2num.index(kind), len(issues)-int(x["local_id"])
44-
open_issues.sort(key=kind_and_id)
44+
open_issues.sort(key=lambda x: x["number"])
4545
report(open_issues)
4646

47+
48+
def _get_kind(issue):
49+
labels = [l['name'] for l in issue['labels']]
50+
for key in ('bug', 'enhancement', 'proposal'):
51+
if key in labels:
52+
return key
53+
return 'issue'
54+
55+
4756
def report(issues):
4857
for issue in issues:
49-
metadata = issue["metadata"]
50-
priority = issue["priority"]
5158
title = issue["title"]
52-
content = issue["content"]
53-
kind = metadata["kind"]
54-
status = issue["status"]
55-
id = issue["local_id"]
56-
link = "https://bitbucket.org/pytest-dev/pytest/issue/%s/" % id
59+
body = issue["body"]
60+
kind = _get_kind(issue)
61+
status = issue["state"]
62+
number = issue["number"]
63+
link = "https://github.com/pytest-dev/pytest/issues/%s/" % number
5764
print("----")
5865
print(status, kind, link)
5966
print(title)
6067
#print()
61-
#lines = content.split("\n")
68+
#lines = body.split("\n")
6269
#print ("\n".join(lines[:3]))
63-
#if len(lines) > 3 or len(content) > 240:
70+
#if len(lines) > 3 or len(body) > 240:
6471
# print ("...")
72+
print("\n\nFound %s open issues" % len(issues))
73+
6574

6675
if __name__ == "__main__":
6776
import argparse
@@ -72,3 +81,4 @@ def report(issues):
7281
help="cache file")
7382
args = parser.parse_args()
7483
main(args)
84+

0 commit comments

Comments
 (0)