Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 230 lines (186 sloc) 6.86 KB
"""Generate the release notes automatically from Github pull requests.
Start with:
export GH_TOKEN=<your-gh-api-token>
Then, for a major release:
python /path/to/ v0.14.0 master --version 0.15.0
For a minor release:
python /path/to/ v.14.2 v0.14.x --version 0.14.3
You should probably redirect the output with:
python /path/to/ [args] | tee release_notes.rst
You'll require PyGitHub and tqdm, which you can install with:
pip install -r requirements/_release_tools.txt
import os
import argparse
from datetime import datetime
from collections import OrderedDict
import string
from warnings import warn
from github import Github
from tqdm import tqdm
except ImportError:
from warnings import warn
warn('tqdm not installed. This script takes approximately 5 minutes '
'to run. To view live progressbars, please install tqdm. '
'Otherwise, be patient.')
def tqdm(i, **kwargs):
return i
GH_USER = 'scikit-image'
GH_REPO = 'scikit-image'
GH_TOKEN = os.environ.get('GH_TOKEN')
if GH_TOKEN is None:
raise RuntimeError(
"It is necessary that the environment variable `GH_TOKEN` "
"be set to avoid running into problems with rate limiting. "
"One can be acquired at\n\n"
"You do not need to select any permission boxes while generating "
"the token.")
g = Github(GH_TOKEN)
repository = g.get_repo(f'{GH_USER}/{GH_REPO}')
parser = argparse.ArgumentParser(usage=__doc__)
parser.add_argument('from_commit', help='The starting tag.')
parser.add_argument('to_commit', help='The head branch.')
parser.add_argument('--version', help="Version you're about to release.",
args = parser.parse_args()
for tag in repository.get_tags():
if == args.from_commit:
previous_tag = tag
raise RuntimeError(f'Desired tag ({args.from_commit}) not found')
# For some reason, go get the github commit from the commit to get
# the correct date
github_commit = previous_tag.commit.commit
previous_tag_date = datetime.strptime(github_commit.last_modified,
'%a, %d %b %Y %H:%M:%S %Z')
all_commits = list(tqdm(repository.get_commits(sha=args.to_commit,
desc=f'Getting all commits between {args.from_commit} '
f'and {args.to_commit}'))
all_hashes = set(c.sha for c in all_commits)
authors = set()
reviewers = set()
committers = set()
users = dict() # keep track of known usernames
def find_author_info(commit):
"""Return committer and author of a commit.
commit : Github commit
The commit to query.
committer : str or None
The git committer.
author : str
The git author.
committer = None
if commit.committer is not None:
committer = or commit.committer.login
git_author = commit.raw_data['commit']['author']['name']
if is not None:
author = or + f' ({git_author})'
# Users that deleted their accounts will appear as None
author = git_author
return committer, author
def add_to_users(users, new_user):
if is None:
users[new_user.login] = new_user.login
users[new_user.login] =
for commit in tqdm(all_commits, desc='Getting commiters and authors'):
committer, author = find_author_info(commit)
if committer is not None:
# users maps github ids to a unique name.
add_to_users(users, commit.committer)
if is not None:
# this gets found as a commiter
committers.discard('GitHub Web Flow')
authors.discard('Azure Pipelines Bot')
highlights = OrderedDict()
highlights['New Feature'] = {}
highlights['Improvement'] = {}
highlights['Bugfix'] = {}
highlights['API Change'] = {}
highlights['Deprecations'] = {}
highlights['Build Tool'] = {}
other_pull_requests = {}
for pull in tqdm(g.search_issues(f'repo:{GH_USER}/{GH_REPO} '
f'merged:>{previous_tag_date.isoformat()} '
desc='Pull Requests...'):
pr = repository.get_pull(pull.number)
if pr.merge_commit_sha in all_hashes:
summary = pull.title
for review in pr.get_reviews():
if review.user.login not in users:
users[review.user.login] =
for key, key_dict in highlights.items():
pr_title_prefix = (key + ': ').lower()
if summary.lower().startswith(pr_title_prefix):
key_dict[pull.number] = {
'summary': summary[len(pr_title_prefix):]
other_pull_requests[pull.number] = {
'summary': summary
# add Other PRs to the ordered dict to make doc generation easier.
highlights['Other Pull Request'] = other_pull_requests
# Now generate the release notes
announcement_title = f'Announcement: scikit-image {args.version}'
print('=' * len(announcement_title))
We're happy to announce the release of scikit-image v{args.version}!
scikit-image is an image processing toolbox for SciPy that includes algorithms
for segmentation, geometric transformations, color space manipulation,
analysis, filtering, morphology, feature detection, and more.
For more information, examples, and documentation, please visit our website:
for section, pull_request_dicts in highlights.items():
if not pull_request_dicts:
print(f'{section}s\n{"*" * (len(section)+1)}')
for number, pull_request_info in pull_request_dicts.items():
print(f'- {pull_request_info["summary"]} (#{number})')
contributors = OrderedDict()
contributors['authors'] = authors
#contributors['committers'] = committers
contributors['reviewers'] = reviewers
for section_name, contributor_set in contributors.items():
committer_str = (f'{len(contributor_set)} {section_name} added to this '
'release [alphabetical by first name or login]')
print('-' * len(committer_str))
for c in sorted(contributor_set, key=str.lower):
print(f'- {c}')
You can’t perform that action at this time.