#!/bin/sh # issue-status-autoflip.sh — PostToolUse(Agent):派工出去的當下,把那張票自動改成 s/doing。 # # 🔴 為什麼要自動(leo 2026-08-09): # 「你可以設置一個當你改變狀態時會自動改 status 標籤嗎? # 你從 pending 在執行,當你派出時就自動改成 doing 能做到嗎?」 # # 2026-08-09 這一天總管手動改了二十幾次標籤。**漏一次,看板就在說謊**—— # 而 leo 是靠那個看板判斷「還剩什麼」。用錯誤訊號佔用他的注意力, # 比沒有訊號更糟(他會以為沒人在做,或以為有人在做)。 # ⇒ 這種「每次都要記得做」的事,就是該讓機器做的事。 # # 做什麼:從派工單裡認出工單號(只認 `【工單】` 那一行附近的 owner/repo#N 格式), # 呼叫 Gitea API 把 s/doing 貼上去(scope label 互斥,舊狀態自動掉)。 # # 刻意不做的: # - **不自動改回 pending/stage/closed**。那些要看「做出來的東西對不對」, # 是判斷,不是事件。自動化只能做「派出去了」這種客觀事實。 # - 不擋任何東西。失敗就安靜略過——這是便利設施,不是安全閘, # 絕不能因為它掛掉而卡住派工。 set -eu PAYLOAD=$(cat 2>/dev/null || echo '{}') # 只從【工單】那一行抓,避免把內文隨手提到的 #NN 當成本次工單 SPEC=$(printf '%s' "$PAYLOAD" | python3 -c ' import sys, json, re try: d = json.load(sys.stdin) except Exception: sys.exit(0) p = (d.get("tool_input") or {}).get("prompt") or "" for line in p.splitlines(): if "【工單】" not in line: continue m = re.search(r"([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)#(\d+)", line) if m: print(f"{m.group(1)} {m.group(2)} {m.group(3)}") break ' 2>/dev/null || true) [ -n "$SPEC" ] || exit 0 set -- $SPEC OWNER="$1"; REPO="$2"; NUM="$3" # token 從該 repo 的 gitea remote 取;取不到就安靜結束(不影響派工) for d in "$CLAUDE_PROJECT_DIR/products/$REPO" "$CLAUDE_PROJECT_DIR/matrix/$REPO" "$CLAUDE_PROJECT_DIR"; do [ -d "$d/.git" ] || continue URL=$(git -C "$d" remote get-url gitea 2>/dev/null) || continue case "$URL" in *@*) break ;; esac done [ -n "${URL:-}" ] || exit 0 TOKEN=$(printf '%s' "$URL" | sed -E 's|.*//[^:]+:([^@]+)@.*|\1|') HOST=$(printf '%s' "$URL" | sed -E 's|.*@([^/]+)/.*|\1|') [ "$TOKEN" != "$URL" ] || exit 0 curl -s -o /dev/null --max-time 8 \ -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ -d '{"labels":["s/doing"]}' \ "https://$HOST/api/v1/repos/$OWNER/$REPO/issues/$NUM/labels" 2>/dev/null || true exit 0