Skip to content

fix: pre-production/production ブランチ保護のデフォルト設定を差別化 - #583

Merged
keito4 merged 1 commit into
mainfrom
fix/branch-protection-defaults
Mar 15, 2026
Merged

fix: pre-production/production ブランチ保護のデフォルト設定を差別化#583
keito4 merged 1 commit into
mainfrom
fix/branch-protection-defaults

Conversation

@keito4

@keito4 keito4 commented Mar 15, 2026

Copy link
Copy Markdown
Owner

Summary

  • setup-team-protection.sh にブランチ種別ごとのデフォルト保護設定を追加
  • cloud_provisioning PR fix: add bash-compatible short aliases to output.sh #359 と同パターンで pre-production / production を保護
  • --uniform オプションで従来の全ブランチ同一設定に切替可能

変更後のデフォルト保護

ブランチ enforce_admins required_reviews code_owner_reviews
main (default_branch) true 0 false
pre-production false 1 true
production false 1 true

Test plan

  • --dry-run で main / pre-production / production それぞれに適切なデフォルトが適用されることを確認
  • --uniform で全ブランチ同一設定になることを確認
  • --protection-level strict がブランチ種別デフォルトより優先されることを確認
  • CI Quality Gate パス

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --uniform flag to apply identical branch protection settings across all branches
    • Introduced type-specific default protection with tailored review requirements per branch
  • Documentation

    • Expanded setup guides with command examples for multi-branch protection scenarios
    • Clarified default behaviors for admin enforcement, review requirements, and code owner reviews

cloud_provisioning PR #359 と同様に、ブランチ種別ごとのデフォルト保護を適用:
- main: enforce_admins=true, reviews=0, code_owner_reviews=false
- pre-production/production: enforce_admins=false, reviews=1, code_owner_reviews=true
--uniform オプションで従来の全ブランチ同一設定に切替可能

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the bug 不具合・バグ label Mar 15, 2026
@coderabbitai

coderabbitai Bot commented Mar 15, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This pull request adds a --uniform flag to enable identical branch protection settings across all branches, introduces per-branch default protection configurations (main vs. pre-production/production), and reorganizes documentation to reflect these branch-type-specific defaults. The script now applies different protection levels based on branch classification unless uniform mode is enabled.

Changes

Cohort / File(s) Summary
Documentation & Examples
.claude/commands/setup-team-protection.md
Reorganized branch protection descriptions with a new per-branch defaults table, added --uniform flag reference, replaced API examples with simplified script commands, restructured sections for per-branch configuration, and added examples for pre-production/production protection.
Branch Protection Script
script/setup-team-protection.sh
Added --uniform flag parsing, implemented per-branch default logic (main: enforce_admins=true/reviewers=0; pre-production/production: enforce_admins=false/reviewers=1), updated strict mode validation with variable-based comparisons, introduced require_code_owner_reviews variable tracking, and augmented DRY_RUN/payload outputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bug


🐰 A uniform flag hops through the branches with care,
Per-branch defaults now dance in the air,
Pre-prod and production get their special treat,
While main stays steady with admin-enforced beat! 🌿✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: differentiating default branch protection settings between pre-production/production branches, which aligns with the core objective of the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/branch-protection-defaults
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@keito4

keito4 commented Mar 15, 2026

Copy link
Copy Markdown
Owner Author

🔍 AI Code Review (Local Hook)

Models: Codex (default) / Gemini (default)

🤖 Codex Review

指摘事項(重要度順)

  1. --reviewers--enforce-admins の指定が実質無効化されるケースがある
    setup_branch_protection の分岐でブランチ種別デフォルトが CLI 指定値を上書きしています。--uniform 未指定時、pre-production/production では reviewers=1enforce_admins=falsemain/master では reviewers=0enforce_admins=true に固定され、ユーザーが --reviewers--enforce-admins を指定しても反映されません。ヘルプや想定される CLI 挙動と矛盾し、意図した保護設定にならない可能性があります。
    影響範囲: script/setup-team-protection.sh:223-248

判定: patch is incorrect
理由: --reviewers / --enforce-admins のユーザー指定がブランチ種別デフォルトで上書きされる挙動は、オプションの意味を損ない、意図しない設定を適用し得るため。
信頼度: 0.54


⚠️ 修正が必要です

上記のレビューで問題が指摘されています。修正してからマージしてください。


🤖 Generated by post_pr_ai_review.py hook

@keito4

keito4 commented Mar 15, 2026

Copy link
Copy Markdown
Owner Author

