Smart Merge Queue
Automate merging with stack-aware CI optimization and conflict resolution
The Smart Merge Queue automatically merges approved pull requests in the correct order, running CI efficiently and handling rebases automatically.
Table of Contents
Section titled “Table of Contents”Overview
Section titled “Overview”The Problem
Section titled “The Problem”Manual merging is:
- ⏰ Slow - Wait for CI, merge, repeat
- 🐛 Error-prone - Merge conflicts, wrong order
- 💸 Expensive - Run CI for every PR individually
- 😓 Tedious - Babysit the merge process
The Solution
Section titled “The Solution”Smart Merge Queue:
✅ Automatic Merging - Set it and forget it ✅ Stack-Aware - Merges in dependency order ✅ CI Validation - Ensures checks pass for latest commits ✅ Priority Handling - Higher priority merges sooner
Real-World Impact
Section titled “Real-World Impact”Without Queue:
PR #123 → Wait for CI (5 min) → Merge →PR #124 → Rebase → Wait for CI (5 min) → Merge →PR #125 → Rebase → Wait for CI (5 min) → MergeTotal: ~20 minutes, 3 CI runsWith Queue:
Add #123, #124, #125 to queue →Queue detects dependencies →Merges #123 →Validates CI for #124 →Merges #124 →Validates CI for #125 →Merges #125Total: fewer manual steps and a consistent, ordered merge flow 🎉How It Works
Section titled “How It Works”Queue Flow
Section titled “Queue Flow”1. PR gets approved ↓2. Add to merge queue ↓3. Queue checks: - All approvals? ✓ - CI passing? ✓ - Conflicts? Block and report - Dependencies? Order correctly ↓4. Run final CI check ↓5. Merge to main ↓6. Update dependent PRsStack-Aware Merging
Section titled “Stack-Aware Merging”Queue understands stacks:
Queue contains:- PR #123 (base)- PR #124 (depends on #123)- PR #125 (depends on #124)
Queue automatically:1. Merges #123 first2. Rebases #124 onto new main3. Runs CI for #1244. Merges #1245. Rebases #1256. Merges #125
All automatic!CI Validation
Section titled “CI Validation”Before merging, the queue verifies:
- All required approvals are present
- Latest CI results for the PR’s head SHA are successful
- Stack dependencies are merged in order
Getting Started
Section titled “Getting Started”Prerequisites
Section titled “Prerequisites”- Repository with CI configured
- Merge permissions
- Branch protection (optional but recommended)
Adding PR to Queue
Section titled “Adding PR to Queue”Via Web UI:
- Open approved PR
- Click “Add to Merge Queue” button
- PR status changes to “In Queue”
- Watch it merge automatically!
Via CLI:
# Add single PRoch queue add 125
# Add with numeric priority (higher = sooner)och queue add 126 --priority 5Via API:
curl -X POST https://git.yourcompany.com/api/repos/OWNER/REPO/merge-queue \ -H "Authorization: Bearer $TOKEN" \ -d '{"pullRequestNumber": 125, "priority": 0, "mergeMethod": "merge"}'Viewing Queue Status
Section titled “Viewing Queue Status”Web UI:
Navigate to /queue or click “Merge Queue” in repository navigation
CLI:
# View entire queueoch queue listAPI:
curl https://git.yourcompany.com/api/repos/OWNER/REPO/merge-queue \ -H "Authorization: Bearer $TOKEN"Queue Management
Section titled “Queue Management”Priority
Section titled “Priority”Priority is numeric. Higher values are processed sooner. Default is 0.
och queue add 126 --priority 5Removing from Queue
Section titled “Removing from Queue”# Remove specific PRoch queue remove 125Pausing the Queue
Section titled “Pausing the Queue”Pausing and resuming the queue is managed in the web UI.
Configuration
Section titled “Configuration”Repository Settings
Section titled “Repository Settings”Queue behavior is enforced by:
- Branch protection rules (required approvals, required checks)
- CI status for the PR’s latest commit
- Per‑entry merge method chosen when adding to the queue
Configuration is managed in the repository settings UI.
Branch Protection Rules
Section titled “Branch Protection Rules”Recommended settings:
branches: main: required_status_checks: - test - lint required_approvals: 1 allow_force_push: false allow_queue_bypass: false # Even admins use queue!Webhook Notifications
Section titled “Webhook Notifications”Get notified when PRs merge:
# Configure webhookcurl -X POST https://git.yourcompany.com/api/repos/OWNER/REPO/webhooks \ -d '{ "url": "https://yourapp.com/webhook", "events": ["merge_queue.merged", "merge_queue.failed"], "secret": "your-secret" }'Payload:
{ "event": "merge_queue.merged", "pr": { "number": 125, "title": "Add login UI", "author": "swadhin" }, "queue": { "position": 1, "wait_time_seconds": 180 }, "timestamp": "2024-01-01T12:00:00Z"}Best Practices
Section titled “Best Practices”💡 When to Use the Queue
Section titled “💡 When to Use the Queue”✅ Always use for:
- Feature branches → main
- Release branches
- Any PR affecting production
❌ Don’t use for:
- Draft PRs
- WIP branches
- Experimental features
💡 Optimizing Queue Performance
Section titled “💡 Optimizing Queue Performance”1. Fast CI: Keep queue checks short and focused. Run slower or optional suites after merge.
2. Parallel CI: Split workflows into parallel jobs to reduce total wall‑clock time.
3. Small PRs: Smaller, focused PRs reduce queue time and review delays.
💡 Handling Conflicts
Section titled “💡 Handling Conflicts”Manual resolution:
# If a conflict blocks the queue, you'll get a notification# Fix locally:git checkout feature-branchgit fetch origingit rebase origin/main# Resolve conflictsgit push --force-with-lease
# PR automatically re-enters queue💡 Queue Monitoring
Section titled “💡 Queue Monitoring”Set up alerts:
# Slack notification if queue stalledalerts: - type: queue_stalled threshold: 30m channel: "#eng-deployments"
- type: merge_failed channel: "#eng-alerts"Dashboard example:
# View queue healthoch queue stats
# Output:# Queue Health: ✅ Good# - Average wait time: 4.2 min# - CI success rate: 94%# - Merge rate: 15 PRs/hour# - Current size: 8 PRsTroubleshooting
Section titled “Troubleshooting””PR stuck in queue”
Section titled “”PR stuck in queue””Causes:
- CI failing
- Waiting for approval
- Merge conflict
- Dependency not merged yet
Solutions:
# Check statusoch queue status 125
# View logsoch queue logs 125
# Remove and re-addoch queue remove 125# Fix issueoch queue add 125“Auto-rebase failed”
Section titled ““Auto-rebase failed””Cause: Complex merge conflicts.
Solution:
# Remove from queueoch queue remove 125
# Manually rebasegit checkout feature-branchgit rebase origin/main# Resolve conflictsgit push -f
# Re-add to queueoch queue add 125“Queue not processing”
Section titled ““Queue not processing””Causes:
- CI checks failing or still running
- Required approvals missing
- The PR is not in the queue
Solutions:
# Check the queueoch queue list
# Inspect the PRoch pr view 125“Wrong merge order”
Section titled ““Wrong merge order””Cause: Stack dependency is missing or incorrect.
Solution:
- Ensure PRs are created as a stack (base PR first, then dependents).
- Re‑submit the stack with the CLI if needed.
Roadmap ideas
Section titled “Roadmap ideas”Future improvements may include merge trains and scheduled merges. If these are important for your team, open an issue with your use case.
Queue Hooks
Section titled “Queue Hooks”Custom automation:
module.exports = { beforeMerge(pr) { // Send Slack notification // Update JIRA ticket // Trigger deployment },
afterMerge(pr) { // Create release notes // Update documentation },};