Last active
March 21, 2016 13:29
-
-
Save gsora/de0232283a084b75b73c to your computer and use it in GitHub Desktop.
Clone all the repos of given GitHub organizations
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 | |
| import json | |
| import argparse | |
| import os | |
| from urllib import request as r | |
| from urllib import error | |
| from subprocess import call as execute | |
| parser = argparse.ArgumentParser(description='Clone all the repos of given GitHub organizations, space-divided') | |
| parser.add_argument('orgnames', metavar='orgnames', type=str, nargs='+', | |
| help='GitHub organization name') | |
| args = parser.parse_args() | |
| orgnames = args.orgnames | |
| def clone(url): | |
| try: | |
| repos = r.urlopen("https://api.github.com/orgs/{}/repos".format(url)) | |
| except error.HTTPError: | |
| print("Organization not found, check your spelling maybe?") | |
| exit(1) | |
| jRepos = json.loads(repos.read().decode("utf-8")) | |
| for url in jRepos: | |
| rUrl = url["html_url"] | |
| print("Cloning {} in current director...".format(rUrl)) | |
| execute(["git", "clone", rUrl]) | |
| print("\n") | |
| for organization in orgnames: | |
| clone(organization) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment