-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_repositorio_github.sh
More file actions
88 lines (78 loc) · 2.4 KB
/
setup_repositorio_github.sh
File metadata and controls
88 lines (78 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
# setup_repositorio_github.sh - Script seguro para crear repositorios
# Configuración
ORGANIZACION="MechBot-2x"
NOMBRE_REPO="coding-kittens"
RAMA_PRINCIPAL="main"
DESCRIPCION="Programación cuántica con gatos 🐱💻"
VISIBILIDAD="false" # false = público, true = privado
# Función para obtener token de forma segura
obtener_token() {
if [ -z "$GITHUB_TOKEN" ]; then
if [ -f ".env" ]; then
source .env
else
echo -n "Ingrese su Token de Acceso Personal de GitHub: "
read -s GITHUB_TOKEN
echo
fi
fi
}
# Función para verificar el token
verificar_token() {
echo "Verificando token de GitHub..."
respuesta=$(curl -s -o /dev/null -w "%{http_code}" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user)
[ "$respuesta" -eq 200 ] && echo "✅ Token válido" || { echo "❌ Token inválido (HTTP $respuesta)"; return 1; }
}
# Función para crear el repositorio
crear_repositorio() {
echo "Creando repositorio $NOMBRE_REPO en $ORGANIZACION..."
respuesta=$(curl -s -o respuesta.json -w "%{http_code}" \
-X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/orgs/$ORGANIZACION/repos \
-d '{
"name": "'$NOMBRE_REPO'",
"description": "'"$DESCRIPCION"'",
"private": '$VISIBILIDAD',
"auto_init": true,
"default_branch": "'$RAMA_PRINCIPAL'"
}')
if [ "$respuesta" -eq 201 ]; then
echo "✅ Repositorio creado exitosamente"
URL_REPO=$(jq -r '.html_url' respuesta.json)
echo "🔗 $URL_REPO"
rm respuesta.json
else
echo "❌ Error al crear repositorio (HTTP $respuesta)"
[ -f "respuesta.json" ] && jq . respuesta.json
rm -f respuesta.json
return 1
fi
}
# Función para configurar Git
configurar_git() {
if [ -d .git ]; then
echo "Configurando repositorio local..."
git remote add origin https://$GITHUB_TOKEN@github.com/$ORGANIZACION/$NOMBRE_REPO.git
git branch -M $RAMA_PRINCIPAL
git push -u origin $RAMA_PRINCIPAL
echo "✅ Configuración Git completada"
else
echo "⚠️ No es un repositorio Git. Ejecuta 'git init' primero."
fi
}
# Ejecución principal
obtener_token
if verificar_token; then
if crear_repositorio; then
configurar_git
fi
fi
# Limpieza de seguridad
unset GITHUB_TOKEN
echo "🚀 Configuración completada!"