You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
924 B
Bash

#!/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
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 <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}\"
}"