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