Last active
August 29, 2015 13:57
-
-
Save Luzifer/9430214 to your computer and use it in GitHub Desktop.
Little script to list open pull-requests on GitHub across all repositories
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 | |
# Get an own access token from https://github.com/settings/applications | |
# and put it here to get this script working | |
access_token = 'nopeyoucantgetmine' | |
import urllib, urllib2, json, os, sys | |
rows, columns = [int(elem) for elem in os.popen('stty size', 'r').read().split()] | |
def request(path, params = {}): | |
params['access_token'] = access_token | |
url = 'https://api.github.com%s?%s' % (path, urllib.urlencode(params)) | |
return json.loads(urllib2.urlopen(url).read()) | |
def get_issues(): | |
return request('/issues', {'filter': 'created', 'sort': 'updated'}) | |
def get_pullrequest(repo, number): | |
return request('/repos/%s/pulls/%d' % (repo, number)) | |
def align_right(string, width): | |
return '%s%s' % (' ' * (width - len(string)), string) | |
for issue in get_issues(): | |
labels = ', '.join(['#%s' % elem['name'] for elem in issue['labels']]) | |
branch = get_pullrequest(issue['repository']['full_name'], issue['number'])['head']['ref'] | |
sys.stdout.write('\x1b[0;36m%s\x1b[0m\r' % align_right(labels, columns)) | |
sys.stdout.write(u'\x1b[0;32m%s\x1b[0m - \x1b[1;37m%s\x1b[0m \x1b[0;36m\u21A3 %s\x1b[0m\n' % (align_right(str(issue['number']), 4), issue['title'], issue['pull_request']['html_url'])) | |
sys.stdout.write('\x1b[0;33m%s\x1b[0m\r' % align_right(u'\u2325 %s' % branch, columns)) | |
sys.stdout.write('Opened by %s on %s, updated on %s, %d Comments\n' % (issue['user']['login'], issue['created_at'][0:10], issue['updated_at'][0:10], issue['comments'])) | |
sys.stdout.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BTW, not every issue is a pull request, this script explodes on my non-pull request issue