Skip to content

Commit e74503d

Browse files
Update summarize_applications.py
1 parent 76e0521 commit e74503d

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

.github/scripts/summarize_applications.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
import csv
23
from github import Github
34
import re
5+
from collections import Counter
46

57
# Get token and repo name from environment variables
68
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
@@ -11,15 +13,20 @@
1113
repo = g.get_repo(GITHUB_REPOSITORY)
1214

1315
# Fetch issues with 'ambassador' label
14-
issues = repo.get_issues(state='all', labels=['ambassador'])
16+
issues = list(repo.get_issues(state='all', labels=['ambassador']))
1517

1618
# Prepare summary content
1719
summary_lines = []
1820
summary_lines.append("# PyTorch Ambassador Applications Summary\n\n")
19-
summary_lines.append(f"**Total Applications**: {issues.totalCount}\n\n")
21+
summary_lines.append(f"**Total Applications**: {len(issues)}\n\n")
22+
2023
summary_lines.append("| Issue # | Nominee Name | Email | Organization | Location |\n")
2124
summary_lines.append("|--------|--------------|------|--------------|----------|\n")
2225

26+
# Data collection for location grouping and CSV export
27+
location_counter = Counter()
28+
csv_rows = []
29+
2330
for issue in issues:
2431
body = issue.body
2532

@@ -35,9 +42,29 @@ def extract(label):
3542

3643
summary_lines.append(f"| {issue.number} | {name} | {email} | {org} | {location} |\n")
3744

38-
# Write summary to SUMMARY.md
39-
output_file = "SUMMARY.md"
40-
with open(output_file, "w") as f:
45+
# Count locations
46+
location_counter[location] += 1
47+
48+
# Prepare CSV row
49+
csv_rows.append([issue.number, name, email, org, location])
50+
51+
# Add location summary to Markdown
52+
summary_lines.append("\n## Applications by Location\n\n")
53+
summary_lines.append("| Location | Count |\n")
54+
summary_lines.append("|----------|------:|\n")
55+
for loc, count in location_counter.items():
56+
summary_lines.append(f"| {loc} | {count} |\n")
57+
58+
# Write to Markdown
59+
with open("SUMMARY.md", "w") as f:
4160
f.writelines(summary_lines)
4261

43-
print(f"Summary written to {output_file}")
62+
print("Summary written to SUMMARY.md")
63+
64+
# Write to CSV
65+
with open("SUMMARY.csv", "w", newline='', encoding='utf-8') as csvfile:
66+
writer = csv.writer(csvfile)
67+
writer.writerow(["Issue #", "Nominee Name", "Email", "Organization", "Location"])
68+
writer.writerows(csv_rows)
69+
70+
print("Summary written to SUMMARY.csv")

0 commit comments

Comments
 (0)