Files
ISEP/hooks/issue-status-autoflip.sh
T
Leo daa84b583f ISEP#47: source Gitea token from env/.env, not remote URL (9 scripts + credential helper)
- 6 hooks + gitea-labels-sync/wiki-panorama/gitea-bootstrap 全改用 gitea_token()
- wiki-panorama clone/fetch 改乾淨 URL + credential helper
- gitea-bootstrap 冪等清 remote URL + 設 credential.helper
- 驗證:bootstrap/labels-sync API 認證通過、clone/push 經 helper 無 token 洩漏

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kxf68FcYGqiuLAPiKKU2U3
2026-09-18 12:36:30 +00:00

59 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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 來源=env.envinkstone/ISEP#47),不再從 remote URL 抽;取不到就安靜結束(不影響派工)
_GT_LIB="$(dirname -- "$0")/../scripts/lib/gitea-token.sh"; [ -f "$_GT_LIB" ] && . "$_GT_LIB"
command -v gitea_token >/dev/null 2>&1 || exit 0
TOKEN=$(gitea_token) || exit 0
[ -n "$TOKEN" ] || exit 0
HOST="git.uncle6.me"
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