65 lines
2.9 KiB
Python
65 lines
2.9 KiB
Python
import requests
|
|
import os
|
|
import subprocess
|
|
|
|
# Configurações
|
|
GITHUB_TOKEN = "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"
|
|
PROJECTS = [
|
|
"Q1Agenda", "Q1food", "Q1 SITE", "GoHorseJobs", "Q1Vestuario",
|
|
"PHOTUM", "SaveinMed", "Q1FIT", "THOR(q1fit)", "Zeus"
|
|
]
|
|
BASE_DIR = r"C:\dev"
|
|
|
|
def search_and_clone():
|
|
headers = {"Authorization": f"token {GITHUB_TOKEN}"}
|
|
|
|
for project in PROJECTS:
|
|
print(f"--- Buscando no GitHub: {project} ---")
|
|
|
|
# Buscar repositórios na conta/organização ou geral
|
|
# Vamos buscar especificamente em rede5 (se existir) ou no geral
|
|
query = f"{project} user:rede5" # Tentar primeiro na organização rede5
|
|
url = f"https://api.github.com/search/repositories?q={query}"
|
|
|
|
resp = requests.get(url, headers=headers).json()
|
|
|
|
if 'items' in resp and resp['items']:
|
|
repo = resp['items'][0] # Pega o primeiro resultado (mais relevante)
|
|
clone_url = repo['clone_url']
|
|
repo_name = repo['name']
|
|
|
|
# Adicionar o token na URL para clonagem automática
|
|
authed_clone_url = clone_url.replace("https://", f"https://{GITHUB_TOKEN}@")
|
|
|
|
target_path = os.path.join(BASE_DIR, repo_name)
|
|
|
|
if os.path.exists(target_path):
|
|
print(f" Aviso: Pasta {target_path} já existe. Pulando...")
|
|
else:
|
|
print(f" Clonando {repo_name} de {clone_url}...")
|
|
try:
|
|
subprocess.run(["git", "clone", authed_clone_url, target_path], check=True)
|
|
print(f" OK: Clonado com sucesso em {target_path}")
|
|
except Exception as e:
|
|
print(f" Erro ao clonar: {e}")
|
|
else:
|
|
# Tentar busca geral se não achar na rede5
|
|
print(f" Não encontrado na org 'rede5'. Tentando busca geral...")
|
|
query_global = project
|
|
url_global = f"https://api.github.com/search/repositories?q={query_global}"
|
|
resp_global = requests.get(url_global, headers=headers).json()
|
|
|
|
if 'items' in resp_global and resp_global['items']:
|
|
# Aqui é mais arriscado, vamos ver se o nome é exato
|
|
repo = next((r for r in resp_global['items'] if r['name'].lower() == project.lower()), None)
|
|
if repo:
|
|
authed_clone_url = repo['clone_url'].replace("https://", f"https://{GITHUB_TOKEN}@")
|
|
target_path = os.path.join(BASE_DIR, repo['name'])
|
|
if not os.path.exists(target_path):
|
|
print(f" Clonando (Global Match) {repo['name']}...")
|
|
subprocess.run(["git", "clone", authed_clone_url, target_path], check=True)
|
|
else:
|
|
print(f" Repositório '{project}' não localizado no GitHub.")
|
|
|
|
if __name__ == "__main__":
|
|
search_and_clone()
|