Skip to content

Add script to enable branch protection on main#2

Merged
bastiensoret merged 1 commit intodevfrom
claude/protect-main-branch-lFDWW
Mar 19, 2026
Merged

Add script to enable branch protection on main#2
bastiensoret merged 1 commit intodevfrom
claude/protect-main-branch-lFDWW

Conversation

@bastiensoret
Copy link
Copy Markdown
Owner

Summary

Add a new bash script that automates the process of enabling branch protection rules on the main branch of the bastiensoret/Cesar repository via the GitHub API.

Changes

  • New script: scripts/protect-main.sh
    • Requires a GitHub personal access token with "repo" scope
    • Configures branch protection with the following rules:
      • Requires 1 approving pull request review before merging
      • Dismisses stale reviews when new commits are pushed
      • Enforces protection rules for repository administrators
      • Prevents force pushes to the branch
      • Prevents deletion of the branch
    • Includes proper error handling and user-friendly output messages
    • Uses GitHub REST API v3 to apply protection settings

Implementation Details

  • Script validates that GITHUB_TOKEN environment variable is set before execution
  • Uses curl with strict error handling (-sf flags) to communicate with GitHub API
  • Hardcoded repository details (owner: bastiensoret, repo: Cesar, branch: main)
  • Provides clear documentation and instructions for token creation

https://claude.ai/code/session_01RGbmL5YQv2AWnjFyqjpMtn

Provides a one-command setup for protecting the main branch:
requires PR reviews, blocks force pushes, and enforces rules for admins.

https://claude.ai/code/session_01RGbmL5YQv2AWnjFyqjpMtn
@bastiensoret bastiensoret merged commit 95cf12a into dev Mar 19, 2026
@bastiensoret bastiensoret deleted the claude/protect-main-branch-lFDWW branch March 19, 2026 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants