Skip to content

Instantly share code, notes, and snippets.

@billchen8888
Forked from xrotwang/list_repos.py
Created April 27, 2022 21:21
Show Gist options
  • Select an option

  • Save billchen8888/4289dcd395023688abfd4427da4b99a3 to your computer and use it in GitHub Desktop.

Select an option

Save billchen8888/4289dcd395023688abfd4427da4b99a3 to your computer and use it in GitHub Desktop.
List an organizations GitHub repositories and their size
import sys
import re
import requests
from hurry.filesize import size
NEXT = re.compile('\<(?P<url>[^\>]+)\>; rel\=\"next\"')
def get_repos(org):
repos = []
m = NEXT.search('<https://api.github.com/orgs/%s/repos>; rel="next"' % org)
while m:
res = requests.get(m.group('url'))
repos.extend(res.json())
m = NEXT.search(res.headers.get('link', ''))
return repos
if __name__ == '__main__':
repos = get_repos(sys.argv[1])
max_name = max([len(r['name']) for r in repos])
for repos in sorted(get_repos(sys.argv[1]), key=lambda r: r['size'], reverse=True):
print repos['name'].ljust(max_name + 1), size(repos['size'] * 1024)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment