Created
March 10, 2016 19:38
-
-
Save acdha/1f01051b89c99201bd75 to your computer and use it in GitHub Desktop.
Quick and dirty utility to list all of the repositories which your account has access to
This file contains hidden or 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 | |
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