40 lines
1,010 B
Bash
Executable file
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}\"
|
|
}"
|