Skip to content

Instantly share code, notes, and snippets.

@totetmatt
Created January 26, 2018 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totetmatt/7e76ddfe16971deaa8b6a48567317bf1 to your computer and use it in GitHub Desktop.
Save totetmatt/7e76ddfe16971deaa8b6a48567317bf1 to your computer and use it in GitHub Desktop.
Script to generate the contributor <-> project graph from an organization
from github import Github
import csv
GITHUB_TOKEN=""
ORGANIZATION=''
# or using an access token
g = Github(GITHUB_TOKEN)
with open('git_network.node.csv','w') as nodes:
writer_node = csv.DictWriter(nodes,fieldnames=['id','label','type'])
writer_node.writeheader()
with open('git_network.edge.csv','w') as edges:
writer_edge = csv.DictWriter(edges,fieldnames=['source','target'])
writer_edge.writeheader()
# Then play with your Github objects:
for repo in g.get_organization(ORGANIZATION).get_repos():
print(repo.name)
writer_node.writerow({'id':repo.name,'label':repo.name,'type':'repo'})
for c in repo.get_contributors():
writer_node.writerow({'id':c.login,'label':c.name,'type':'user'})
writer_edge.writerow({'source':c.login,'target':repo.name})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment