Skip to content

Instantly share code, notes, and snippets.

@mcouthon
Forked from ralphbean/list-all-repos.py
Last active March 17, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcouthon/07f9ee4e7c0b0e0597d1ade10d5f4c61 to your computer and use it in GitHub Desktop.
Save mcouthon/07f9ee4e7c0b0e0597d1ade10d5f4c61 to your computer and use it in GitHub Desktop.
Script to list all repos for a github organization
#!/usr/bin/env python
""" Print all of the clone-urls for a GitHub organization.
It requires the pygithub3 module, which you can install like this::
$ sudo yum -y install python-virtualenv
$ mkdir scratch
$ cd scratch
$ virtualenv my-virtualenv
$ source my-virtualenv/bin/activate
$ pip install pygithub3
Usage example::
$ python list-all-repos.py
Advanced usage. This will actually clone all the repos for a
GitHub organization or user::
$ for url in $(python list-all-repos.py); do git clone $url; done
"""
import pygithub3
def gather_repos(api_token, organization, no_forks=True):
gh = pygithub3.Github(token=api_token)
all_repos = gh.repos.list(user=organization).all()
for repo in all_repos:
# Don't print the urls for repos that are forks.
if no_forks and repo.fork:
continue
if repo.archived:
continue
yield repo
def print_repo_info(api_token, organization):
for repo in gather_repos(api_token, organization):
print(repo.name, repo.language, repo.languages_url, repo.updated_at)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment