Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick and dirty utility to list all of the repositories which your account has access to
#!/usr/bin/env python3
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import subprocess
from getpass import getpass, getuser
import keyring
from github3 import authorize, login
def github_mfa_callback():
code = ''
while not code:
code = getpass('Enter 2FA code:')
return code
try:
username = subprocess.check_output('git config github.user'.split())
username = username.decode('utf-8').strip()
except subprocess.CalledProcessError:
username = getuser()
token = keyring.get_password('https://api.github.com', username)
if not token:
note = 'github repo lister'
note_url = 'https://github.com/acdha/'
scopes = ['user', 'repo']
password = getpass('Github password for %s:' % username)
auth = authorize(username, password, scopes, note, note_url,
two_factor_callback=github_mfa_callback)
keyring.set_password('https://api.github.com', username, auth.token)
gh = login(token=token)
for org in gh.iter_orgs():
for repo in org.iter_repos():
print('private' if repo.private else 'public', org.name, repo.name, repo.html_url,
sep='\t')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.