# Shared helpers for Peppa's Gitea scripts. Source after loading .env. : "${GITEA_URL:?}" "${GITEA_TOKEN:?set GITEA_TOKEN in .env}" GITEA_BOT_USER="${GITEA_BOT_USER:-peppa-bot}" gitea_api() { curl -fsS -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" "$@"; } # gitea_create_repo [extra-json-fields] # Repos owned by the bot user go through /user/repos, others through /orgs//repos. gitea_create_repo() { local owner=$1 name=$2 desc=$3 extra=${4:-} gitea_api "$GITEA_URL/api/v1/repos/$owner/$name" >/dev/null 2>&1 && return 0 local path="orgs/$owner/repos"; [ "$owner" = "$GITEA_BOT_USER" ] && path="user/repos" gitea_api -X POST "$GITEA_URL/api/v1/$path" \ -d "{\"name\":\"$name\",\"description\":\"$desc\",\"default_branch\":\"main\",\"private\":true$extra}" >/dev/null echo "created $owner/$name" } # Configures a local repo to push to Gitea as the bot via git-credential-peppa. gitea_git_setup() { git config credential.helper peppa git config user.name "Peppa" git config user.email "$GITEA_BOT_USER@telecom.quest" }