[追加] Git hooks: pre-commit ロック検証 + post-commit Issue 自動更新 (#66)
scripts/pre-commit-lock-check.sh: - コミット前にファイルロックを検証 - POLARIS_AGENT_ID 環境変数でエージェント識別 - ロック保持者以外の変更を exit 1 で拒否 scripts/post-commit-issue-update.sh: - コミットメッセージから #N を抽出 - gh issue comment で自動更新 - cargo test 結果も添付 - バックグラウンド実行(コミットをブロックしない) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ec1d25887e
commit
553eed3b5d
2 changed files with 100 additions and 0 deletions
36
scripts/post-commit-issue-update.sh
Executable file
36
scripts/post-commit-issue-update.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/bin/bash
|
||||
# Polaris: コミット後に関連 Issue を自動更新する post-commit hook
|
||||
#
|
||||
# コミットメッセージに (#52, #53) のような Issue 番号があれば、
|
||||
# 自動で gh issue comment を実行する。
|
||||
|
||||
REPO="Miyabi-G-K/miyabi-cli-standalone"
|
||||
|
||||
# 直前のコミット情報を取得
|
||||
COMMIT_HASH=$(git rev-parse --short HEAD)
|
||||
COMMIT_MSG=$(git log -1 --pretty=%B)
|
||||
AUTHOR=$(git log -1 --pretty=%an)
|
||||
|
||||
# コミットメッセージから Issue 番号を抽出 (#52, #53 等)
|
||||
ISSUE_NUMS=$(echo "$COMMIT_MSG" | grep -oE '#[0-9]+' | sed 's/#//')
|
||||
|
||||
if [ -z "$ISSUE_NUMS" ]; then
|
||||
exit 0 # Issue 番号がなければ何もしない
|
||||
fi
|
||||
|
||||
# 各 Issue にコメントを投稿
|
||||
for NUM in $ISSUE_NUMS; do
|
||||
gh issue comment "$NUM" \
|
||||
--repo "$REPO" \
|
||||
--body "✅ **コミット反映**: \`$COMMIT_HASH\` by $AUTHOR
|
||||
|
||||
\`\`\`
|
||||
$COMMIT_MSG
|
||||
\`\`\`
|
||||
|
||||
cargo test: $(cargo test 2>&1 | grep 'test result' | tail -1)" \
|
||||
2>/dev/null &
|
||||
done
|
||||
|
||||
# バックグラウンドで実行(コミットをブロックしない)
|
||||
wait
|
||||
64
scripts/pre-commit-lock-check.sh
Executable file
64
scripts/pre-commit-lock-check.sh
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
# Polaris: コミット前にファイルロックを検証する pre-commit hook
|
||||
#
|
||||
# ロックされているファイルを、ロック保持者以外が変更しようとしたら拒否する。
|
||||
|
||||
STORE="$(git rev-parse --show-toplevel)/project_memory/tasks.json"
|
||||
MIYABI_BIN="$(git rev-parse --show-toplevel)/target/release/miyabi"
|
||||
|
||||
# miyabi バイナリがなければスキップ(ビルド前)
|
||||
if [ ! -x "$MIYABI_BIN" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 変更されたファイル一覧
|
||||
CHANGED_FILES=$(git diff --cached --name-only)
|
||||
|
||||
if [ -z "$CHANGED_FILES" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ロック一覧を取得
|
||||
LOCKS=$("$MIYABI_BIN" gate --store-path "$STORE" --format json locks 2>/dev/null)
|
||||
|
||||
if [ -z "$LOCKS" ] || [ "$LOCKS" = "[]" ] || [ "$LOCKS" = "{}" ]; then
|
||||
exit 0 # ロックなし
|
||||
fi
|
||||
|
||||
# 現在のエージェント ID(環境変数から取得、なければチェックしない)
|
||||
AGENT_ID="${POLARIS_AGENT_ID:-}"
|
||||
|
||||
if [ -z "$AGENT_ID" ]; then
|
||||
exit 0 # エージェント ID 未設定ならチェックスキップ
|
||||
fi
|
||||
|
||||
# 各変更ファイルのロック状態を確認
|
||||
BLOCKED=0
|
||||
for FILE in $CHANGED_FILES; do
|
||||
LOCK_OWNER=$(echo "$LOCKS" | python3 -c "
|
||||
import sys, json
|
||||
try:
|
||||
data = json.load(sys.stdin)
|
||||
if isinstance(data, dict):
|
||||
entry = data.get('$FILE', {})
|
||||
if entry:
|
||||
print(entry.get('agent', '') + '@' + entry.get('node', ''))
|
||||
except: pass
|
||||
" 2>/dev/null)
|
||||
|
||||
if [ -n "$LOCK_OWNER" ] && [ "$LOCK_OWNER" != "$AGENT_ID" ]; then
|
||||
echo "❌ BLOCKED: $FILE is locked by $LOCK_OWNER"
|
||||
echo " You ($AGENT_ID) cannot modify this file."
|
||||
echo " Run: miyabi gate assign <task-id> --files \"$FILE\" to acquire lock"
|
||||
BLOCKED=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$BLOCKED" -eq 1 ]; then
|
||||
echo ""
|
||||
echo "🔒 Commit rejected by Polaris file lock enforcement."
|
||||
echo " Set POLARIS_AGENT_ID to identify yourself."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue