devops/create_repo.sh
Azmog 687f0eba16 Rend FORGE_URL configurable via variable d'environnement
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 11:59:48 +02:00

40 lines
1,010 B
Bash
Executable file

#!/usr/bin/env bash
#
# Crée un dépôt sur la forge via l'API.
#
# Usage :
# export FORGE_TOKEN="ton_token"
# ./create_repo.sh <nom_du_repo> ["description"]
#
# Exemple :
# ./create_repo.sh exercice "Adam"
set -euo pipefail
# URL de la forge : surchargeable via la variable d'environnement FORGE_URL
FORGE_URL="${FORGE_URL:-https://gitlab.cleanows.fr}"
# Token lu depuis la variable d'environnement (ne jamais l'écrire en dur)
if [[ -z "${FORGE_TOKEN:-}" ]]; then
echo "Erreur : la variable FORGE_TOKEN n'est pas définie." >&2
echo "Fais : export FORGE_TOKEN=\"ton_token\"" >&2
exit 1
fi
# Arguments
REPO_NAME="${1:-}"
REPO_DESC="${2:-}"
if [[ -z "$REPO_NAME" ]]; then
echo "Usage : $0 <nom_du_repo> [\"description\"]" >&2
exit 1
fi
curl -X POST "${FORGE_URL}/api/v1/user/repos" \
-H "Authorization: token ${FORGE_TOKEN}" \
-H "Content-Type: application/json" \
-H "accept: application/json" \
-d "{
\"name\": \"${REPO_NAME}\",
\"description\": \"${REPO_DESC}\"
}"