Skip to content

Instantly share code, notes, and snippets.

@SamLR
Last active September 1, 2019 15:49
Show Gist options
  • Save SamLR/82f27a9096af2bf79817378cd335eb19 to your computer and use it in GitHub Desktop.
Save SamLR/82f27a9096af2bf79817378cd335eb19 to your computer and use it in GitHub Desktop.
from github import Github, GithubException
import json
from datetime import datetime
import os
def main(token):
g = Github(token)
alphagov = g.get_organization('alphagov')
mirror = g.get_organization('alphagov-mirror')
count=0
names = []
for repo in alphagov.get_repos('all'):
names.append(repo.name)
try:
mirror.create_fork(repo)
except GithubException as e:
print("Skipping %s, got error: %s"%(repo.name, e))
count += 1
if count % 10 == 0:
print("%d done"%count)
print("imported %d repositories"%count)
out_file_name = "out-%s.json"%datetime.now()
print("Writing %s"%out_file_name)
with open(out_file_name, "w") as out_file:
json.dump(names, out_file)
if __name__ == '__main__':
main(os.getenv("GITHUB_TOKEN"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment