Files
2025-08-16 23:31:26 -04:00

76 lines
2.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# verify_phase0.sh — prints tracker sanity and issues for Phase 0 (prefers open "Phase 0", then "Patch 0")
# Usage: bash scripts/tracker/verify_phase0.sh [milestone_id]
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Auto-load .gitea.env if needed
if [[ -z "${GITEA_BASE_URL:-}" || -z "${OWNER:-}" || -z "${REPO:-}" || -z "${GITEA_TOKEN:-}" ]]; then
ENV_FILE="${HERE}/../../.gitea.env"
if [[ -f "$ENV_FILE" ]]; then
# shellcheck disable=SC1090
source "$ENV_FILE"
fi
fi
if [[ -z "${GITEA_BASE_URL:-}" || -z "${OWNER:-}" || -z "${REPO:-}" || -z "${GITEA_TOKEN:-}" ]]; then
echo "Missing Gitea env. Ensure .gitea.env exists or export GITEA_BASE_URL, OWNER, REPO, GITEA_TOKEN."
exit 1
fi
api() {
local path="$1"
curl -sS -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" "${GITEA_BASE_URL}/api/v1${path}"
}
# Basic sanity: user & labels
echo "== User =="
api "/user" | jq '{login, id}'
echo "== Labels (count) =="
api "/repos/${OWNER}/${REPO}/labels" | jq 'length'
# Fetch milestones once
MS_JSON="$(api "/repos/${OWNER}/${REPO}/milestones")"
echo "== Milestones =="
echo "$MS_JSON" | jq -c '.[] | {id, title, state, open_issues, closed_issues}' | jq .
# Choose milestone id
ms_id="${1:-}"
if [[ -z "${ms_id}" ]]; then
# Priority order: open Phase 0 → open Patch 0 → any Phase 0 → any Patch 0
for jqf in '.[] | select(.state=="open") | select(.title|test("(?i)phase 0")) | .id' '.[] | select(.state=="open") | select(.title|test("(?i)patch 0")) | .id' '.[] | select(.title|test("(?i)phase 0")) | .id' '.[] | select(.title|test("(?i)patch 0")) | .id'
do
cand="$(echo "$MS_JSON" | jq -r "$jqf" | head -n1)"
if [[ -n "${cand}" && "${cand}" != "null" ]]; then
ms_id="$cand"
break
fi
done
fi
if [[ -z "${ms_id:-}" ]]; then
echo "No matching milestone found (Phase 0 / Patch 0). Pass an ID explicitly."
exit 1
fi
# Print chosen milestone details
MS_OBJ="$(echo "$MS_JSON" | jq -c ".[] | select(.id==${ms_id})")"
if [[ -z "${MS_OBJ}" ]]; then
echo "Milestone #${ms_id} not found in repository."
exit 1
fi
title="$(echo "$MS_OBJ" | jq -r '.title')"
state="$(echo "$MS_OBJ" | jq -r '.state')"
echo "== Using milestone #${ms_id}${title} (${state}) =="
# Issues under chosen milestone (open)
echo "== Open issues in this milestone =="
api "/repos/${OWNER}/${REPO}/issues?milestones=${ms_id}&state=open" | jq -r '.[] | "#\(.number) \(.title)"'
# All open issues (with milestone name, for quick scan)
echo "== All Open Issues (title + milestone) =="
api "/repos/${OWNER}/${REPO}/issues?state=open" | jq -r '.[] | "\(.title) — [\(.milestone.title // "no milestone")]"'