Hmm, the user wants a repository ruleset with protections, checks, and exceptions. This is a common DevOps/GitOps need, so I should provide a structured yet flexible framework.
First, I need to define core principles: security, stability, compliance, and automation. Then break it into logical sections: protection rules (what to guard), check rules (automated validations), and exceptions (how to handle edge cases).
For protections, I'll cover branch policies, PR requirements, and access controls. Checks should include CI/CD, security scans, and linting. Exceptions need clear audit trails and time limits. A matrix summary would help visualize the ruleset.
I should emphasize this is a template—the user must adapt it to their stack (GitHub/GitLab/Bitbucket) and compliance needs (SOC2, HIPAA etc.). The tone should be authoritative but practical, with concrete examples like "require 2 approvals for main."
Excellent request. A well-structured repository ruleset is the cornerstone of a secure, stable, and efficient development workflow. Below is a comprehensive, vendor-agnostic framework that you can adapt to GitHub (Branch Protection Rules + Code Owners), GitLab (Push Rules, Merge Request Approvals), or Bitbucket (Branch Permissions, Merge Checks).
Repository Ruleset Framework: Protections, Checks, & Exceptions
Core Principles: Security, Stability, Compliance, Automation, and Developer Experience.
1. PROTECTION RULES (What must be guarded)
These are non-negotiable guardrails on critical branches.
| Rule | Description | Enforcement | Critical For |
|---|
main / master Branch | - Direct pushes FORBIDDEN. All changes must come via Pull/Merge Requests. - Require至少 N (e.g., 2) approvals. At least one from a code owner/maintainer. - Require status checks to pass before merging (see Section 2). | Enforced by VCS platform. | Production stability, audit trail, peer review. |
develop / staging Branch | - Direct pushes FORBIDDEN (same as main). - Require至少 1 approval. - Require CI pipeline to pass. | Enforced, but can be slightly less strict than main. | Pre-production quality gate. |
| Long-lived Feature Branches | - Naming convention: feat/, fix/, docs/, etc. - Automated cleanup: Delete branch after successful merge. | Policy & automation. | Repository hygiene, prevents stale branches. |
| Tags | - Protect semantic version tags (v*.*.*). Only release engineers/maintainers can create/modify. - Sign tags (GPG) for release integrity. | Tag protection + signing enforcement. | Release integrity, supply chain security. |
| | | |