diff options
author | 2024-01-27 21:22:38 +0100 | |
---|---|---|
committer | 2024-01-27 21:23:04 +0100 | |
commit | 8f3b23df8de848464a49bf6f60b4680b7a62fda0 (patch) | |
tree | 235a1a98044745d663fbee27dda623d16a17c212 /docs | |
parent | 8d21867caf40e862b6ffe6e12ebdedc7f5b5ace4 (diff) | |
download | iced-8f3b23df8de848464a49bf6f60b4680b7a62fda0.tar.gz iced-8f3b23df8de848464a49bf6f60b4680b7a62fda0.tar.bz2 iced-8f3b23df8de848464a49bf6f60b4680b7a62fda0.zip |
Update `CHANGELOG`
Diffstat (limited to 'docs')
-rw-r--r-- | docs/release_summary.py | 118 |
1 files changed, 69 insertions, 49 deletions
diff --git a/docs/release_summary.py b/docs/release_summary.py index 62694d05..39ec876c 100644 --- a/docs/release_summary.py +++ b/docs/release_summary.py @@ -1,55 +1,75 @@ -import re -import sys import requests -from typing import List, Tuple - -if len(sys.argv) < 3: - print("Usage: python release_summary.py <personal_access_token> <previous_release_branch>") - exit(1) - -TOKEN = sys.argv[1] -HEADERS = {"Authorization": f"Bearer {TOKEN}"} -PR_COMMIT_REGEX = re.compile(r"(?i)Merge pull request #(\d+).*") - -def get_merged_prs_since_release(repo: str, previous_release_branch: str) -> List[Tuple[str, int, str, str]]: - prs = [] - compare_url = f"https://api.github.com/repos/{repo}/compare/{previous_release_branch}...master?per_page=1000" - compare_response = requests.get(compare_url, headers=HEADERS) - - if compare_response.status_code == 200: - compare_data = compare_response.json() - for commit in compare_data["commits"]: - match = PR_COMMIT_REGEX.search(commit["commit"]["message"]) - if match: - pr_number = int(match.group(1)) - pr_url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}" - - print(f"Querying PR {pr_number}") - pr_response = requests.get(pr_url, headers=HEADERS) - - if pr_response.status_code == 200: - pr_data = pr_response.json() - prs.append((pr_data["title"], pr_number, pr_data["html_url"], pr_data["user"]["login"])) - else: - print(f"Error fetching PR {pr_number}: {pr_response.status_code}") - else: - print(f"Error comparing branches: {compare_response.status_code}") - - return prs - -def print_pr_list(prs: List[Tuple[str, int, str, str]]): +import os + +def get_merged_prs(repo, milestone, token): + url = f'https://api.github.com/repos/{repo}/pulls' + params = { + 'state': 'closed', + 'per_page': 100, # Number of items per page, adjust as needed + } + headers = {'Authorization': f'token {token}'} + + all_prs = [] + page = 1 + + while True: + params['page'] = page + response = requests.get(url, params=params, headers=headers) + response.raise_for_status() + + prs = response.json() + + if not prs: + break # No more pages + + all_prs.extend([pr for pr in prs if pr['merged_at'] and (pr['milestone'] or {}).get('title', '') == milestone]) + page += 1 + + return all_prs + +def categorize_prs(prs): + categorized_prs = {'addition': [], 'change': [], 'fix': []} + for pr in prs: - print(f"- {pr[0]}. [#{pr[1]}]({pr[2]})") + labels = [label['name'] for label in pr['labels']] + if 'addition' in labels or 'feature' in labels: + categorized_prs['addition'].append(pr) + elif 'fix' in labels or 'bug' in labels: + categorized_prs['fix'].append(pr) + elif 'change' in labels or 'improvement' in labels: + categorized_prs['change'].append(pr) + + return categorized_prs + +def get_authors(prs): + authors = set() + for pr in prs: + authors.add(pr['user']['login']) + return sorted(authors, key=str.casefold) + +def main(): + repo = 'iced-rs/iced' + milestone = '0.12' + token = os.environ['GITHUB_TOKEN'] + + prs = get_merged_prs(repo, milestone, token) + categorized_prs = categorize_prs(prs) + + for category, items in categorized_prs.items(): + print(f"### {category.capitalize()}") + + for pr in items: + print(f"- {pr['title']}. [#{pr['number']}](https://github.com/{repo}/pull/{pr['number']})") + + print("") + + print("") + + authors = get_authors(prs) -def print_authors(prs: List[Tuple[str, int, str, str]]): - authors = set(pr[3] for pr in prs) - print("\nAuthors:") - for author in sorted(authors, key=str.casefold): + print("Many thanks to...") + for author in authors: print(f"- @{author}") if __name__ == "__main__": - repo = "iced-rs/iced" - previous_release_branch = sys.argv[2] - merged_prs = get_merged_prs_since_release(repo, previous_release_branch) - print_pr_list(merged_prs) - print_authors(merged_prs) + main()
\ No newline at end of file |