🔍 AI Code Review (Local Hook)

Models: Codex (default) / Gemini (default)

🤖 Codex Review

指摘事項(重大度順)

  1. CLI指定値がブランチ種別デフォルトで上書きされ、ユーザー指定が無視されます(DX/正確性)。
    --reviewers--enforce-admins を指定しても、main|masterpre-production|production では常にデフォルト値に置き換わります。期待される「ユーザー指定の上書き」挙動と逆転しており、意図した保護レベルになりません。--uniform が唯一の回避手段ですが、ユーザーは通常これを指定しないため、実運用で誤設定のリスクが高いです。
    影響箇所: script/setup-team-protection.sh:221-249
    例: reviewers=0 固定、enforce_admins=true/false 固定により --reviewers 2--enforce-admins が反映されない。

総合判定: patch is incorrect
理由: 明示指定のCLIオプションがブランチ種別デフォルトで上書きされ、ユーザーの意図と異なる保護設定になるため。
信頼度: 0.62


⚠️ 修正が必要です

上記のレビューで問題が指摘されています。修正してからマージしてください。


🤖 Generated by post_pr_ai_review.py hook

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: af5cacb22c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +236 to +237
enforce_admins=false
reviewers=1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Honor explicit protection flags over branch defaults

When --uniform is not set, the branch-type case block hard-codes enforce_admins/reviewers for pre-production and production, which silently overrides explicit CLI inputs like --enforce-admins and --reviewers. For example, running with --enforce-admins --branches production still produces enforce_admins=false, so admins remain exempt even though the caller asked to enforce rules for them. This is a regression from prior behavior and can apply weaker protection than requested.

Useful? React with 👍 / 👎.

@claude

claude Bot commented Mar 15, 2026

Copy link
Copy Markdown
Contributor

コードレビュー

全体的に変更の意図が明確で、既存パターン(cloud_provisioning PR #359)との一貫性も保たれています。CI も全グリーンです。以下にフィードバックをまとめます。


✅ 良い点

  • --uniform フラグで後方互換性を維持しつつ新しいデフォルト挙動を導入している点が適切
  • case 文によるブランチ種別判定がシンプルで読みやすい
  • info ログでどのデフォルトが適用されたかをドライラン時に確認できる
  • ドキュメント(.claude/commands/setup-team-protection.md)がコードの変更と同期して更新されている

🔍 指摘事項

1. require_code_owner_reviews の初期値が意図と逆(軽微なバグ)

# script/setup-team-protection.sh L221
local require_code_owner_reviews=true  # ← 初期値が true

main ブランチに対して code_owner_reviews=false を設定する case 分岐は存在しますが、--uniform モードでは初期値の true がそのまま使われます。既存の --uniform の挙動では以前 require_code_owner_reviews がハードコードされていたので動作は変わりませんが、変数の初期値として true を持つのは意図が不明瞭です。

提案: false を初期値にし、strict や branch-type ロジックで true に設定する方が意図が明確になります。

local require_code_owner_reviews=false

2. --uniform --enforce-admins 組み合わせ時の挙動が文書化されていない

--uniform 使用時は branch-type デフォルトがスキップされますが、ENFORCE_ADMINS のグローバル変数は引き続き使われます。これ自体は正しい挙動ですが、ドキュメントの --uniform の説明に「CLI オプション(--enforce-admins など)は引き続き有効」という一文を加えると親切です。

3. master ブランチのケースが case に追加されたが既存動作と差異がある

main|master)
  enforce_admins=true
  reviewers=0
  ...

以前は master ブランチに対して特別なデフォルトがなかったため、--reviewers の指定値(デフォルト 1)が使われていました。mastermain と同一扱いにする変更は理にかなっていますが、既存ユーザーが --branches master を使っている場合に reviewers=0 になる破壊的変更です。リリースノートに記載することを推奨します。


📋 サマリ

分類 評価
コード品質 ✅ シンプルで読みやすい
バグリスク ⚠️ require_code_owner_reviews の初期値(軽微)
後方互換性 ⚠️ master ブランチのデフォルト変更
テスト ✅ Integration Tests パス
ドキュメント ✅ 同期更新済み

LGTM です。指摘の #1(初期値修正)のみ対応いただけると完璧です。

🤖 Claude Code レビュー

@keito4
keito4 merged commit 708871d into main Mar 15, 2026
19 of 20 checks passed
@keito4
keito4 deleted the fix/branch-protection-defaults branch March 15, 2026 13:14
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.97.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 不具合・バグ released リリース済み

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant