#!/usr/bin/env bash set -euo pipefail : "${GITEA_BASE_URL:?Set GITEA_BASE_URL (e.g., https://gitea.qortal.link)}" : "${GITEA_TOKEN:?Set GITEA_TOKEN}" : "${OWNER:?Set OWNER}" : "${REPO:?Set REPO}" MS_ID="${1:-}" api() { curl -sS -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" "${GITEA_BASE_URL}/api/v1$1" } if [[ -z "${MS_ID}" ]]; then echo "Auto-detecting 'Phase 0' milestone id..." MS_ID="$(api "/repos/${OWNER}/${REPO}/milestones?state=open" | jq -r '.[] | select(.title|test("Phase 0"; "i")) | .id' | head -n1)" fi if [[ -z "${MS_ID}" || "${MS_ID}" == "null" ]]; then echo "Could not find Phase 0 milestone. Pass an ID explicitly: $0 " exit 2 fi echo "Closing milestone id=${MS_ID}" curl -sS -X PATCH -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" "${GITEA_BASE_URL}/api/v1/repos/${OWNER}/${REPO}/milestones/${MS_ID}" --data '{"state":"closed"}' | jq -r '{id, title, state}'