Debian Codegraph @

testing/web-platform/tests/tools/third_party/pytest/extra/get_issues.py

raw
1 import json
2 from pathlib import Path
3
4 import requests
5
6
7 issues_url = "https://api.github.com/repos/pytest-dev/pytest/issues"
8
9
10 def get_issues():
11 issues = []
12 url = issues_url
13 while 1:
14 get_data = {"state": "all"}
15 r = requests.get(url, params=get_data)
16 data = r.json()
17 if r.status_code == 403:
18 # API request limit exceeded
19 print(data["message"])
20 exit(1)
21 issues.extend(data)
22
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
32
33
34 def main(args):
35 cachefile = Path(args.cache)
36 if not cachefile.exists() or args.refresh:
37 issues = get_issues()
38 cachefile.write_text(json.dumps(issues), "utf-8")
39 else:
40 issues = json.loads(cachefile.read_text("utf-8"))
41
42 open_issues = [x for x in issues if x["state"] == "open"]
43
44 open_issues.sort(key=lambda x: x["number"])
45 report(open_issues)
46
47
48 def _get_kind(issue):
49 labels = [label["name"] for label in issue["labels"]]
50 for key in ("bug", "enhancement", "proposal"):
51 if key in labels:
52 return key
53 return "issue"
54
55
56 def report(issues):
57 for issue in issues:
58 title = issue["title"]
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
64 print("----")
65 print(status, kind, link)
66 print(title)
67 # print()
68 # lines = body.split("\n")
69 # print("\n".join(lines[:3]))
70 # if len(lines) > 3 or len(body) > 240:
71 # print("...")
72 print("\n\nFound %s open issues" % len(issues))
73
74
75 if __name__ == "__main__":
76 import argparse
77
78 parser = argparse.ArgumentParser("process bitbucket issues")
79 parser.add_argument(
80 "--refresh", action="store_true", help="invalidate cache, refresh issues"
81 )
82 parser.add_argument(
83 "--cache", action="store", default="issues.json", help="cache file"
84 )
85 args = parser.parse_args()
86 main(args)