From 7fb63778d4cd9995d077c18f5c435ac91110efad Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 15 Apr 2025 10:53:56 -0300 Subject: [PATCH] =?UTF-8?q?Atualiza=20arquivos=20de=20configura=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20projeto,=20ajustando=20o=20Dockerfile=20e=20requ?= =?UTF-8?q?irements.txt=20para=20melhor=20compatibilidade=20e=20desempenho?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- laborious/util/git_clone.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 laborious/util/git_clone.py diff --git a/laborious/util/git_clone.py b/laborious/util/git_clone.py new file mode 100644 index 0000000..8cfc362 --- /dev/null +++ b/laborious/util/git_clone.py @@ -0,0 +1,30 @@ +import os +from git import Repo +from urllib.parse import quote + +# Lê variáveis de ambiente +GIT_TOKEN = os.getenv("GIT_TOKEN") +GIT_EMAIL = os.getenv("GIT_EMAIL") +REPO_URL = os.getenv("REPO_URL") # ex: "github.com/usuario/repositorio.git" +CLONE_DIR = os.getenv("CLONE_DIR", "./repo_clonado") + +if not GIT_TOKEN or not GIT_EMAIL or not REPO_URL: + raise EnvironmentError("As variáveis GIT_TOKEN, GIT_EMAIL e REPO_URL devem estar definidas.") + +# Escapa o token (caso contenha caracteres especiais) +safe_token = quote(GIT_TOKEN) + +# Monta URL com autenticação via token +repo_url_with_auth = f"https://{safe_token}@{REPO_URL}" + +# Clona o repositório +print(f"Clonando repositório em {CLONE_DIR}...") +Repo.clone_from(repo_url_with_auth, CLONE_DIR) +print("Repositório clonado com sucesso.") + +# Opcional: configura o e-mail globalmente no Git (ou dentro do repo) +repo = Repo(CLONE_DIR) +with repo.config_writer() as git_config: + git_config.set_value("user", "email", GIT_EMAIL) + +print(f"E-mail configurado como {GIT_EMAIL}.")