Skip to content

Instantly share code, notes, and snippets.

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,
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
username = subprocess.check_output('git config github.user'.split())
username = username.decode('utf-8').strip()
except subprocess.CalledProcessError:
username = getuser()
token = keyring.get_password('', username)
if not token:
note = 'github repo lister'
note_url = ''
scopes = ['user', 'repo']
password = getpass('Github password for %s:' % username)
auth = authorize(username, password, scopes, note, note_url,
keyring.set_password('', 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',,, repo.html_url,
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.