Created
May 21, 2018 16:01
-
-
Save bhardin/5532f33cd36a5d97e1740c73c0270847 to your computer and use it in GitHub Desktop.
Create nice looking PR notes from a milestone
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
from github import Github | |
import os | |
import sys | |
release = str(sys.argv[1]) | |
# or using an access token | |
GITHUB_ACCESS_TOKEN = os.environ['GITHUB_ACCESS_TOKEN'] | |
g = Github(GITHUB_ACCESS_TOKEN) | |
FEATURES = 'Feature' | |
repo = g.get_repo('carta/carta-web') | |
milestones = repo.get_milestones(state='all') | |
milestone = None | |
for m in milestones: | |
if m.title == release: | |
milestone = m | |
break | |
if not milestone: | |
raise RuntimeError("Milestone not found. :(") | |
issues = repo.get_issues(milestone=milestone, state='all') | |
PR_dict = {} | |
def print_items(name): | |
print("## {}".format(name.title())) | |
for issue in PR_dict[name]: | |
print(issue) | |
print("") | |
def print_features(): | |
# features first | |
print_items(FEATURES) | |
for name in sorted(PR_dict): | |
if name == FEATURES: | |
continue | |
print_items(name) | |
def add_issue_to_dict(label, item): | |
pr_array = PR_dict.get(label, []) | |
pr_array.append(item) | |
PR_dict[label] = pr_array | |
for i in issues: | |
custom_label = FEATURES # by default everything is a feature | |
if i.labels: | |
if len(i.labels) == 1: | |
custom_label = i.labels[0].name | |
else: | |
raise RuntimeError("Don't know how to parse multiple labels") | |
title = i.title | |
number = i.number | |
author = i.user.login | |
item = "#{pr_id}: {title} (@{author})".format( | |
title=title, | |
pr_id=number, | |
author=author | |
) | |
add_issue_to_dict(custom_label, item) | |
print_features() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment