From 54987909f9098ad686c1d9e645b60f93e998a2fc Mon Sep 17 00:00:00 2001 From: egutierrez Date: Thu, 11 Sep 2025 03:47:01 +0200 Subject: [PATCH] =?UTF-8?q?Commit=20autom=C3=A1tico=20inicial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __marimo__/session/github_crear_repo.py.json | 25 ++------------------ github_crear_repo.py | 19 +++++++++------ 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/__marimo__/session/github_crear_repo.py.json b/__marimo__/session/github_crear_repo.py.json index e44dd0d..debd747 100644 --- a/__marimo__/session/github_crear_repo.py.json +++ b/__marimo__/session/github_crear_repo.py.json @@ -32,7 +32,7 @@ }, { "id": "KsAh", - "code_hash": "9b30df28058d9b85e3f8b440bea8bd9e", + "code_hash": "a8b08f30b385ad82f8918f577e5deb8f", "outputs": [ { "type": "data", @@ -41,28 +41,7 @@ } } ], - "console": [ - { - "type": "stream", - "name": "stdout", - "text": "Resultado creaci\u00f3n: ok: controlando_git_desde_python http://10.8.0.6:3123/egutierrez/controlando_git_desde_python\n" - }, - { - "type": "stream", - "name": "stdout", - "text": "\n\n" - }, - { - "type": "stream", - "name": "stdout", - "text": "\n[master 253ac3b] Commit autom\u00e1tico inicial\n 1 file changed, 22 insertions(+), 1 deletion(-)\n" - }, - { - "type": "stream", - "name": "stdout", - "text": "Branch 'master' set up to track remote branch 'master' from 'origin'.\n" - } - ] + "console": [] }, { "id": "nSXV", diff --git a/github_crear_repo.py b/github_crear_repo.py index 0086389..c3e27ca 100644 --- a/github_crear_repo.py +++ b/github_crear_repo.py @@ -35,7 +35,7 @@ def _(): def crear_repo(host, username, token, repo_name, private=False, description=""): """Crea un repositorio en GitHub, GitLab o Gitea según el host. - Devuelve 'ok: nombre_repo url' o 'fail'. + Devuelve 'ok: nombre_repo url_push' o 'fail'. """ headers = {"Content-Type": "application/json"} @@ -51,7 +51,8 @@ def _(): payload = {"name": repo_name, "private": private, "description": description} r = requests.post(f"{api_url}/user/repos", headers=headers, json=payload) if r.status_code in (200, 201): - url = r.json().get("html_url", "") + # URL con token embebido para push HTTPS + url = f"https://{username}:{token}@github.com/{username}/{repo_name}.git" return f"ok: {repo_name} {url}" return "fail" @@ -70,7 +71,8 @@ def _(): } r = requests.post(f"{api_url}/projects", headers=headers, data=payload) if r.status_code in (200, 201): - url = r.json().get("web_url", "") + # URL con token para push + url = f"https://{username}:{token}@gitlab.com/{username}/{repo_name}.git" return f"ok: {repo_name} {url}" return "fail" @@ -85,7 +87,10 @@ def _(): payload = {"name": repo_name, "private": private, "description": description} r = requests.post(f"{api_url}/user/repos", headers=headers, json=payload) if r.status_code in (200, 201): - url = r.json().get("html_url", "") + # URL de push con token embebido + url = f"{host}/{username}/{repo_name}.git" + if url.startswith("http"): + url = url.replace("://", f"://{username}:{token}@") return f"ok: {repo_name} {url}" return "fail" @@ -95,7 +100,6 @@ def _(): except Exception: return "fail" - def run_cmd(cmd): """Ejecuta un comando en shell y muestra salida.""" @@ -110,7 +114,7 @@ def _(): def commit_and_push(resultado_creacion, commit_message="Commit automático inicial"): """ Recibe el resultado de crear_repo, por ejemplo: - 'ok: nombre_repo https://gitlab.com/usuario/nombre_repo' + 'ok: nombre_repo https://usuario:token@host/usuario/nombre_repo.git' Hace init, commit y push a ese remoto. """ if not resultado_creacion.startswith("ok:"): @@ -127,7 +131,7 @@ def _(): if not os.path.exists(".git"): run_cmd("git init") - # Detectar rama actual (master, main, etc.) + # Detectar rama actual result = subprocess.run( "git rev-parse --abbrev-ref HEAD", shell=True, text=True, capture_output=True @@ -155,6 +159,7 @@ def _(): if resultado.startswith("ok:"): commit_and_push(resultado) + return HOST, TOKEN, USERNAME, requests