-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a script that generates a changelog from recent PRs and their labels #1718
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9aad514
Add a script that generates a changelog from recent PRs and their labels
emilk 9e24e3f
Fix typo
emilk c91b11b
Add emojis for all categories, and list commits oldest -> newest
emilk bb658a0
Cleanup
emilk ec7e701
py-format
emilk 519df20
Add option to include labels
emilk 9ea9baf
py-format
emilk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Summarizes recent PRs based on their GitHub labels. | ||
|
||
The result can be copy-pasted into CHANGELOG.md, though it often needs some manual editing too. | ||
""" | ||
|
||
import re | ||
import sys | ||
from typing import Any, List, Optional, Tuple | ||
|
||
import requests | ||
from git import Repo # pip install GitPython | ||
from tqdm import tqdm | ||
|
||
|
||
def get_github_token() -> str: | ||
import os | ||
|
||
token = os.environ.get("GH_ACCESS_TOKEN", "") | ||
if token != "": | ||
return token | ||
|
||
home_dir = os.path.expanduser("~") | ||
token_file = os.path.join(home_dir, ".githubtoken") | ||
|
||
try: | ||
with open(token_file, "r") as f: | ||
token = f.read().strip() | ||
return token | ||
except Exception: | ||
pass | ||
|
||
print("ERROR: expected a GitHub token in the environment variable GH_ACCESS_TOKEN or in ~/.githubtoken") | ||
sys.exit(1) | ||
|
||
|
||
OWNER = "rerun-io" | ||
REPO = "rerun" | ||
COMMIT_RANGE = "latest..HEAD" | ||
INCLUDE_LABELS = False # It adds quite a bit of visual noise | ||
|
||
|
||
def pr_title_labels(pr_number: int) -> Tuple[Optional[str], List[str]]: | ||
url = f"https://api.github.com/repos/{OWNER}/{REPO}/pulls/{pr_number}" | ||
gh_access_token = get_github_token() | ||
headers = {"Authorization": f"Token {gh_access_token}"} | ||
response = requests.get(url, headers=headers) | ||
json = response.json() | ||
|
||
# Check if the request was successful (status code 200) | ||
if response.status_code == 200: | ||
labels = [label["name"] for label in json["labels"]] | ||
return (json["title"], labels) | ||
else: | ||
print(f"ERROR: {response.status_code} - {json['message']}") | ||
return (None, []) | ||
|
||
|
||
def commit_title_pr_number(commit: Any) -> Tuple[str, Optional[int]]: | ||
match = re.match(r"(.*) \(#(\d+)\)", commit.summary) | ||
if match: | ||
return (str(match.group(1)), int(match.group(2))) | ||
else: | ||
return (commit.summary, None) | ||
|
||
|
||
def print_section(title: str, items: List[str]) -> None: | ||
if 0 < len(items): | ||
print(f"#### {title}") | ||
for line in items: | ||
print(f"- {line}") | ||
print() | ||
|
||
|
||
repo = Repo(".") | ||
commits = list(repo.iter_commits(COMMIT_RANGE)) | ||
commits.reverse() # Most recent last | ||
|
||
# Sections: | ||
analytics = [] | ||
enhancement = [] | ||
bugs = [] | ||
dev_experience = [] | ||
docs = [] | ||
examples = [] | ||
misc = [] | ||
performance = [] | ||
python = [] | ||
renderer = [] | ||
rfc = [] | ||
rust = [] | ||
ui = [] | ||
viewer = [] | ||
web = [] | ||
|
||
for commit in tqdm(commits, desc="Processing commits"): | ||
(title, pr_number) = commit_title_pr_number(commit) | ||
if pr_number is None: | ||
# Someone committed straight to main: | ||
summary = f"{title} [{commit.hexsha}](https://github.com/{OWNER}/{REPO}/commit/{commit.hexsha})" | ||
misc.append(summary) | ||
else: | ||
(pr_title, labels) = pr_title_labels(pr_number) | ||
title = pr_title or title # We prefer the PR title if available | ||
summary = f"{title} [#{pr_number}](https://github.com/{OWNER}/{REPO}/pull/{pr_number})" | ||
|
||
if INCLUDE_LABELS and 0 < len(labels): | ||
summary += f" ({', '.join(labels)})" | ||
|
||
added = False | ||
|
||
if labels == ["β΄ release"]: | ||
# Ignore release PRs | ||
continue | ||
|
||
# Some PRs can show up underm multiple sections: | ||
if "π python API" in labels: | ||
python.append(summary) | ||
added = True | ||
if "π¦ rust SDK" in labels: | ||
rust.append(summary) | ||
added = True | ||
if "π analytics" in labels: | ||
analytics.append(summary) | ||
added = True | ||
|
||
if not added: | ||
# Put the remaining PRs under just one section: | ||
if "πͺ³ bug" in labels or "π£ crash" in labels: | ||
bugs.append(summary) | ||
elif "π performance" in labels: | ||
performance.append(summary) | ||
elif "examples" in labels: | ||
examples.append(summary) | ||
elif "π documentation" in labels: | ||
docs.append(summary) | ||
elif "ui" in labels: | ||
ui.append(summary) | ||
elif "πΊ re_viewer" in labels: | ||
viewer.append(summary) | ||
elif "πΊ re_renderer" in labels: | ||
renderer.append(summary) | ||
elif "πΈοΈ web" in labels: | ||
web.append(summary) | ||
elif "enhancement" in labels: | ||
enhancement.append(summary) | ||
elif "π§βπ» dev experience" in labels: | ||
dev_experience.append(summary) | ||
elif "π¬ discussion" in labels: | ||
rfc.append(summary) | ||
elif not added: | ||
misc.append(summary) | ||
|
||
print() | ||
# Most interesting first: | ||
print_section("π Python SDK", python) | ||
print_section("π¦ Rust SDK", rust) | ||
print_section("πͺ³ Bug Fixes", bugs) | ||
print_section("π Performance Improvements", performance) | ||
print_section("π§βπ« Examples", examples) | ||
print_section("π Docs", docs) | ||
print_section("πΌ UI Improvements", ui) | ||
print_section("π€·ββοΈ Other Viewer Improvements", viewer) | ||
print_section("πΈοΈ Web", web) | ||
print_section("π¨ Renderer Improvements", renderer) | ||
print_section("β¨ Other Enhancement", enhancement) | ||
print_section("π Analytics", analytics) | ||
print_section("π£ Merged RFCs", rfc) | ||
print_section("π§βπ» Dev-experience", dev_experience) | ||
print_section("π€·ββοΈ Other", misc) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should exclude
regression
tagged PRs π€depends obv. for how long a thing regressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean add a separate category for regression fixes?