Created
May 23, 2012 11:37
-
-
Save Schnouki/2774728 to your computer and use it in GitHub Desktop.
buddycloud contributors stats
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 python3 | |
#%# family=contrib | |
#%# capabilities=autoconf | |
from urllib.request import urlopen | |
import json | |
import re | |
import sys | |
def field(login): | |
# From http://munin-monitoring.org/wiki/notes_on_datasource_names | |
return re.sub(r"[^A-Za-z0-9_]", "_", login) | |
if len(sys.argv) > 1 and sys.argv[1] == "autoconf": | |
print("yes") | |
sys.exit(0) | |
# Get repositories list | |
resp = urlopen("https://api.github.com/orgs/buddycloud/repos") | |
repos = json.loads(resp.read().decode("utf-8")) | |
# Graph config if asked for | |
if len(sys.argv) > 1 and sys.argv[1] == "config": | |
print("graph_title Contributors per project") | |
print("graph_args --base 1000 --lower-limit 0") | |
print("graph_vlabel Number of contributors") | |
print("graph_category buddycloud contributors") | |
print("graph_info Number of contributors for each buddycloud project") | |
for repo in repos: | |
md = {"name": repo["name"], "fieldname": field(repo["name"]), "draw": "STACK"} | |
# Hardcode the name of the "AREA" entry in case the order changes... | |
if repo["name"] == "buddycloud-server": | |
md["draw"] = "AREA" | |
print("BC_PROJECT_{fieldname}.label {name}".format(**md)) | |
print("BC_PROJECT_{fieldname}.info {name}".format(**md)) | |
print("BC_PROJECT_{fieldname}.draw {draw}".format(**md)) | |
#print("BC_PROJECT_{fieldname}.type COUNTER".format(**md)) | |
# Else, get contributors for each repo and display graph data | |
else: | |
all_contrib = set() | |
for repo in repos: | |
fieldname = field(repo["name"]) | |
resp = urlopen("https://api.github.com/repos/{owner[login]}/{name}/contributors".format(**repo)) | |
contrib = json.loads(resp.read().decode("utf-8")) | |
print("BC_PROJECT_{fieldname}.value {nbcontrib}".format(fieldname=fieldname, nbcontrib=len(contrib))) | |
for user in contrib: | |
all_contrib.add(user["login"]) |
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 python3 | |
#%# family=contrib | |
#%# capabilities=autoconf | |
from urllib.request import urlopen | |
import json | |
import re | |
import sys | |
def field(login): | |
# From http://munin-monitoring.org/wiki/notes_on_datasource_names | |
return re.sub(r"[^A-Za-z0-9_]", "_", login) | |
if len(sys.argv) > 1 and sys.argv[1] == "autoconf": | |
print("yes") | |
sys.exit(0) | |
# Get repositories list | |
resp = urlopen("https://api.github.com/orgs/buddycloud/repos") | |
repos = json.loads(resp.read().decode("utf-8")) | |
# Get contributors for each repos | |
all_contrib = {} | |
for repo in repos: | |
resp = urlopen("https://api.github.com/repos/{owner[login]}/{name}/contributors".format(**repo)) | |
contrib = json.loads(resp.read().decode("utf-8")) | |
for user in contrib: | |
login, count = user["login"], user["contributions"] | |
if login not in all_contrib: | |
all_contrib[login] = 0 | |
all_contrib[login] += count | |
# Graph config if asked for | |
if len(sys.argv) > 1 and sys.argv[1] == "config": | |
print("graph_title buddycloud contributors") | |
print("graph_args --base 1000 --lower-limit 0") | |
print("graph_vlabel Number of commits") | |
print("graph_category buddycloud contributors") | |
print("graph_info Number of commits by each buddycloud contributor") | |
for login in sorted(all_contrib.keys()): | |
md = {"login": login, "fieldname": field(login), "draw": "STACK"} | |
# Hardcode the name of the "AREA" entry in case the order changes... | |
if login == "astro": | |
md["draw"] = "AREA" | |
print("BC_CONTRIB_{fieldname}.label {login}".format(**md)) | |
print("BC_CONTRIB_{fieldname}.info {login}".format(**md)) | |
print("BC_CONTRIB_{fieldname}.draw {draw}".format(**md)) | |
# Else, graph data | |
else: | |
for login, count in sorted(all_contrib.items(), key=lambda t: t[1], reverse=True): | |
print("BC_CONTRIB_{fieldname}.value {count}".format(fieldname=field(login), count=count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment