Upload files to ""
This commit is contained in:
parent
6da8d92b21
commit
81521c5cac
56
clone_repos.py
Normal file
56
clone_repos.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
import requests
|
||||||
|
from git import Repo
|
||||||
|
import os
|
||||||
|
|
||||||
|
def read_config():
|
||||||
|
os.chdir("/external/repos")
|
||||||
|
current_dir = os.getcwd()
|
||||||
|
print("Current directory:", current_dir)
|
||||||
|
with open("./config.txt", "r") as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
url = lines[0].strip()
|
||||||
|
token = lines[1].strip()
|
||||||
|
return url, token
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Read URL and token from config file
|
||||||
|
url, token = read_config()
|
||||||
|
|
||||||
|
# Perform request
|
||||||
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
# r = requests.get(url, headers=headers)
|
||||||
|
page = 1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
# Perform request with pagination
|
||||||
|
headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
params = {"page": page}
|
||||||
|
r = requests.get(url, headers=headers, params=params)
|
||||||
|
|
||||||
|
# Check if there are no more pages
|
||||||
|
if not r.json()["data"]:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Loop through each repository returned, cloning it
|
||||||
|
# Loop through each repository returned
|
||||||
|
for repository in r.json()["data"]:
|
||||||
|
repo_path = "repos/" + repository["full_name"]
|
||||||
|
|
||||||
|
# Check if the repository is already cloned
|
||||||
|
if os.path.exists(repo_path):
|
||||||
|
# Update the existing clone
|
||||||
|
repo = Repo(repo_path)
|
||||||
|
repo.remotes.origin.pull()
|
||||||
|
else:
|
||||||
|
# Clone the repository
|
||||||
|
Repo.clone_from(repository["clone_url"], repo_path, depth=1)
|
||||||
|
|
||||||
|
# Increment page number
|
||||||
|
page += 1
|
||||||
|
# Check if there are no more pages or repositories
|
||||||
|
if not r.json()["data"]:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user