Skip to content

Commit 4a23b44

Browse files
committed
Add --json to save counts of issues and PRs per person
1 parent 5e8aba4 commit 4a23b44

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

issues_by_dev.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import requests # pip install requests
2525
from ghapi.all import GhApi, paged # pip install ghapi
2626
from prettytable import PrettyTable, TableStyle # pip install "prettytable>=3.12.0"
27-
from rich.progress import track # pip install rich
27+
from rich import print # pip install rich
28+
from rich.progress import track
29+
30+
from potential_closeable_issues import save_json
2831

2932
Issue: TypeAlias = dict[str, Any]
3033

@@ -33,6 +36,7 @@
3336
GITHUB_TOKEN = os.environ["GITHUB_TOOLS_TOKEN"]
3437

3538
URL = "https://raw.githubusercontent.com/python/devguide/main/core-team/core-team.csv"
39+
REPO = "https://github.com/python/cpython"
3640

3741

3842
class Author(NamedTuple):
@@ -52,7 +56,7 @@ def check_issues(author: str | None = None) -> Author:
5256
per_page=100,
5357
):
5458
for issue in page:
55-
if issue.html_url.startswith("https://github.com/python/cpython/pull/"):
59+
if issue.html_url.startswith(f"{REPO}/pull/"):
5660
prs.append(issue)
5761
else:
5862
issues.append(issue)
@@ -82,6 +86,7 @@ def main() -> None:
8286
)
8387
parser.add_argument("--links", action="store_true", help="Add links")
8488
parser.add_argument("--limit", type=int, help="Limit to this number of usernames")
89+
parser.add_argument("-j", "--json", action="store_true", help="output to JSON file")
8590
args = parser.parse_args()
8691

8792
# https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#list-organization-members
@@ -127,12 +132,13 @@ def main() -> None:
127132
print()
128133
total_issues = total_prs = 0
129134
counter = Counter(totals)
135+
data = {}
130136
for i, (author, count) in enumerate(counter.most_common(), start=1):
131-
x = len(authors[author].issues)
132-
y = len(authors[author].prs)
133-
total_issues += x
134-
total_prs += y
135-
if x or y:
137+
issues = len(authors[author].issues)
138+
prs = len(authors[author].prs)
139+
total_issues += issues
140+
total_prs += prs
141+
if issues or prs:
136142
match (args.markdown, args.links):
137143
case True, True:
138144
link_function = markdown_link
@@ -144,15 +150,15 @@ def main() -> None:
144150
row = (
145151
i,
146152
author,
147-
link_function(f"https://github.com/python/cpython/issues/{author}", x),
148-
link_function(f"https://github.com/python/cpython/pulls/{author}", y),
153+
link_function(f"{REPO}/issues/{author}", issues),
154+
link_function(f"{REPO}/pulls/{author}", prs),
149155
link_function(
150-
f"https://github.com/python/cpython/issues?q=is%3Aopen+author%3A{author}",
151-
x + y,
156+
f"{REPO}/issues?q=is%3Aopen+author%3A{author}", issues + prs
152157
),
153158
)
154159

155160
table.add_row(row)
161+
data[author] = {"issues": issues, "prs": prs}
156162

157163
total_row = [
158164
"",
@@ -165,6 +171,12 @@ def main() -> None:
165171
table.add_row(total_row)
166172
print(table)
167173

174+
if args.json:
175+
print(data)
176+
# # Use same name as this .py but with .json
177+
filename = os.path.splitext(__file__)[0] + ".json"
178+
save_json(data, filename)
179+
168180

169181
if __name__ == "__main__":
170182
main()

potential_closeable_issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def save_json(data: Any, filename: str) -> None:
175175
data = {"last_update": dt.datetime.now(dt.UTC).isoformat(), **data}
176176
with open(filename, "w", encoding="utf-8") as f:
177177
json.dump(data, f, indent=2)
178-
print(f"Saved candidates to {filename}")
178+
print(f"Saved to {filename}")
179179

180180

181181
def main() -> None:

0 commit comments

Comments
 (0)