53 lines
1.8 KiB
Bash
53 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# providers/forgejo.sh
|
|
# Forgejo REST API provider implementation.
|
|
# =============================================================================
|
|
|
|
provider_name() {
|
|
echo "Forgejo (${FORGEJO_URL})"
|
|
}
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# provider_create_repo <name> <description> <private: true|false>
|
|
# ---------------------------------------------------------------------------
|
|
provider_create_repo() {
|
|
local name="$1"
|
|
local desc="$2"
|
|
local private="$3"
|
|
local auto_init="${4:-false}" # genomi: true (submodule add esige un branch). master: false (git init locale + push).
|
|
|
|
local http_code
|
|
http_code=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-X POST "${FORGEJO_URL}/api/v1/user/repos" \
|
|
-d "{
|
|
\"name\": \"${name}\",
|
|
\"description\": \"${desc}\",
|
|
\"private\": ${private},
|
|
\"auto_init\": ${auto_init}
|
|
}")
|
|
|
|
case "$http_code" in
|
|
201) success "Repository '${name}' created successfully." ;;
|
|
409) info "Repository '${name}' already exists - skipping." ;;
|
|
401) error "Unauthorized. Check your FORGEJO_TOKEN."; return 1 ;;
|
|
*) error "Forgejo API returned HTTP ${http_code}. Check connectivity."; return 1 ;;
|
|
esac
|
|
}
|
|
|
|
provider_clone_url() {
|
|
echo "${FORGEJO_URL}/${FORGEJO_USER}/${1}.git"
|
|
}
|
|
|
|
provider_ssh_url() {
|
|
local host
|
|
# Extract hostname by removing protocol and trailing slashes
|
|
host=$(echo "${FORGEJO_URL}" | sed -e 's|^[^/]*//||' -e 's|/*$||')
|
|
echo "ssh://git@${host}:${FORGEJO_SSH_PORT:-222}/${FORGEJO_USER}/${1}.git"
|
|
}
|
|
|
|
provider_web_url() {
|
|
echo "${FORGEJO_URL}/${FORGEJO_USER}/${1}"
|
|
}
|