-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclone_repos.py
38 lines (32 loc) · 1.38 KB
/
clone_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
import requests
import os
def get_user_repositories(username, token):
headers = {"Authorization": f"Bearer {token}"}
url = f"https://api.github.com/users/{username}/repos"
params = {"per_page": 100} # Adjust the per_page parameter as needed
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
return response.json()
else:
print(f"Failed to retrieve repositories for user {username}")
print(f"Response: {response.text}")
return None
def clone_repositories(repositories, destination_folder, repo_prefix):
os.makedirs(destination_folder, exist_ok=True)
os.chdir(destination_folder)
for repo in repositories:
repo_name = repo["name"]
if repo_name.startswith(repo_prefix):
repo_url = repo["clone_url"]
os.system(f"git clone {repo_url}")
if __name__ == "__main__":
github_username = "buluma"
github_token = "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" # Generate a token with repo scope from https://github.com/settings/tokens
repo_prefix = "ansible-role-"
repos = get_user_repositories(github_username, github_token)
if repos:
destination_folder = "../roles"
clone_repositories(repos, destination_folder, repo_prefix)
print("Repositories cloned successfully.")
else:
print("Failed to retrieve repositories.")