feat(demo): reset deletes the demo repositories' issues, PRs and branches

A rerun should start from nothing. DEMO_REPOS is the entire blast radius and
is deliberately explicit: a real service's issues are genuine triage records,
and clearing them to tidy a demo would destroy the evidence the system exists
to produce.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
jenkins 2026-08-06 16:24:53 -03:00
parent e9c2d84dbc
commit e93dc7b8a8

View File

@ -82,43 +82,65 @@ cmd_monitor() {
exec python3 "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hermes_triage_monitor.py" exec python3 "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/hermes_triage_monitor.py"
} }
# Restores only what the demo itself creates. Real service repositories are # Deletes the demo repositories' issues, pull requests and repair branches so a
# never touched: those issues are genuine triage records and deleting them to # rerun starts from nothing. DEMO_REPOS is the whole blast radius and is
# tidy a demo would destroy the evidence the system exists to produce. # deliberately explicit: a real service's issues are genuine triage records,
# and clearing them to tidy a demo would destroy the evidence the system
# exists to produce.
DEMO_REPOS="${DEMO_REPOS:-hermes-code-demo}"
cmd_reset() { cmd_reset() {
require_jenkins require_jenkins
say "Reset — restoring the demo to its pre-run state" say "Reset — restoring the demo to its pre-run state"
note "fixture -> healthy" note "fixture -> healthy"
kubectl -n "$DEMO_NS" patch cm hermes-triage-demo-fixture \ if kubectl -n "$DEMO_NS" patch cm hermes-triage-demo-fixture \
--type merge -p '{"data":{"state":"healthy"}}' >/dev/null 2>&1 && --type merge -p '{"data":{"state":"healthy"}}' >/dev/null 2>&1; then
note " fixture: $(kubectl -n "$DEMO_NS" get cm hermes-triage-demo-fixture -o jsonpath='{.data.state}')" || note " fixture: $(kubectl -n "$DEMO_NS" get cm hermes-triage-demo-fixture -o jsonpath='{.data.state}')"
else
note " fixture patch failed (is the demo namespace present?)" note " fixture patch failed (is the demo namespace present?)"
fi
local gitea="${GITEA_URL:-https://scm.bstein.dev}" local gitea="${GITEA_URL:-https://scm.bstein.dev}"
if [ -z "${GITEA_TOKEN:-}" ]; then if [ -z "${GITEA_TOKEN:-}" ]; then
note "GITEA_TOKEN unset; skipping pull request and branch cleanup" note "GITEA_TOKEN unset; skipping repository cleanup"
else else
note "closing open repair pull requests on hermes-code-demo" for repo in $DEMO_REPOS; do
local prs note "clearing bstein/$repo (demo repository)"
prs="$(curl -s -H "Authorization: token $GITEA_TOKEN" \ local items
"$gitea/api/v1/repos/bstein/hermes-code-demo/pulls?state=open" | items="$(curl -s -H "Authorization: token $GITEA_TOKEN" \
python3 -c 'import json,sys "$gitea/api/v1/repos/bstein/$repo/issues?state=all&limit=100" |
for p in json.load(sys.stdin): python3 -c 'import json,sys
print(p["number"], p["head"]["ref"])' 2>/dev/null || true)" for i in json.load(sys.stdin):
if [ -z "$prs" ]; then print(i["number"], "pr" if i.get("pull_request") else "issue")' 2>/dev/null || true)"
note " none open" if [ -z "$items" ]; then
else note " no issues or pull requests"
while read -r num ref; do else
[ -z "$num" ] && continue while read -r num kind; do
curl -s -o /dev/null -X PATCH -H "Authorization: token $GITEA_TOKEN" \ [ -z "$num" ] && continue
-H "Content-Type: application/json" -d '{"state":"closed"}' \ curl -s -o /dev/null -X DELETE -H "Authorization: token $GITEA_TOKEN" \
"$gitea/api/v1/repos/bstein/hermes-code-demo/pulls/$num" "$gitea/api/v1/repos/bstein/$repo/issues/$num"
curl -s -o /dev/null -X DELETE -H "Authorization: token $GITEA_TOKEN" \ note " deleted $kind #$num"
"$gitea/api/v1/repos/bstein/hermes-code-demo/branches/$ref" done <<< "$items"
note " closed #$num and deleted branch $ref" fi
done <<< "$prs"
fi local branches
branches="$(curl -s -H "Authorization: token $GITEA_TOKEN" \
"$gitea/api/v1/repos/bstein/$repo/branches" |
python3 -c 'import json,sys,urllib.parse
for b in json.load(sys.stdin):
if b["name"].startswith("hermes-repair/"):
print(urllib.parse.quote(b["name"], safe=""))' 2>/dev/null || true)"
if [ -z "$branches" ]; then
note " no repair branches"
else
for ref in $branches; do
curl -s -o /dev/null -X DELETE -H "Authorization: token $GITEA_TOKEN" \
"$gitea/api/v1/repos/bstein/$repo/branches/$ref"
note " deleted branch $(printf '%b' "${ref//%/\\x}")"
done
fi
done
fi fi
if [ -d "$CODE_REPO_DIR/.git" ]; then if [ -d "$CODE_REPO_DIR/.git" ]; then
@ -127,13 +149,14 @@ for p in json.load(sys.stdin):
if grep -q 'percent / 100' "$CODE_REPO_DIR/src/discount.py" 2>/dev/null; then if grep -q 'percent / 100' "$CODE_REPO_DIR/src/discount.py" 2>/dev/null; then
note " src/discount.py is correct; demo is armable" note " src/discount.py is correct; demo is armable"
else else
note " src/discount.py still carries the seeded defect — merge or revert it before demoing" note " src/discount.py still carries the seeded defect — revert it before demoing"
fi fi
else else
note "demo repository not cloned at $CODE_REPO_DIR; skipping" note "demo repository not cloned at $CODE_REPO_DIR; skipping"
fi fi
say "Ready" say "Ready"
note "real service repositories were not touched"
note "run 'preflight' next, then arm the fixture build" note "run 'preflight' next, then arm the fixture build"
} }