Skip to content

Instantly share code, notes, and snippets.

@gustavofonseca
Created December 20, 2012 16:07
Show Gist options
  • Select an option

  • Save gustavofonseca/4346211 to your computer and use it in GitHub Desktop.

Select an option

Save gustavofonseca/4346211 to your computer and use it in GitHub Desktop.
Script that shows all pull-requests from all repos of an organization waiting for revision.
#!/usr/bin/env python
# coding: utf-8
"""
Script that shows all pull-requests from all repos of an
organization waiting for revision.
need to pip install prettytable
"""
import urllib2
import json
import base64
import sys
import getpass
from prettytable import PrettyTable
# fetch args from the CLI
if len(sys.argv) < 3:
exit('missing arguments <org> <username>')
orgname = sys.argv[1]
username = sys.argv[2]
passwd = getpass.getpass()
LIST_REPOS = 'https://api.github.com/orgs/{0}/repos'.format(orgname)
LIST_ISSUES = 'https://api.github.com/repos/{0}/%s/pulls'.format(orgname)
def make_request(url):
req = urllib2.Request(url)
auth = base64.standard_b64encode('%s:%s' % (username, passwd))
req.add_header('Authorization', 'Basic %s' % auth)
return urllib2.urlopen(req)
def list_org_repos(orgname):
response = json.loads(make_request(LIST_REPOS).read())
if 'message' in response:
sys.stderr.write(response)
exit(1)
for repo in response:
yield repo['name']
def list_repo_issues(repos):
for repo in repos:
response = json.load(make_request(LIST_ISSUES % repo))
if 'message' in response:
sys.stderr.write(response)
exit(1)
for issue in response:
d = {
'repo': repo,
'title': issue['title'],
'url': issue['url'],
'state': issue['state'],
'html_url': issue['html_url'],
}
yield d
def print_data(data):
t = PrettyTable(['Repository', 'Title', 'State', 'URL'])
t.align = 'l'
for i in data:
t.add_row([i['repo'], i['title'], i['state'], i['html_url']])
print t.get_string(sortby='Repository')
repos = list_org_repos(orgname)
assigned_issues = list_repo_issues(repos)
print_data(assigned_issues)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment