Created
September 7, 2023 14:46
-
-
Save wrgoldstein/de65a8215624b1ca2fedd957bf071c32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import requests | |
import collections | |
headers = { | |
'Accept': 'application/vnd.github+json', | |
'Authorization': 'Bearer ' + os.getenv('GITHUB_API_TOKEN', ''), | |
'X-GitHub-Api-Version': '2022-11-28', | |
} | |
pulls = requests.get('https://api.github.com/repos/hodihq/post-checkout-survey/pulls?state=all&per_page=40', headers=headers) | |
def get_pr_info(pr): | |
creator = pr['user']['login'] | |
number = pr['number'] | |
url = 'https://api.github.com/repos/hodihq/post-checkout-survey/pulls/{number}/reviews'.format(number=number) | |
reviews = requests.get(url, headers=headers) | |
reviewers = [x['user']['login'] for x in reviews.json()] | |
return creator, list(set(reviewers)) | |
data = [get_pr_info(pr) for pr in pulls.json()] | |
request_counts = collections.Counter([u for (u, _) in data]) | |
review_counts = collections.Counter([e for (_, u) in data for e in u]) | |
print("```") | |
print("Review request counts (out of the last 40 PRs):") | |
for k,v in sorted(request_counts.items(), key=lambda i: -i[1]): | |
print(f"{k.ljust(20)} {v}") | |
print("```") | |
print("```") | |
print("Reviewer counts (out of the last 40 PRs):") | |
for k,v in sorted(review_counts.items(), key=lambda i: -i[1]): | |
print(f"{k.ljust(20)} {v}") | |
print("```") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment