Commit automático inicial
This commit is contained in:
+52
-48
@@ -19,14 +19,20 @@ def _(mo):
|
||||
@app.cell
|
||||
def _():
|
||||
import os
|
||||
import requests
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
# Variables configurables
|
||||
HOST = "http://10.8.0.6:3123/" # Cambia entre GitHub, GitLab o tu servidor Gitea
|
||||
USERNAME = "egutierrez"
|
||||
TOKEN = "7dedbd8257bd85ac023d18fb15f3c26d6fb3c3b5" # Token personal / PAT
|
||||
TOKEN = os.environ["GITEA_TOKEN"] # Token personal / PAT
|
||||
return HOST, TOKEN, USERNAME, os
|
||||
|
||||
|
||||
@app.cell
|
||||
def _(HOST, TOKEN, USERNAME, os):
|
||||
import requests
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
# Nombre de la carpeta padre
|
||||
carpeta_actual = os.path.basename(os.getcwd())
|
||||
@@ -159,8 +165,7 @@ def _():
|
||||
|
||||
if resultado.startswith("ok:"):
|
||||
commit_and_push(resultado)
|
||||
|
||||
return HOST, TOKEN, USERNAME, requests
|
||||
return
|
||||
|
||||
|
||||
@app.cell
|
||||
@@ -170,56 +175,55 @@ def _(mo):
|
||||
|
||||
|
||||
@app.cell
|
||||
def _(HOST, TOKEN, USERNAME, requests):
|
||||
def _():
|
||||
|
||||
NOMBRE_REPO = "controlando_git_desde_python"
|
||||
# NOMBRE_REPO = ""
|
||||
|
||||
def borrar_repo(host, username, token, repo_name):
|
||||
"""Borra un repositorio en GitHub, GitLab o Gitea según el host.
|
||||
Devuelve 'ok: nombre_repo borrado' o 'fail'.
|
||||
"""
|
||||
headers = {"Content-Type": "application/json"}
|
||||
try:
|
||||
# --- GitHub ---
|
||||
if "github" in host:
|
||||
headers["Authorization"] = f"token {token}"
|
||||
api_url = "https://api.github.com"
|
||||
r = requests.delete(f"{api_url}/repos/{username}/{repo_name}", headers=headers)
|
||||
if r.status_code == 204:
|
||||
return f"ok: {repo_name} borrado"
|
||||
return "fail"
|
||||
# def borrar_repo(host, username, token, repo_name):
|
||||
# """Borra un repositorio en GitHub, GitLab o Gitea según el host.
|
||||
# Devuelve 'ok: nombre_repo borrado' o 'fail'.
|
||||
# """
|
||||
# headers = {"Content-Type": "application/json"}
|
||||
# try:
|
||||
# # --- GitHub ---
|
||||
# if "github" in host:
|
||||
# headers["Authorization"] = f"token {token}"
|
||||
# api_url = "https://api.github.com"
|
||||
# r = requests.delete(f"{api_url}/repos/{username}/{repo_name}", headers=headers)
|
||||
# if r.status_code == 204:
|
||||
# return f"ok: {repo_name} borrado"
|
||||
# return "fail"
|
||||
|
||||
# --- GitLab ---
|
||||
elif "gitlab" in host:
|
||||
headers["PRIVATE-TOKEN"] = token
|
||||
api_url = f"{host}/api/v4"
|
||||
# Ojo: GitLab usa ID o namespace/proyecto
|
||||
r = requests.delete(f"{api_url}/projects/{username}%2F{repo_name}", headers=headers)
|
||||
if r.status_code == 202:
|
||||
return f"ok: {repo_name} borrado"
|
||||
return "fail"
|
||||
# # --- GitLab ---
|
||||
# elif "gitlab" in host:
|
||||
# headers["PRIVATE-TOKEN"] = token
|
||||
# api_url = f"{host}/api/v4"
|
||||
# # Ojo: GitLab usa ID o namespace/proyecto
|
||||
# r = requests.delete(f"{api_url}/projects/{username}%2F{repo_name}", headers=headers)
|
||||
# if r.status_code == 202:
|
||||
# return f"ok: {repo_name} borrado"
|
||||
# return "fail"
|
||||
|
||||
# --- Gitea ---
|
||||
elif "gitea" in host or "http" in host:
|
||||
headers["Authorization"] = f"token {token}"
|
||||
api_url = f"{host}/api/v1"
|
||||
r = requests.delete(f"{api_url}/repos/{username}/{repo_name}", headers=headers)
|
||||
if r.status_code == 204:
|
||||
return f"ok: {repo_name} borrado"
|
||||
return "fail"
|
||||
# # --- Gitea ---
|
||||
# elif "gitea" in host or "http" in host:
|
||||
# headers["Authorization"] = f"token {token}"
|
||||
# api_url = f"{host}/api/v1"
|
||||
# r = requests.delete(f"{api_url}/repos/{username}/{repo_name}", headers=headers)
|
||||
# if r.status_code == 204:
|
||||
# return f"ok: {repo_name} borrado"
|
||||
# return "fail"
|
||||
|
||||
else:
|
||||
return "fail"
|
||||
# else:
|
||||
# return "fail"
|
||||
|
||||
except Exception as e:
|
||||
print("Error:", str(e))
|
||||
return "fail"
|
||||
# except Exception as e:
|
||||
# print("Error:", str(e))
|
||||
# return "fail"
|
||||
|
||||
|
||||
# Ejemplo de uso:
|
||||
resultado_borrado = borrar_repo(HOST, USERNAME, TOKEN, NOMBRE_REPO)
|
||||
print("Resultado borrado:", resultado_borrado)
|
||||
|
||||
# # Ejemplo de uso:
|
||||
# resultado_borrado = borrar_repo(HOST, USERNAME, TOKEN, NOMBRE_REPO)
|
||||
# print("Resultado borrado:", resultado_borrado)
|
||||
return
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user