Created
October 12, 2017 13:44
-
-
Save codysoyland/2a09e2ca13342697a8ebb9fc1584ce37 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
#!/usr/bin/env python | |
import requests | |
import subprocess | |
import re | |
import string | |
import textwrap | |
import argparse | |
def parse_args(): | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-u', '--github-username', help='Github username associated with API token', required=True) | |
parser.add_argument('-t', '--github-token', help='Github personal access token (https://github.com/settings/tokens)', required=True) | |
parser.add_argument('git_tag', help='Git tag to compare against master (e.g. "v0.6.0")') | |
return parser.parse_args() | |
def get_pr_ids(git_tag): | |
# Get list of pull request IDs | |
git_output = subprocess.check_output(['git', 'log', git_tag + '..master', '--merges', '--oneline']).decode('utf-8') | |
for message in git_output.splitlines(): | |
if 'Merge pull request' in message: | |
pr_search = re.search(r'#(\d+)', message) | |
if pr_search: | |
yield pr_search.groups()[0] | |
def get_pr_metadata(pr_id, github_creds): | |
# Collect metadata from Github API | |
pr = requests.get('https://api.github.com/repos/pilosa/pilosa/pulls/%s' % pr_id, auth=github_creds).json() | |
pr_meta = {} | |
pr_meta['pr_id'] = pr_id | |
pr_meta['title'] = pr['title'] | |
pr_meta['url'] = pr['html_url'] | |
return { | |
'pr_id': pr_id, | |
'title': pr['title'], | |
'url': pr['html_url'] | |
} | |
def main(): | |
args = parse_args() | |
for pr_id in get_pr_ids(args.git_tag): | |
pr_meta = get_pr_metadata(pr_id, github_creds=(args.github_username, args.github_token)) | |
print(string.Template('''- $title ([#$pr_id]($url))''').substitute(pr_meta)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment