A Guide to CodePeel's Pre-Merge Quality Gates
How pre-merge checks turn review findings into GitHub commit statuses: the four check types, error versus warning severity, branch protection integration, and calibration advice.
A review comment asks a developer to act. A merge gate requires them to. CodePeel's pre-merge quality gates bridge this gap by evaluating review findings against configurable standards, then posting the result directly to GitHub's Commit Status API under the codepeel/premerge context. When paired with branch protection, a failing check blocks the merge button automatically.
Key Takeaways
- Zero Re-Scan Overhead: Pre-merge gates evaluate findings already produced during the review pass, adding no extra latency or API cost.
- Dual Severity Model: Checks configure as either
error(blocks branch merge) orwarning(flags metrics in the dashboard without blocking).- Safe Rollout Strategy: Calibrate by starting all gates in
warningmode for two weeks, then promote zero-tolerance security rules toerror.- Independent Review Evaluation: Failed reviews due to external provider outages never post red statuses, ensuring CI pipelines never lock up.
Pre-merge quality gates are automated verification policies that translate granular code review findings into pass/fail status checks on pull requests. Instead of relying on manual reviewer diligence, gates convert policy rules into machine-enforced merge criteria.
This architecture guide explores how the evaluation engine works, what each check measures, how status severity maps to GitHub branch protection, and how to calibrate thresholds without disrupting development velocity.
A post-review evaluation pipeline
Pre-merge checks never re-scan your source code. They execute immediately after the review pass finishes and inspect the aggregate metrics that the analysis already produced: bug totals, security vulnerabilities, performance regressions, and critical-severity tags.
Pull Request Opened / Updated
│
▼
CodePeel Review Pass
(Diff Parser + AST + Security SAST)
│
▼
Aggregated Findings
(Bugs, Vulnerabilities, Severity)
│
▼
Pre-Merge Quality Evaluation
┌───────────────────────┐
│ Check 1: Security │ ──► Error (Block)
│ Check 2: Bug Density │ ──► Warning (Log)
│ Check 3: Max Issues │ ──► Pass
│ Check 4: Critical Flaw│ ──► Pass
└───────────────────────┘
│
▼
GitHub Commit Status API
(`codepeel/premerge` Context)
The sequence follows six deterministic steps:
- A pull request opens or receives fresh commits. The primary review executes (deterministic regex diff checks, security SAST, and model analysis as detailed in How CodePeel's OWASP Security Scanning Works).
- The review produces structured metrics. Counts are categorized by severity and vulnerability type.
- Configured checks execute in memory. Each check evaluates its specific metric against your team's threshold.
- Every check records an audit event. Events capture the repository name, commit SHA, timestamp, and human-readable explanation.
- Results attach to the review object. Details become visible in the CodePeel dashboard.
- A commit status publishes to GitHub. The result posts to the head commit via the GitHub Commit Status API.
Because the gates evaluate pre-existing review findings, checks consume no additional LLM tokens and execute in milliseconds. Most importantly, checks require a successful review pass. If a review encounters an upstream outage, no status posts. A broken review never blocks engineering work.
The four check types

| Check type | What it evaluates | Threshold required | Default severity | Target use case |
|---|---|---|---|---|
security_blocker | Any security findings | None (Zero-tolerance) | error | Payment, auth, and crypto repositories |
bug_density | Bug count | Yes (Default: 5) | warning | General code health and defect tracking |
max_issues | Bugs + Security + Performance | Yes (Default: 10) | error | Service stability and tech debt ceilings |
critical_findings | Critical-severity findings | None (Zero-tolerance) | error | High-reliability production systems |
1. Security blocker (security_blocker)
Fails whenever a review flags any security vulnerability. This is a zero-tolerance gate with no threshold counter. Use it on sensitive repositories handling authentication, payment processing, or confidential user data, where shipping known vulnerabilities carries high risk. The security detections powering this gate align with the OWASP Top 10 classifications detailed in our OWASP security scanning guide.
2. Bug density (bug_density)
Fails when the total number of flagged bugs exceeds your configured threshold. For example, a threshold of 5 permits five or fewer bugs; a sixth bug trips the check. Teams typically keep this rule at warning severity to monitor defect density trends without interrupting merges.
3. Max issues (max_issues)
Fails when the sum of bugs, security vulnerabilities, and performance flaws surpasses the threshold limit. Architectural notes and style suggestions are excluded from this calculation. This rule offers flexible enforcement: higher thresholds accommodate large legacy refactors, while low thresholds safeguard core production microservices.
A threshold-based check saved without an explicit number acts as a no-op that always passes. If you intend zero tolerance, set the threshold value explicitly to 0.
4. Critical findings (critical_findings)
Fails if any single finding carries a critical severity tag, regardless of its category. Critical findings are reserved for unambiguous hazards: data corruption risks, remote code execution vulnerabilities, unhandled process crashes, or severe concurrency race conditions.
Error versus warning severity
Every gate assigns a severity level that determines GitHub merge behavior:
errorseverity: A failed check marks the commit status red. When configured in GitHub Branch Protection Rules, the pull request cannot be merged.warningseverity: A failed check logs to the audit history and appears in dashboard summaries, but the GitHub commit status remains green. Merging proceeds without disruption.
The aggregate commit status follows strict logic: if all checks pass, or if failures are limited to warning-level rules, the status reports success. If even one error-level check fails, the aggregate status reports failure.
The commit status payload
CodePeel posts a single consolidated status per evaluated commit:
| Field | Configuration | Specification |
|---|---|---|
| Context | codepeel/premerge | Distinct status namespace recognized by GitHub |
| State | success or failure | Dictates branch protection pass/fail status |
| Description | Short status text | Summarizes why the check passed or failed (max 140 chars) |
| Target URL | Dashboard link | Direct link to the per-check drill-down analysis |
The status writes via GitHub's REST API using the GitHub App's statuses:write permission. GitHub presents the indicator inside the PR checks tray alongside automated unit tests and CI builds.
To enforce hard merge blocking, open repository settings: Branches → Branch protection rules → Require status checks to pass before merging, then search and select codepeel/premerge. From that moment, an error failure disables the merge button until a developer fixes the findings or updates the branch.
Real-world evaluation example
Consider a team that enables security_blocker (error), critical_findings (error), and bug_density set to a threshold of 5 (warning).
A pull request review finishes with the following metrics:
- 2 security vulnerabilities
- 3 bug findings
- 0 critical-severity flaws
The gates evaluate as follows:
security_blocker: 2 vulnerabilities found → Fail (Error severity)critical_findings: 0 critical flaws → Passbug_density: 3 bugs found (threshold: 5) → Pass
Because an error-level gate failed, the codepeel/premerge status reports failure, blocking the pull request. Once the developer patches the security issues and pushes a new commit, CodePeel re-evaluates the fresh diff. With security issues resolved to zero, the status shifts to success, unblocking the merge. If only bug_density had tripped, the status would have remained green.
Calibration and rollout guide
Uncalibrated quality gates frustrate engineering teams. If a gate blocks every pull request indiscriminately, developers will disable branch protection rules.
To calibrate thresholds scientifically, compare your defect rates against the testing corpus described in How to Benchmark an AI Code Reviewer.
Week 1 - 2: Observation Phase
└── Set all checks to 'warning' severity
└── Review dashboard metrics across 50+ pull requests
└── Establish your baseline defect frequency
Week 3: Zero-Tolerance Promotion
└── Promote 'security_blocker' to 'error'
└── Promote 'critical_findings' to 'error'
└── Keep quantitative density gates on 'warning'
Week 4+: Iterative Tightening
└── Calibrate 'bug_density' threshold to 80th percentile of typical PRs
└── Adjust 'max_issues' based on repository maturity
- Phase 1: Observation. Configure every gate to
warning. Let reviews run across real pull requests for two weeks without interfering with team cadence. - Phase 2: Promote zero-tolerance checks. Turn
security_blockerandcritical_findingstoerror. Because these rules only catch severe flaws, false-positive pushback remains minimal. - Phase 3: Calibrate quantitative limits. Set
bug_densityandmax_issuesthresholds based on actual team averages. Start generous and tighten gradually as code quality improves. - Phase 4: Re-evaluate during team scaling. Thresholds calibrated for a three-person startup will constrain a twenty-person organization. Check the audit history monthly to maintain balance.
Scope and technical boundaries
- Organization-level policies: Check configurations apply across repositories managed by the GitHub App installation.
- Pull request pipeline scope: Reviews initiated manually inside the VS Code extension or via the Claude Code MCP server execute locally and do not post commit statuses. Gates evaluate pull requests exclusively.
- Unified status surface: GitHub renders a single
codepeel/premergecheck item. Deep per-rule breakdowns live behind the Target URL link. - Fresh commit evaluation: Editing gate thresholds does not trigger retroactive status updates. Push a commit or close and reopen the PR to trigger a re-run.
For configuration syntax and team settings, reference the pre-merge checks documentation. To resolve errors automatically before gates fail, explore How Auto-Fix PR Generation Works End to End.
