-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path34_git_all_repos.py
43 lines (36 loc) · 1.08 KB
/
34_git_all_repos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import sys
import os
import requests
def get_total_repos(group, name):
repo_urls = []
page = 1
while True:
url = "https://api.github.com/{0}/{1}/repos?per_page=100&page={2}"
r = requests.get(url.format(group, name, page))
if r.status_code == 200:
rdata = r.json()
for repo in rdata:
repo_urls.append(repo["clone_url"])
if len(rdata) >= 100:
page += 1
else:
print("Found {0} repos.".format(len(repo_urls)))
break
else:
print(r)
return False
return repo_urls
def clone_repos(all_repos):
count = 1
print("Cloning...")
for repo in all_repos:
os.system("Git clone " + repo)
print("Completed repo #{0} of {1}".format(count, len(all_repos)))
count += 1
if __name__ == "__main__":
if len(sys.argv) > 2:
total = get_total_repos(sys.argv[1], sys.argv[2])
if total:
clone_repos(total)
else:
print("Usage: python USERS_OR_ORG GITHUB_USER_OR_ORG-NAME")