Loading...
Loading...
Fandhe-AI 組織標準の CI ガード一式(codex-review 導入 / AGENTS.md レビュー観点集 / 必須チェック集約ジョブ / branch protection ruleset・追加ガード)を対象リポジトリへ導入する。「リポジトリガード入れて」「CI ガード導入して」 「branch protection セットアップ」「codex-review 導入して」「AGENTS.md 整備して」などで使用。 複数リポジトリへの一括適用にも対応。.claude/ 体系の初期セットアップは init-claude、既存体系の充実は update-claude を参照。
npx skill4agent add fandhe-ai/agent-cli-skills setup-repo-guardsci-completesetup-repo-guards Fandhe-AI/my-repo public
setup-repo-guards Fandhe-AI/repo-a public Fandhe-AI/repo-b privateowner/repopublicprivateghcommand -v gh && gh auth statusjqcommand -v jq.github/workflows/codex-review.ymlcodex-review.yml@maingh api repos/Fandhe-AI/actions/commits/main# レビュー済み SHA 定数(内容精査済み。既存導入リポジトリ fandhe-frontend の
# .github/workflows/codex-review.yml が参照している SHA と同一)
sha="fed9c07d98367f77e5e2b63bca38843f46feee96"gh api "repos/Fandhe-AI/actions/compare/<旧SHA>...<新SHA>"docs/codex-review-runner-exception.mdpost_feedbackubuntu-latestCODEX_HOME_DIR.claude/rules/.github/codex/prompts/review.mdci-completeneeds:if: always()toJSON(needs)skippedif:permissions: {}lint-docs / lint-docs-completename: #gh api -X PATCH repos/...main-protection~DEFAULT_BRANCH.claude/rules/ruleset-policy.mdautoMerge: trueintegration_idissuer-unboundPUTrequired_status_checks.parametersrepo="Fandhe-AI/<REPO>"
# Step 1: wrapper の存在と SHA 固定(@main が残っていないこと)
grep -n "uses: Fandhe-AI/actions" .github/workflows/codex-review.yml
# Step 2: AGENTS.md の存在と P0/P1/P2 定義
grep -n "P0\|P1\|P2" AGENTS.md | head
# Step 3: 直近 PR の check runs で集約ジョブが報告されること
gh pr checks "$(gh pr list --repo "${repo}" --state merged --limit 1 --json number --jq '.[0].number')" --repo "${repo}"
# Step 4: ruleset とマージ設定
gh api "repos/${repo}/rulesets" --jq '.[] | {id, name, enforcement}'
gh api "repos/${repo}" --jq '{allow_squash_merge, allow_merge_commit, allow_rebase_merge, delete_branch_on_merge, allow_auto_merge}'
# Step 4-a: 一括更新後の 3 軸スイープ(strict / bypass_actors / integration_id 残存)
# PUT した ruleset 単体ではなく branch target の全 ruleset を掃く(org 継承は source_type でルーティング)。
# コマンド全文・判定表は .claude/rules/ruleset-policy.md の「一括更新後の検証」節を参照
org="${repo%%/*}"
gh api "repos/${repo}/rulesets" \
--jq '.[] | select(.target == "branch") | [(.id|tostring), .name, (.source_type // "unknown")] | @tsv' |
while IFS=$'\t' read -r id name src; do
case "${src}" in
Repository) path="repos/${repo}/rulesets/${id}" ;;
Organization) path="orgs/${org}/rulesets/${id}" ;;
*) echo "UNKNOWN source_type: ${name} (${src}) — 手動確認"; continue ;;
esac
gh api "${path}" --jq '{
name: .name, enforcement: .enforcement, bypass: (.bypass_actors | length),
strict: ([.rules[]? | select(.type=="required_status_checks") | .parameters.strict_required_status_checks_policy] | first),
total: ([.rules[]? | select(.type=="required_status_checks") | .parameters.required_status_checks[]?] | length),
unbound: [.rules[]? | select(.type=="required_status_checks") | .parameters.required_status_checks[]? | select(.integration_id == null) | .context]
}'
done
# Step 4-b: classic branch protection を別枠で掃く(defaultBranchRef 解決・@uri エンコード・HTTP status 分岐)
db=$(gh repo view "${repo}" --json defaultBranchRef --jq '.defaultBranchRef.name')
db_enc=$(printf '%s' "${db}" | jq -sRr '@uri')
code=$(gh api -i "repos/${repo}/branches/${db_enc}/protection" 2>/dev/null | awk 'NR==1{print $2}')
case "${code}" in
200) gh api "repos/${repo}/branches/${db_enc}/protection" --jq \
'{strict: (.required_status_checks.strict // "none"), unbound: [.required_status_checks.checks[]? | select(.app_id == null) | .context]}' ;;
404) echo "classic BP なし(${db})" ;;
*) echo "判定不能 (HTTP ${code:-?}) — Administration: read 権限を確認。green と扱わない" ;;
esac| 問題 | 回避策 |
|---|---|
| 集約ジョブの skipped 全許容が fail-open として codex に P1 指摘される | Step 3: skipped 許容を条件付きジョブの明示リストに限定する |
| チェック名変更 PR が CI 全 pass でも BLOCKED(ruleset が旧名のまま「Expected」待ち) | Step 4: マージ前に ruleset を新チェック名へ PUT で置換する |
未クォート | Step 3: name に |
| paths フィルタ付き workflow のチェックを必須にするとマージが永久ブロックされる | Step 4: 常に報告されるチェックのみ必須化する |
| 参考ファイルの取り違え(別リポジトリ用 AGENTS.md の混入)を codex が検出 | Step 2: 対象リポジトリ固有の具体項目に落とし込む |
| AGENTS.md の P1 定義と CI ゲート実挙動(P1 でも fail)の矛盾を codex が指摘 | Step 2: P1 定義をゲート実挙動と矛盾させない |
| GITHUB_TOKEN read 化で暗黙 write 依存の workflow が壊れる | Step 4: 全 workflow の permissions 明示を確認してから適用する |
ruleset を PUT したら | Step 4-a: PUT 後に 3 軸スイープ( |
| 旧 ruleset / classic BP の掃き漏らしで未束縛・strict=true が残る | Step 4-a/4-b: 全 branch ruleset を列挙して掃き、classic BP は |
| AGENTS.md に自動マージの G0 契約を書く際 strict を要件として列挙し、実装より強い契約が codex P0 の根拠になる | Step 2: G0 契約を書くなら strict は「意図的な非要件」と明記する( |
--no-verify"${var}"