Skip to content

Instantly share code, notes, and snippets.

@stefanor
Created August 14, 2020 19:03
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 stefanor/add8d40b9cabf9a7a94edecfb128020a to your computer and use it in GitHub Desktop.
Save stefanor/add8d40b9cabf9a7a94edecfb128020a to your computer and use it in GitHub Desktop.
Python fragment, mirroring repos from GitHub with pygithub3
repos = gh.repos.list_by_org(args.org).all()
for repo in repos:
log.debug("Mirroring %s", repo.full_name)
dirname = os.path.join(args.basedir, '%s.git' % repo.full_name)
userdir = os.path.dirname(dirname)
if not os.path.exists(userdir):
os.mkdir(userdir)
# Seed private forks from the org, when possible
if not os.path.exists(dirname) and repo.owner.login != args.org:
origin = os.path.join(args.basedir, args.org, '%s.git' % repo.name)
if os.path.exists(origin):
subprocess.check_call(('git', 'clone', '--mirror', '--quiet',
origin, dirname))
if not os.path.exists(dirname):
subprocess.check_call(('git', 'clone', '--mirror', '--quiet',
repo.clone_url, dirname))
else:
subprocess.check_call(('git', 'remote', 'set-url', 'origin',
repo.clone_url), cwd=dirname)
subprocess.check_call(('git', 'fetch', '--quiet', '--prune'),
cwd=dirname)
subprocess.check_call(('git', 'update-server-info'), cwd=dirname)
with open(os.path.join(dirname, 'description'), 'w') as f:
if repo.description:
f.write(repo.description.encode('UTF-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment