usage: make_github_changelog.py [-h] --token TOKEN [--since-tag SINCE_TAG] [--base BASE]
Helper for writing changelogs
optional arguments:
-h, --help show this help message and exit
--token TOKEN, -t TOKEN
GitHub API token
--since-tag SINCE_TAG
Find PRs since tag was merged
--base BASE, -b BASE Base branch PRs were merged into
Last active
December 13, 2021 15:08
-
-
Save ZedThree/8a65d45d9b6a607228f2d99861b16736 to your computer and use it in GitHub Desktop.
Helper for making simple markdown changelogs from closed GitHub PRs and issues
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
#!/usr/bin/env python3 | |
import argparse | |
import github as gh | |
def format_pull(pull: gh.PullRequest.PullRequest) -> str: | |
url = pull.url.replace("api.github.com/repos", "github.com").replace( | |
"pulls", "pull" | |
) | |
user_name = pull.user.login | |
user_url = pull.user.url.replace("api.", "") | |
return fr"- {pull.title} [\#{pull.number}]({url}) ([{user_name}]({user_url}))" | |
def format_issue(issue: gh.Issue.Issue) -> str: | |
url = issue.url.replace("api.github.com/repos", "github.com") | |
return fr"- {issue.title} [\#{issue.number}]({url})" | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description="Helper for writing changelogs") | |
parser.add_argument( | |
"--token", "-t", type=str, help="GitHub API token", required=True | |
) | |
parser.add_argument( | |
"--since-tag", type=str, help="Find PRs since tag was merged", default=None | |
) | |
parser.add_argument( | |
"--base", | |
"-b", | |
type=str, | |
help="Base branch PRs were merged into", | |
default="master", | |
) | |
args = parser.parse_args() | |
github = gh.Github(args.token) | |
repo = github.get_repo("boutproject/BOUT-dev") | |
print(f"Got repo: {repo}") | |
if args.since_tag: | |
latest_tag = repo.get_release(args.since_tag) | |
else: | |
latest_tag = repo.get_releases()[0] | |
print(f"Using tag: {latest_tag}") | |
print("\n**Closed issues:**\n") | |
issues = repo.get_issues(state="closed", since=latest_tag.created_at) | |
for issue in issues: | |
if issue.closed_at < latest_tag.created_at: | |
continue | |
if issue.pull_request: | |
continue | |
print(format_issue(issue)) | |
pulls = repo.get_pulls(state="closed", base=args.base) | |
print("\n**Merged pull requests:**\n") | |
for pull in pulls: | |
if not pull.merged: | |
continue | |
if pull.merged_at > latest_tag.created_at: | |
print(format_pull(pull)) | |
else: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment