Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 54e479900a |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "isep",
|
"name": "isep",
|
||||||
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:42 支機械閘、7 支 slash command、2 支 skill、24 支腳本。本機與雲端裝同一份。",
|
"description": "InkStone Environment Plugin —— leo 的 Claude Code 環境唯一真相源:41 支機械閘、7 支 slash command、2 支 skill、23 支腳本。本機與雲端裝同一份。",
|
||||||
"version": "0.0.0",
|
"version": "0.1.0",
|
||||||
"keywords": ["inkstone", "guardrails", "hooks", "gitea", "arcrun"]
|
"keywords": ["inkstone", "guardrails", "hooks", "gitea", "arcrun"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
| | 數量 | 是什麼 |
|
| | 數量 | 是什麼 |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `hooks/` | 42 支 + `hooks.json` | 全部機械閘(PreToolUse/Stop/SubagentStop/SessionStart/PostToolUse 共 52 條註冊) |
|
| `hooks/` | 41 支 + `hooks.json` | 全部機械閘(PreToolUse/Stop/SubagentStop/SessionStart/PostToolUse 共 51 條註冊) |
|
||||||
| `commands/` | 7 支 | `/wiki-recall` `/ship-check` `/cp-write` … |
|
| `commands/` | 7 支 | `/wiki-recall` `/ship-check` `/cp-write` … |
|
||||||
| `skills/` | 2 支 | |
|
| `skills/` | 2 支 | |
|
||||||
| `scripts/` | 23 支 | `ticket`/`github-arm.sh`/`gitea-bootstrap.sh` … |
|
| `scripts/` | 23 支 | `ticket`/`github-arm.sh`/`gitea-bootstrap.sh` … |
|
||||||
@@ -43,14 +43,6 @@ hook 一律用官方的 `${CLAUDE_PLUGIN_ROOT}`,**不准寫死絕對路徑、
|
|||||||
🔴 **只改這裡,然後兩邊 `/plugin update`。**
|
🔴 **只改這裡,然後兩邊 `/plugin update`。**
|
||||||
不要再改 `InkStoneCo/.claude/hooks/`——那個目錄退場中。
|
不要再改 `InkStoneCo/.claude/hooks/`——那個目錄退場中。
|
||||||
|
|
||||||
## 版本
|
## 狀態
|
||||||
|
|
||||||
**「ISEP 現在是哪一版」只有一個地方答得出來:[Gitea Releases](https://git.uncle6.me/inkstone/ISEP/releases)。**
|
- 0.1.0 — 從 `InkStoneCo/.claude/` 搬過來,51 條 hook 路徑全部改成 `${CLAUDE_PLUGIN_ROOT}`
|
||||||
每一版的內容、改了什麼、驗過什麼都寫在那裡的 release note,不寫在這份 README。
|
|
||||||
|
|
||||||
這份 README 本來寫死過「狀態:0.1.0」,但 repo 一個 tag 都沒打(`release_counter=0`)——
|
|
||||||
leo 當場指出這是違規:宣稱交付卻沒有 tag 撐它(`inkstone/ISEP#6`)。
|
|
||||||
現在改成結構性防漂移:`.claude-plugin/plugin.json` 的 `version` 欄位永遠跟最新 tag 一致,
|
|
||||||
`scripts/check-version-consistency.sh` 會擋下兩者對不上的狀態,
|
|
||||||
`hooks/release-tag-guard.sh` 則在打 tag 的當下直接擋住不一致的 tag——
|
|
||||||
細節與判準都寫在那兩支腳本開頭的註解。
|
|
||||||
|
|||||||
@@ -32,10 +32,6 @@
|
|||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
|
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/leo21c-write-guard.sh"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "command",
|
|
||||||
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/release-tag-guard.sh"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# release-tag-guard.sh — PreToolUse(Bash):打 tag 那一刻擋下版本不一致
|
|
||||||
#
|
|
||||||
# 立這道閘的來由(inkstone/ISEP#6,2026-08-20):
|
|
||||||
# README.md 曾寫死「狀態:0.1.0」,但這個 repo `release_counter=0`、
|
|
||||||
# 一個 tag 都沒打。leo 當場指出這是違規,且命中規範自己的 E12
|
|
||||||
# (宣稱交付但沒有 tag);leo 補充:「release 不是寫在 readme,要放在 release 裡」。
|
|
||||||
#
|
|
||||||
# 這支閘解的不是「README 寫錯字」,是**結構性防漂移**:
|
|
||||||
# 「ISEP 現在是哪一版」只有一個地方答得出來= Gitea Releases(git tag)。
|
|
||||||
# `.claude-plugin/plugin.json` 的 `version` 欄位必須跟這個 tag 完全一致,
|
|
||||||
# 不然又回到「版本號在不同地方各說各話」的老路——只是這次換成
|
|
||||||
# 「manifest 一個號碼、tag 又一個號碼」而不是「README 一個號碼、repo 裡沒 tag」。
|
|
||||||
# 同一套判準也寫在 `scripts/check-version-consistency.sh`(可以隨時手動跑,
|
|
||||||
# 不必等到打 tag那一刻);這支 hook 是「結構性做不到」的那一半——
|
|
||||||
# 在真正動手打 tag 的當下擋住,而不是靠事後補跑腳本才發現。
|
|
||||||
#
|
|
||||||
# 🔴 紅線:**這支 hook 不打 tag、不建 release**——它只在別人(人類/總管)要打 tag 時
|
|
||||||
# 檢查一致性。真正打哪個版本號的 tag,是總管驗過整個 milestone 之後的動作。
|
|
||||||
#
|
|
||||||
# 設計紀律(沿用本 repo既有 guard 的兩條,見 main-and-prod-push-guard.sh 註解):
|
|
||||||
# • **先排除「談論/讀取/刪除/列出」**,只擋「真的要打一個新 tag」的那個命令形狀。
|
|
||||||
# • **抽不出版本號就不擋**(fail-open on 解析失敗,不是 fail-open on 檢查結果)——
|
|
||||||
# 避免因為指令格式特殊(例如帶簽名 `-s`、多行訊息)誤攔到人,
|
|
||||||
# 那正是「閘被誤攔多次會被繞過」的病根(README 段落引的 D95 同一款教訓)。
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
INPUT="$(cat)"
|
|
||||||
CMD=$(printf '%s' "$INPUT" | python3 -c '
|
|
||||||
import sys, json
|
|
||||||
try: print(json.load(sys.stdin).get("tool_input", {}).get("command", "") or "")
|
|
||||||
except Exception: print("")
|
|
||||||
' 2>/dev/null || printf '')
|
|
||||||
|
|
||||||
[ -z "$CMD" ] && exit 0
|
|
||||||
|
|
||||||
# ── 先排除不是「打新 tag」的動作 ──────────────────────────────────────
|
|
||||||
case "$CMD" in
|
|
||||||
sed\ *|cat\ *|grep\ *|head\ *|tail\ *|wc\ *|less\ *|ls\ *|awk\ *|rg\ *|echo\ *) exit 0 ;;
|
|
||||||
*"git tag -d"*|*"git tag --delete"*|*"git tag -l"*|*"git tag --list"*|*"git tag -n"*) exit 0 ;;
|
|
||||||
*" --dry-run"*|*"--dry-run "*) exit 0 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
case "$CMD" in
|
|
||||||
*"git tag "*) ;;
|
|
||||||
*) exit 0 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# ── 從命令裡萃取版本號(第一個 vX.Y.Z 或 X.Y.Z 樣式的 token)───────────
|
|
||||||
TAGNAME=$(printf '%s' "$CMD" | grep -oE 'v?[0-9]+\.[0-9]+\.[0-9]+' | head -1 || printf '')
|
|
||||||
[ -n "$TAGNAME" ] || exit 0 # 抽不出版本號=不是本閘管的形狀,不擋(見上方設計紀律)
|
|
||||||
|
|
||||||
VER=${TAGNAME#v}
|
|
||||||
|
|
||||||
PROJ="${CLAUDE_PROJECT_DIR:-$(pwd)}"
|
|
||||||
PLUGIN_JSON="$PROJ/.claude-plugin/plugin.json"
|
|
||||||
[ -f "$PLUGIN_JSON" ] || exit 0 # 不在 ISEP repo 裡(沒有這個檔案)=不是本閘管的 repo
|
|
||||||
|
|
||||||
PJVER=$(python3 -c "import json;print(json.load(open('$PLUGIN_JSON')).get('version',''))" 2>/dev/null || printf '')
|
|
||||||
[ -n "$PJVER" ] || exit 0
|
|
||||||
|
|
||||||
if [ "$PJVER" != "$VER" ]; then
|
|
||||||
cat >&2 <<MSG
|
|
||||||
🚫 版本不一致,擋下這次打 tag(inkstone/ISEP#6:版本結構性防漂移閘)
|
|
||||||
|
|
||||||
你想打的 tag:$TAGNAME(版本號 $VER)
|
|
||||||
.claude-plugin/plugin.json 現在的 version:$PJVER
|
|
||||||
|
|
||||||
兩者必須完全一致——「ISEP 現在是哪一版」只有 Gitea Releases 答得出來,
|
|
||||||
而 Releases 的 tag 名稱跟 plugin.json 的宣稱要是同一個數字,不然又是各說各話。
|
|
||||||
|
|
||||||
【怎麼過】把 .claude-plugin/plugin.json 的 version 改成 $VER,
|
|
||||||
連同這次要發的其他改動一起 commit,再重新打 tag $TAGNAME。
|
|
||||||
(或者你要打的其實是 $PJVER 這個號碼,那就把 tag 名稱改對。)
|
|
||||||
|
|
||||||
驗法一致的獨立腳本:scripts/check-version-consistency.sh
|
|
||||||
MSG
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
+113
@@ -0,0 +1,113 @@
|
|||||||
|
# ISEP labels.yaml — 全 inkstone org 的標籤唯一真相源
|
||||||
|
# 規約:改標籤=改本檔 → PR → release → 跑 scripts/gitea-labels-sync.sh
|
||||||
|
# scope 帶「/」且 exclusive:true 者,同票至多一個(Gitea 平台保證,非法狀態不可表示)
|
||||||
|
|
||||||
|
labels:
|
||||||
|
# ── 狀態機(exclusive,同票只能有一個)─────────────────
|
||||||
|
- name: "s/triage"
|
||||||
|
color: "d4c5f9"
|
||||||
|
exclusive: true
|
||||||
|
description: "新進來的,還沒驗傷——還沒決定要不要做"
|
||||||
|
- name: "s/backlog"
|
||||||
|
color: "c2e0c6"
|
||||||
|
exclusive: true
|
||||||
|
description: "驗過了、確定要做,但還沒排進任何 sprint"
|
||||||
|
- name: "s/todo"
|
||||||
|
color: "ededed"
|
||||||
|
exclusive: true
|
||||||
|
description: "已排進 milestone,等人領票"
|
||||||
|
- name: "s/doing"
|
||||||
|
color: "0e8a16"
|
||||||
|
exclusive: true
|
||||||
|
description: "進行中——已 self-assign,現在有人在做"
|
||||||
|
- name: "s/review"
|
||||||
|
color: "1d76db"
|
||||||
|
exclusive: true
|
||||||
|
description: "PR 已開(含 closes #n),等總管 review 並 merge"
|
||||||
|
- name: "s/stage"
|
||||||
|
color: "5319e7"
|
||||||
|
exclusive: true
|
||||||
|
description: "已部署 stage,等 leo 實際驗收"
|
||||||
|
- name: "s/pending"
|
||||||
|
color: "fbca04"
|
||||||
|
exclusive: true
|
||||||
|
description: "卡住——等外部/等依賴,不是沒人做"
|
||||||
|
|
||||||
|
# ── 關閉分類(exclusive,關票必掛恰好一個)──────────────
|
||||||
|
- name: "close/merged"
|
||||||
|
color: "0e8a16"
|
||||||
|
exclusive: true
|
||||||
|
description: "PR merge 自動關(正常路徑)"
|
||||||
|
- name: "close/human-exec"
|
||||||
|
color: "b60205"
|
||||||
|
exclusive: true
|
||||||
|
description: "人執票完成,由人手動關"
|
||||||
|
- name: "close/duplicate"
|
||||||
|
color: "cfd3d7"
|
||||||
|
exclusive: true
|
||||||
|
description: "重複——關新的、留舊的,並指向舊票"
|
||||||
|
- name: "close/wontfix"
|
||||||
|
color: "6c757d"
|
||||||
|
exclusive: true
|
||||||
|
description: "討論後決定不做(只有 leo 可下此判斷)"
|
||||||
|
- name: "close/transferred"
|
||||||
|
color: "cfd3d7"
|
||||||
|
exclusive: true
|
||||||
|
description: "走錯棚,已在正確的 repo 重開"
|
||||||
|
- name: "close/split"
|
||||||
|
color: "cfd3d7"
|
||||||
|
exclusive: true
|
||||||
|
description: "太大,已拆成數張子票"
|
||||||
|
- name: "close/stale"
|
||||||
|
color: "cfd3d7"
|
||||||
|
exclusive: true
|
||||||
|
description: "逾期無資訊,自動關閉"
|
||||||
|
|
||||||
|
# ── 人的介入(正交維度,可疊在任何 s/* 上,故不 exclusive)──
|
||||||
|
- name: "Human"
|
||||||
|
color: "b60205"
|
||||||
|
exclusive: false
|
||||||
|
description: "👤 這件事需要 leo 親手批示/動手(花錢・不可逆・品味方向・物理動作)。與 s/* 正交"
|
||||||
|
- name: "human/exec"
|
||||||
|
color: "e99695"
|
||||||
|
exclusive: false
|
||||||
|
description: "👤 這張票的『執行者』是人(GUI-only/實體權限/法定簽署),不是審核。交付物是環境狀態改變,不是 PR"
|
||||||
|
|
||||||
|
# ── 優先序(exclusive)───────────────────────────────
|
||||||
|
- name: "p/high"
|
||||||
|
color: "b60205"
|
||||||
|
exclusive: true
|
||||||
|
description: "高——擋住交付或有時間壓力"
|
||||||
|
- name: "p/low"
|
||||||
|
color: "bfd4f2"
|
||||||
|
exclusive: true
|
||||||
|
description: "低——想做,但晚一點沒關係"
|
||||||
|
|
||||||
|
# ── 種類(exclusive)────────────────────────────────
|
||||||
|
- name: "type/bug"
|
||||||
|
color: "d73a4a"
|
||||||
|
exclusive: true
|
||||||
|
description: "壞掉的東西"
|
||||||
|
- name: "type/feature"
|
||||||
|
color: "a2eeef"
|
||||||
|
exclusive: true
|
||||||
|
description: "新能力"
|
||||||
|
- name: "type/governance"
|
||||||
|
color: "5319e7"
|
||||||
|
exclusive: true
|
||||||
|
description: "規範、流程、閘本身"
|
||||||
|
- name: "type/chore"
|
||||||
|
color: "fef2c0"
|
||||||
|
exclusive: true
|
||||||
|
description: "雜務、整理、不改行為"
|
||||||
|
|
||||||
|
# ── 結構(正交)──────────────────────────────────
|
||||||
|
- name: "hub"
|
||||||
|
color: "0052cc"
|
||||||
|
exclusive: false
|
||||||
|
description: "Tracking issue——聚合一批 leaf 的 scope 容器,本身不掛 milestone、不對應 PR"
|
||||||
|
|
||||||
|
# 舊標籤:不刪(刪掉會從既有票上被摘除,歷史就斷了),改標記封存
|
||||||
|
archive:
|
||||||
|
- name: "duplicate"
|
||||||
|
reason: "由 close/duplicate 取代"
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# check-version-consistency.sh — ISEP 版本一致性檢查(inkstone/ISEP#6)
|
|
||||||
#
|
|
||||||
# 立這支的來由(2026-08-20):README.md 曾寫死「狀態:0.1.0」,
|
|
||||||
# 但這個 repo `release_counter=0`、一個 tag 都沒打。leo 當場指出這是違規,
|
|
||||||
# 且命中規範自己的 E12(宣稱交付但沒有 tag);leo 補充:
|
|
||||||
# 「release 不是寫在 readme,要放在 release 裡」。
|
|
||||||
#
|
|
||||||
# 判準只有一句:**「ISEP 現在是哪一版」只有一個地方答得出來= Gitea Releases(git tag)。**
|
|
||||||
# 其他地方要嘛指過去、要嘛跟它機械同步,不准各自宣告一個號碼。
|
|
||||||
#
|
|
||||||
# 1. `.claude-plugin/plugin.json` 的 `version` 欄位,必須跟「最新的 tag」完全一致。
|
|
||||||
# 還沒打過任何 tag 時(現在就是這個狀態),version 欄位必須是哨兵值 `0.0.0`
|
|
||||||
# ──意思是「這份 manifest 誠實承認:目前沒有一個經過驗證、掛在 Gitea Releases
|
|
||||||
# 上的版本」。不准提前寫一個沒人驗過的號碼(那正是這張票抓到的違規本身)。
|
|
||||||
# 真正打 tag 的那天,`.claude-plugin/plugin.json` 的 version 要跟那個 tag
|
|
||||||
# 同一個 commit 就改掉,兩者一起進 release。
|
|
||||||
# 2. `README.md` 不准再自己宣告版本號(例如「- 0.1.0 —」這種樣式的行)。
|
|
||||||
# 讀者要查現在是哪一版,去 Releases 頁面,不是讀 README。
|
|
||||||
#
|
|
||||||
# 用法:scripts/check-version-consistency.sh
|
|
||||||
# 離開碼:0=一致(可以放心說「這裡查得到版本」);1=不一致(stderr 講清楚錯在哪、
|
|
||||||
# 該改哪個檔案)。可以隨時手動跑,也是 hooks/release-tag-guard.sh 在打 tag
|
|
||||||
# 那一刻用來擋下不一致 tag 的同一套判準(複製了一份精簡邏輯,避免 hook
|
|
||||||
# 每次 Bash 呼叫都要 fork 這支腳本)。
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
PROJ="$(cd "$(dirname "$0")/.." && pwd)"
|
|
||||||
PLUGIN_JSON="$PROJ/.claude-plugin/plugin.json"
|
|
||||||
README="$PROJ/README.md"
|
|
||||||
|
|
||||||
FAIL=0
|
|
||||||
|
|
||||||
# --- 1. plugin.json 讀得到、version 欄位存在 ---
|
|
||||||
if [ ! -f "$PLUGIN_JSON" ]; then
|
|
||||||
echo "❌ 找不到 $PLUGIN_JSON" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
PJVER=$(python3 -c "import json;print(json.load(open('$PLUGIN_JSON')).get('version',''))" 2>/dev/null || printf '')
|
|
||||||
if [ -z "$PJVER" ]; then
|
|
||||||
echo "❌ .claude-plugin/plugin.json 沒有 version 欄位(或不是合法 JSON)" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- 2. 跟最新 tag 比對 ---
|
|
||||||
LATEST_TAG=$(cd "$PROJ" && git tag --list 'v*' --sort=-v:refname 2>/dev/null | head -1 || printf '')
|
|
||||||
|
|
||||||
if [ -z "$LATEST_TAG" ]; then
|
|
||||||
# 沒有任何 tag:唯一合法的 plugin.json version 是哨兵值 0.0.0
|
|
||||||
if [ "$PJVER" != "0.0.0" ]; then
|
|
||||||
echo "❌ 版本不一致:" >&2
|
|
||||||
echo " repo 裡沒有任何 tag(release_counter=0,還沒有一個正式 release)" >&2
|
|
||||||
echo " 但 .claude-plugin/plugin.json 的 version 卻宣稱「$PJVER」" >&2
|
|
||||||
echo " → 這就是 inkstone/ISEP#6 抓到的違規本身:宣稱一個版本,卻沒有 tag 撐它。" >&2
|
|
||||||
echo " → 修法:version 改回 0.0.0(=尚未發過正式版),等真正打 tag 那天再同步改成那個號碼。" >&2
|
|
||||||
FAIL=1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
TAGVER=${LATEST_TAG#v}
|
|
||||||
if [ "$PJVER" != "$TAGVER" ]; then
|
|
||||||
echo "❌ 版本不一致:" >&2
|
|
||||||
echo " Gitea 上最新的 tag 是 $LATEST_TAG(版本 $TAGVER)" >&2
|
|
||||||
echo " 但 .claude-plugin/plugin.json 的 version 是「$PJVER」" >&2
|
|
||||||
echo " → 兩者必須完全一致,不然「ISEP 現在是哪一版」又變成各說各話。" >&2
|
|
||||||
FAIL=1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- 3. README 不准自己宣告版本號 ---
|
|
||||||
HIT=$(grep -nE '^\s*-\s*v?[0-9]+\.[0-9]+\.[0-9]+\s*(—|-)' "$README" 2>/dev/null || printf '')
|
|
||||||
if [ -f "$README" ] && [ -n "$HIT" ]; then
|
|
||||||
echo "❌ README.md 還在自己宣告版本號(不准,release 只放在 Gitea Releases):" >&2
|
|
||||||
echo "$HIT" >&2
|
|
||||||
FAIL=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$FAIL" -eq 0 ]; then
|
|
||||||
if [ -n "$LATEST_TAG" ]; then
|
|
||||||
echo "✅ 版本一致:plugin.json=$PJVER,最新 tag=$LATEST_TAG,README 沒有自行宣告版本。"
|
|
||||||
else
|
|
||||||
echo "✅ 版本一致:plugin.json=$PJVER(哨兵值,尚無 tag 是合法狀態),README 沒有自行宣告版本。"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit "$FAIL"
|
|
||||||
Executable
+175
@@ -0,0 +1,175 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# gitea-labels-sync.sh — 把 labels.yaml(唯一真相源)同步到 inkstone org 底下的受治理 repo。
|
||||||
|
#
|
||||||
|
# 用法:
|
||||||
|
# scripts/gitea-labels-sync.sh # 同步 org 內全部 repo(自動列舉)
|
||||||
|
# scripts/gitea-labels-sync.sh InkStoneCo Arcrun # 只同步指定的 repo
|
||||||
|
# DRY_RUN=1 scripts/gitea-labels-sync.sh # 只印計畫,不寫入
|
||||||
|
#
|
||||||
|
# 規則(見票 inkstone/ISEP#4):
|
||||||
|
# - 名稱在 labels.yaml 裡但 repo 沒有 → 建立
|
||||||
|
# - 名稱兩邊都有但 color/description/exclusive 不同 → 更新(PATCH)
|
||||||
|
# - repo 有、labels.yaml(含 archive 段)都沒有的名稱 → 只印告警,絕不刪除
|
||||||
|
# - labels.yaml 的 archive 段:已知的舊名,不視為「非規範」,但也不會被建立/更新
|
||||||
|
# - 冪等:兩次連跑,第二次一定是 0 created / 0 updated
|
||||||
|
#
|
||||||
|
# 依賴:curl, jq, python3(+pyyaml)
|
||||||
|
# Token 來源:與 InkStoneCo 頂層同一顆 gitea remote 密碼(不落地、不進 commit)
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
|
LABELS_YAML="${LABELS_YAML:-$REPO_ROOT/labels.yaml}"
|
||||||
|
API_BASE="https://git.uncle6.me/api/v1"
|
||||||
|
ORG="inkstone"
|
||||||
|
DRY_RUN="${DRY_RUN:-0}"
|
||||||
|
|
||||||
|
if [[ ! -f "$LABELS_YAML" ]]; then
|
||||||
|
echo "找不到真相源:$LABELS_YAML" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- token:跟 InkStoneCo 頂層 gitea remote 拿同一把(不落地檔案、不印出來) ---
|
||||||
|
TOKEN="${GITEA_TOKEN:-}"
|
||||||
|
if [[ -z "$TOKEN" ]]; then
|
||||||
|
INKSTONE_TOP="${INKSTONE_TOP:-$HOME/Documents/tech_projects/InkStoneCo}"
|
||||||
|
if [[ -d "$INKSTONE_TOP/.git" ]]; then
|
||||||
|
TOKEN="$(git -C "$INKSTONE_TOP" remote get-url gitea 2>/dev/null | sed -E 's|.*//[^:]+:([^@]+)@.*|\1|')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ -z "$TOKEN" ]]; then
|
||||||
|
echo "拿不到 Gitea token——設 GITEA_TOKEN 環境變數,或確認 $INKSTONE_TOP 的 gitea remote 存在" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- labels.yaml → JSON(一次轉換,供後面反覆查詢用) ---
|
||||||
|
LABELS_JSON="$(python3 -c "
|
||||||
|
import yaml, json, sys
|
||||||
|
with open('$LABELS_YAML') as f:
|
||||||
|
d = yaml.safe_load(f)
|
||||||
|
print(json.dumps(d))
|
||||||
|
")"
|
||||||
|
|
||||||
|
REPO_NAMES=("$@")
|
||||||
|
if [[ ${#REPO_NAMES[@]} -eq 0 ]]; then
|
||||||
|
# macOS 內建 bash 是 3.2,沒有 mapfile/readarray,改用相容寫法
|
||||||
|
REPO_NAMES=()
|
||||||
|
while IFS= read -r line; do
|
||||||
|
[[ -n "$line" ]] && REPO_NAMES+=("$line")
|
||||||
|
done < <(curl -sf -H "Authorization: token $TOKEN" \
|
||||||
|
"$API_BASE/orgs/$ORG/repos?limit=50" | python3 -c "
|
||||||
|
import json, sys
|
||||||
|
for r in json.load(sys.stdin):
|
||||||
|
print(r['name'])
|
||||||
|
")
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "受治理 repo(${#REPO_NAMES[@]} 個):${REPO_NAMES[*]}"
|
||||||
|
echo "DRY_RUN=$DRY_RUN"
|
||||||
|
echo "================================================================"
|
||||||
|
|
||||||
|
TOTAL_CREATED=0
|
||||||
|
TOTAL_UPDATED=0
|
||||||
|
declare -a SUMMARY_LINES=()
|
||||||
|
|
||||||
|
for REPO in "${REPO_NAMES[@]}"; do
|
||||||
|
echo ""
|
||||||
|
echo "── $ORG/$REPO ──────────────────────────────────────────"
|
||||||
|
|
||||||
|
EXISTING_JSON="$(curl -sf -H "Authorization: token $TOKEN" \
|
||||||
|
"$API_BASE/repos/$ORG/$REPO/labels?limit=50")"
|
||||||
|
|
||||||
|
# 用 python3 一次算出這個 repo 的 create/update/warn 計畫(純比對,不動網路)
|
||||||
|
# 用暫存檔傳資料給 python(避免把含 emoji/引號的 JSON 內嵌進 -c 字串源碼裡出錯)
|
||||||
|
LABELS_TMP="$(mktemp)"
|
||||||
|
EXISTING_TMP="$(mktemp)"
|
||||||
|
printf '%s' "$LABELS_JSON" > "$LABELS_TMP"
|
||||||
|
printf '%s' "$EXISTING_JSON" > "$EXISTING_TMP"
|
||||||
|
PLAN_JSON="$(python3 -c "
|
||||||
|
import json, sys
|
||||||
|
|
||||||
|
with open('$LABELS_TMP', encoding='utf-8') as f:
|
||||||
|
labels_def = json.load(f)
|
||||||
|
with open('$EXISTING_TMP', encoding='utf-8') as f:
|
||||||
|
existing = json.load(f)
|
||||||
|
|
||||||
|
canonical = labels_def.get('labels', [])
|
||||||
|
archived_names = {a['name'] for a in labels_def.get('archive', [])}
|
||||||
|
canonical_by_name = {l['name']: l for l in canonical}
|
||||||
|
existing_by_name = {l['name']: l for l in existing}
|
||||||
|
|
||||||
|
to_create = []
|
||||||
|
to_update = []
|
||||||
|
for name, want in canonical_by_name.items():
|
||||||
|
have = existing_by_name.get(name)
|
||||||
|
if have is None:
|
||||||
|
to_create.append(want)
|
||||||
|
continue
|
||||||
|
diff = {}
|
||||||
|
if have.get('color', '').lstrip('#').lower() != want['color'].lstrip('#').lower():
|
||||||
|
diff['color'] = want['color']
|
||||||
|
if (have.get('description') or '') != (want.get('description') or ''):
|
||||||
|
diff['description'] = want.get('description', '')
|
||||||
|
if bool(have.get('exclusive', False)) != bool(want.get('exclusive', False)):
|
||||||
|
diff['exclusive'] = bool(want.get('exclusive', False))
|
||||||
|
if diff:
|
||||||
|
to_update.append({'id': have['id'], 'name': name, 'diff': diff})
|
||||||
|
|
||||||
|
extras = []
|
||||||
|
for name in existing_by_name:
|
||||||
|
if name not in canonical_by_name and name not in archived_names:
|
||||||
|
extras.append(name)
|
||||||
|
|
||||||
|
print(json.dumps({'create': to_create, 'update': to_update, 'extras': extras}))
|
||||||
|
")"
|
||||||
|
rm -f "$LABELS_TMP" "$EXISTING_TMP"
|
||||||
|
|
||||||
|
N_CREATE="$(echo "$PLAN_JSON" | jq '.create | length')"
|
||||||
|
N_UPDATE="$(echo "$PLAN_JSON" | jq '.update | length')"
|
||||||
|
N_EXTRA="$(echo "$PLAN_JSON" | jq '.extras | length')"
|
||||||
|
|
||||||
|
if [[ "$N_CREATE" -gt 0 ]]; then
|
||||||
|
echo "$PLAN_JSON" | jq -c '.create[]' | while read -r item; do
|
||||||
|
NAME="$(echo "$item" | jq -r '.name')"
|
||||||
|
echo " + 建立: $NAME"
|
||||||
|
if [[ "$DRY_RUN" != "1" ]]; then
|
||||||
|
BODY="$(echo "$item" | jq '{name, color, description: (.description // ""), exclusive: (.exclusive // false)}')"
|
||||||
|
curl -sf -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
|
-d "$BODY" "$API_BASE/repos/$ORG/$REPO/labels" > /dev/null
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$N_UPDATE" -gt 0 ]]; then
|
||||||
|
echo "$PLAN_JSON" | jq -c '.update[]' | while read -r item; do
|
||||||
|
NAME="$(echo "$item" | jq -r '.name')"
|
||||||
|
ID="$(echo "$item" | jq -r '.id')"
|
||||||
|
DIFF="$(echo "$item" | jq -c '.diff')"
|
||||||
|
echo " ~ 更新: $NAME ($DIFF)"
|
||||||
|
if [[ "$DRY_RUN" != "1" ]]; then
|
||||||
|
curl -sf -X PATCH -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
|
||||||
|
-d "$DIFF" "$API_BASE/repos/$ORG/$REPO/labels/$ID" > /dev/null
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$N_EXTRA" -gt 0 ]]; then
|
||||||
|
echo " ⚠ 非規範標籤(不動手,只告警):$(echo "$PLAN_JSON" | jq -r '.extras | join(", ")')"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " 小計:+$N_CREATE created, ~$N_UPDATE updated, ⚠$N_EXTRA extra"
|
||||||
|
SUMMARY_LINES+=("$REPO|$N_CREATE|$N_UPDATE|$N_EXTRA")
|
||||||
|
TOTAL_CREATED=$((TOTAL_CREATED + N_CREATE))
|
||||||
|
TOTAL_UPDATED=$((TOTAL_UPDATED + N_UPDATE))
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "================================================================"
|
||||||
|
echo "總計:${TOTAL_CREATED} created, ${TOTAL_UPDATED} updated(跨 ${#REPO_NAMES[@]} 個 repo)"
|
||||||
|
echo ""
|
||||||
|
printf "%-28s %8s %8s %8s\n" "repo" "created" "updated" "extras"
|
||||||
|
for line in "${SUMMARY_LINES[@]}"; do
|
||||||
|
IFS='|' read -r r c u e <<< "$line"
|
||||||
|
printf "%-28s %8s %8s %8s\n" "$r" "$c" "$u" "$e"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user