#!/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 ["description"] # # Exemple : # ./create_repo.sh exercice "Adam" set -euo pipefail FORGE_URL="https://forge.gwenaelremond.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 [\"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}\" }"