From 282e1c523695d45e0519c84e5a0233972ded5c8c Mon Sep 17 00:00:00 2001 From: kasun Date: Sun, 22 Nov 2026 19:27:04 +0100 Subject: [PATCH] chore: add read-only CI wait to the Gitea helper Polling CI with a shell loop triggered a permission prompt during /merge. A dedicated WAIT command can be allowlisted on its own. --- .claude/scripts/gitea.sh | 27 +++++++++++++++++++++++++++ .claude/settings.json | 1 + .claude/skills/merge/SKILL.md | 8 ++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/.claude/scripts/gitea.sh b/.claude/scripts/gitea.sh index 5d8e79f..f4e3130 100755 --- a/.claude/scripts/gitea.sh +++ b/.claude/scripts/gitea.sh @@ -15,6 +15,10 @@ # PATH path below /api/v1, e.g. /repos/kasun/homelab-infrastructure-as-code/pulls?state=open # BODY JSON string, or @file to send a file # +# Read-only CI wait: gitea.sh WAIT /repos/OWNER/REPO/commits/SHA/status +# Polls until checks finish. Exit 0: passed or no CI ran. 1: a check failed. +# 2: bad usage. 3: timed out after 15 minutes. +# # Config (outside the repo, never committed): # ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/url e.g. http://192.168.1.208:3000 # ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/token chmod 600 @@ -28,6 +32,29 @@ method=${1:?usage: gitea.sh METHOD PATH [BODY]} path=${2:?usage: gitea.sh METHOD PATH [BODY]} body=${3:-} +if [[ "$method" == "WAIT" ]]; then + [[ "$path" =~ ^/repos/[^/]+/[^/]+/commits/[0-9a-f]{40}/status$ ]] \ + || { echo "WAIT only accepts /repos/OWNER/REPO/commits/SHA/status" >&2; exit 2; } + for ((i = 1; i <= 45; i++)); do + status=$("$0" GET "$path") || status='{}' + total=$(jq '.statuses // [] | length' <<<"$status") + running=$(jq '[.statuses // [] | .[] | select(.status == "pending" or .status == "running")] | length' <<<"$status") + # Give checks time to register. Path-filtered workflows may never start any. + if (( total == 0 && i >= 7 )); then + echo "no CI ran" + exit 0 + fi + if (( total > 0 && running == 0 && i >= 4 )); then + jq -r '.statuses[] | "\(.context): \(.status) \(.target_url)"' <<<"$status" + jq -e '[.statuses[].status] | any(. == "failure" or . == "error") | not' <<<"$status" >/dev/null || exit 1 + exit 0 + fi + sleep 20 + done + echo "timed out waiting for CI" >&2 + exit 3 +fi + case "$method" in GET | POST | PATCH | PUT | DELETE) ;; *) echo "unsupported method: $method" >&2; exit 2 ;; diff --git a/.claude/settings.json b/.claude/settings.json index 366c9b4..79cc6b0 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -62,6 +62,7 @@ "Bash(git add *)", "Bash(git switch *)", "Bash(.claude/scripts/gitea.sh GET *)", + "Bash(.claude/scripts/gitea.sh WAIT *)", "Bash(.claude/scripts/gitea.sh POST *)", "Bash(git commit *)", "Bash(git push *)", diff --git a/.claude/skills/merge/SKILL.md b/.claude/skills/merge/SKILL.md index 9ebd500..3dca90f 100644 --- a/.claude/skills/merge/SKILL.md +++ b/.claude/skills/merge/SKILL.md @@ -71,11 +71,11 @@ Unless one exists, run `.claude/scripts/gitea.sh POST $REPO/pulls @` ## 6. Wait for CI -Get the SHA with `git rev-parse HEAD`, then repeat `.claude/scripts/gitea.sh GET $REPO/commits//status` until the state settles. +Get the SHA with `git rev-parse HEAD`, then run `.claude/scripts/gitea.sh WAIT $REPO/commits//status` as a background command. Do not write a polling loop, because that causes a permission prompt. -- `success`: continue. -- `failure` or `error`: stop, and report the failing check and its `target_url`. -- No statuses after about two minutes: workflows are path-filtered, so treat this as no CI for this PR and continue. +- Exit 0: checks passed, or it printed `no CI ran` because workflows are path-filtered. Continue. +- Exit 1: stop, and report the failing check and its `target_url`. +- Exit 3: CI timed out. Stop and report it. Then run `.claude/scripts/gitea.sh GET $REPO/pulls/` and confirm `mergeable` is true.