Blog 2019/2/1
<- previous | index | next ->
This script gives you a convenient way to access your list of repos. Useful for piping the output into grep, etc.
Blog 2019/2/1
<- previous | index | next ->
This script gives you a convenient way to access your list of repos. Useful for piping the output into grep, etc.
#!/usr/bin/env python | |
# ls-repos.py: a simple script to list your github repos. | |
# usage: | |
# ./ls-repos.py | |
# list all repos in the form <org>/<repo> | |
# ./ls-repos.py <org> | |
# list all repos for an org in the form <repo> | |
# export LSREPOS_USERNAME and LSREPOS_PASSWORD to avoid prompts. | |
import getpass | |
import os | |
import sys | |
try: | |
import github | |
except: | |
sys.stderr.write("Error: github module not found.\n") | |
sys.stderr.write("Please 'sudo pip install PyGithub'.\n") | |
sys.exit(1) | |
orgname_filter = None | |
if len(sys.argv) > 1: | |
orgname_filter = sys.argv[-1] | |
if "LSREPOS_USERNAME" in os.environ: | |
username = os.environ["LSREPOS_USERNAME"] | |
else: | |
username = raw_input("github username: ") | |
if "LSREPOS_PASSWORD" in os.environ: | |
password = os.environ["LSREPOS_PASSWORD"] | |
else: | |
password = getpass.getpass("github password: ") | |
g = github.Github(username, password) | |
user = g.get_user() | |
repos = list(user.get_repos()) | |
for repo in repos: | |
fullname = repo.full_name | |
(orgname, reponame) = fullname.split('/') | |
if orgname_filter: | |
if orgname == orgname_filter: | |
print reponame | |
else: | |
print fullname |