Commit automático inicial
This commit is contained in:
@@ -7,32 +7,18 @@
|
||||
{
|
||||
"id": "Hbol",
|
||||
"code_hash": "1d0db38904205bec4d6f6f6a1f6cec3e",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "data",
|
||||
"data": {
|
||||
"text/plain": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"id": "kzWc",
|
||||
"id": "MJUe",
|
||||
"code_hash": "2413ef4b5efa1b061ff30e1416c01c0c",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "data",
|
||||
"data": {
|
||||
"text/html": "<span class=\"markdown prose dark:prose-invert\"><h1 id=\"github-crear-repo-y-subirlo\">Github: Crear repo y subirlo</h1></span>"
|
||||
}
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"id": "KsAh",
|
||||
"code_hash": "a8b08f30b385ad82f8918f577e5deb8f",
|
||||
"id": "vblA",
|
||||
"code_hash": "a92967bc0016cfde12c8b2258eff72d8",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "data",
|
||||
@@ -41,63 +27,35 @@
|
||||
}
|
||||
}
|
||||
],
|
||||
"console": [
|
||||
{
|
||||
"type": "stream",
|
||||
"name": "stdout",
|
||||
"text": "Resultado creaci\u00f3n: ok: controlando_git_desde_python http://egutierrez:7dedbd8257bd85ac023d18fb15f3c26d6fb3c3b5@10.8.0.6:3123//egutierrez/controlando_git_desde_python.git\n"
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"type": "stream",
|
||||
"name": "stdout",
|
||||
"text": "\n\n\n"
|
||||
},
|
||||
"id": "bkHC",
|
||||
"code_hash": "2eff9bb2e2805bcf6df002bde0fff45f",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "stream",
|
||||
"name": "stdout",
|
||||
"text": "[master ba677af] Commit autom\u00e1tico inicial\n 1 file changed, 1 insertion(+), 1 deletion(-)\n"
|
||||
},
|
||||
{
|
||||
"type": "stream",
|
||||
"name": "stdout",
|
||||
"text": "Branch 'master' set up to track remote branch 'master' from 'origin'.\n"
|
||||
"type": "error",
|
||||
"ename": "exception",
|
||||
"evalue": "An ancestor raised an exception (NameError): ",
|
||||
"traceback": []
|
||||
}
|
||||
]
|
||||
],
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"id": "nSXV",
|
||||
"id": "lEQa",
|
||||
"code_hash": "1b76b63c5cef32f4010a58e6bcd112f3",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "data",
|
||||
"data": {
|
||||
"text/html": "<span class=\"markdown prose dark:prose-invert\"><span class=\"paragraph\">Aqui borramos si generamos sin querer, cuidado!</span></span>"
|
||||
}
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"id": "HxZB",
|
||||
"code_hash": "67b2c321a1a80633c3328a8f16239616",
|
||||
"outputs": [
|
||||
{
|
||||
"type": "data",
|
||||
"data": {
|
||||
"text/plain": ""
|
||||
}
|
||||
}
|
||||
],
|
||||
"console": [
|
||||
{
|
||||
"type": "stream",
|
||||
"name": "stdout",
|
||||
"text": "Resultado borrado: ok: controlando_git_desde_python borrado\n"
|
||||
}
|
||||
]
|
||||
"id": "PKri",
|
||||
"code_hash": "47f926182e3f327d1e9eaafe61d348d9",
|
||||
"outputs": [],
|
||||
"console": []
|
||||
},
|
||||
{
|
||||
"id": "ZYaS",
|
||||
"id": "Xref",
|
||||
"code_hash": null,
|
||||
"outputs": [],
|
||||
"console": []
|
||||
|
||||
+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