Skip to content

Instantly share code, notes, and snippets.

@NicolasGeraud
Last active July 16, 2016 10:05
Show Gist options
  • Save NicolasGeraud/7808a899ecfb5c3bee2c to your computer and use it in GitHub Desktop.
Save NicolasGeraud/7808a899ecfb5c3bee2c to your computer and use it in GitHub Desktop.
clone or fetch all Gravitee.io repositories.
import subprocess
import requests
import os
import sys
if len(sys.argv) < 2:
print("")
print("Usage: sync_gravitee.py [https | ssh]")
print(" clone mode : https or ssh")
sys.exit(1)
clone_mode = sys.argv[1]
def git(*args):
return subprocess.check_call(['git'] + list(args))
rootdir = os.getcwd()
page = 1
while True:
print('request https://api.github.com/orgs/gravitee-io/repos?page=' + str(page))
r = requests.get('https://api.github.com/orgs/gravitee-io/repos?page=' + str(page))
page = page+1
if len(r.json()) == 0:
break
for repo in r.json():
print("")
dirname = repo.get('name')
print(dirname)
clone_url = repo.get('clone_url')
if 'ssh' == clone_mode:
clone_url = repo.get('ssh_url')
if os.path.isdir(dirname):
os.chdir(dirname)
print("fetch --all --prune")
git("fetch", "--all", "--prune")
os.chdir(rootdir)
else:
print("clone ", clone_url)
git("clone", clone_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment