Created
March 17, 2014 04:21
-
-
Save PaulStovell/9593947 to your computer and use it in GitHub Desktop.
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
""" | |
Generate release notes from a GitHub milestone. | |
Forked from here: https://gist.github.com/unbracketed/3380407 | |
""" | |
MILESTONE_ID = 22 # The ID of the milestone (not the title) - get this from the query string | |
GITHUB_USER = '' # Your username | |
GITHUB_PASSWORD = '' # Your password | |
REPO = 'OctopusDeploy/Issues' # Format is username/repo | |
import requests | |
ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/{repo}/issues?state=closed&milestone={milestone}'.format(repo=REPO, milestone=MILESTONE_ID) | |
MILESTONE_FOR_REPO_URL = 'https://api.github.com/repos/{repo}/milestones/{milestone}'.format(repo=REPO, milestone=MILESTONE_ID) | |
AUTH = (GITHUB_USER, GITHUB_PASSWORD) | |
issues = [] | |
def get(url): | |
r = requests.get(url, auth=AUTH) | |
if not r.status_code == 200: | |
raise Exception(r.status_code) | |
return r | |
r = get(ISSUES_FOR_REPO_URL) | |
for issue in r.json(): | |
issues.append(issue) | |
if 'link' in r.headers: | |
pages = dict( | |
[(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in | |
[link.split(';') for link in | |
r.headers['link'].split(',')]]) | |
while 'last' in pages and 'next' in pages: | |
pages = dict( | |
[(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in | |
[link.split(';') for link in | |
r.headers['link'].split(',')]]) | |
r = get(pages['next']) | |
for issue in r.json(): | |
issues.append(issue) | |
if pages['next'] == pages['last']: | |
break | |
for issue in sorted(issues, key=lambda i: i['title']): | |
print ' - [{id}]({url}{id} - {title}'.format(id=issue['number'], url='https://github.com/OctopusDeploy/Issues/issues/', title=issue['title']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment