Skip to content

Instantly share code, notes, and snippets.

@luismmontielg
Forked from bhardin/create_release_notes.py
Last active May 22, 2018 17:05
Show Gist options
  • Save luismmontielg/601283cada28c323684e080c0f8ea70c to your computer and use it in GitHub Desktop.
Save luismmontielg/601283cada28c323684e080c0f8ea70c to your computer and use it in GitHub Desktop.
Create nice looking PR notes from a milestone
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:
custom_label = ', '.join([label.name for label in i.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