Last active
November 21, 2015 12:51
-
-
Save kakwa/968cdc5db652e50d7d4d to your computer and use it in GitHub Desktop.
Quick and dirty script to display the number of opened issues and PRs on a list of Github projects
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 urllib2 | |
import json | |
import sys | |
import codecs | |
import base64 | |
# Quick and dirty script to display the number of opened issues and PRs on a list of Github projects | |
# How to use: | |
# | |
# 1) create a file with one project per line | |
# ex: | |
# pypyjs/pypyjs | |
# danderson/pixiecore | |
# gogits/gogs | |
# digitalfondue/lavagna | |
# notandy/ympd | |
# | |
# 2) launch the following command | |
# cat list | python ghipr.py | |
# or just use something like: | |
# printf "pypyjs/pypyjs\ngogits/gogs" | python ghipr.py | |
# | |
# add your username and your password | |
# otherwise, you will hit api rate limit pretty fast | |
username=None | |
password=None | |
if username and password: | |
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '') | |
else: | |
base64string = None | |
def get_gh(project='', page=1): | |
req = urllib2.Request(url='https://api.github.com/repos/' + project + '/issues?status=open&page=' + str(page)) | |
if base64string: | |
req.add_header("Authorization", "Basic %s" % base64string) | |
f = urllib2.urlopen(req) | |
return json.loads(f.read()) | |
total = {'issues': 0, 'pr': 0} | |
def get_issue_pr(project): | |
ret = {'issues': 0, 'pr': 0} | |
gh = get_gh(project) | |
#pp.pprint(gh) | |
lenght=(len(gh)) | |
page=1 | |
# result is paginated (30 entries by pages) | |
# we get all the pages | |
while lenght != 0: | |
for i in gh: | |
if 'pull_request' in i: | |
ret['pr'] = ret['pr'] + 1 | |
else: | |
ret['issues'] = ret['issues'] + 1 | |
page= page + 1 | |
gh = get_gh(project, page) | |
lenght=(len(gh)) | |
return ret | |
print('------------------------------------------------------------------') | |
if sys.version < '3': | |
char_stream = codecs.getreader("utf-8")(sys.stdin) | |
else: | |
char_stream = sys.stdin | |
for line in char_stream: | |
project = line.strip('\n') | |
# recover issues and pull requests count | |
t = get_issue_pr(project) | |
# q&d alignment | |
s1=' ' * (30 - len(project)) | |
s2=' ' * (4 - len(str(t['issues']))) | |
# print project info | |
print('Project: ' + project + s1 + '|| Issues: ' + str(t['issues']) + s2 + '|| PRs: ' + str(t['pr'])) | |
# increment total counters | |
total['issues'] = total['issues'] + t['issues'] | |
total['pr'] = total['pr'] + t['pr'] | |
# q&d alignment | |
s1=' ' * (30 + 8 - len('All of them')) | |
s2=' ' * (4 - len(str(total['issues']))) | |
# print global result | |
print('------------------------------------------------------------------') | |
print('All of them ' + s1 + '|| Issues: ' + str(total['issues']) + s2 + '|| PRs: ' + str(total['pr'])) | |
print('------------------------------------------------------------------') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment