Created
February 17, 2025 15:56
-
-
Save aojea/a6632cb00fbe2959c26c065ef63600f3 to your computer and use it in GitHub Desktop.
Download kubernetes PR api-review with code and comments
This file contains hidden or 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 requests | |
from pprint import pprint | |
# Replace with your GitHub personal access token | |
GITHUB_TOKEN = "----------------------" | |
def search_pull_requests_with_label(repo, label): | |
url = f"https://api.github.com/search/issues" | |
query = f"repo:{repo} is:pr label:{label}" | |
params = { | |
"q": query, | |
"sort": "updated", | |
"order": "desc", | |
"per_page": 100, | |
"page": 1 | |
} | |
headers = { | |
"Authorization": f"Bearer {GITHUB_TOKEN}", | |
"Accept": "application/vnd.github.v3+json" | |
} | |
all_prs = [] | |
while True: | |
response = requests.get(url, headers=headers, params=params) | |
response.raise_for_status() | |
data = response.json() | |
all_prs.extend(data.get('items', [])) | |
if "next" in response.links: | |
params["page"] += 1 | |
else: | |
break | |
return all_prs | |
def get_review_comments(repo, pr_number): | |
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}/comments" | |
comments = [] | |
page = 1 | |
headers = { | |
"Authorization": f"Bearer {GITHUB_TOKEN}", | |
"Accept": "application/vnd.github.v3+json" | |
} | |
while True: | |
response = requests.get(url, headers=headers, params={"per_page": 100, "page": page}) | |
response.raise_for_status() | |
data = response.json() | |
comments.extend(data) | |
if len(data) < 100: | |
break | |
page += 1 | |
return comments | |
def print_pull_requests_with_comments(prs, repo): | |
for pr in prs: | |
print(f"Title: {pr['title']}") | |
print("Review Comments:") | |
pr_number = pr['number'] | |
comments = get_review_comments(repo, pr_number) | |
for comment in comments: | |
print(f" - {comment['user']['login']} (at {comment['created_at']}): {comment['diff_hunk']} {comment['body']}") | |
print("=" * 40) | |
if __name__ == "__main__": | |
repo = "kubernetes/kubernetes" | |
label = "api-review" | |
prs = search_pull_requests_with_label(repo, label) | |
print_pull_requests_with_comments(prs, repo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment