Auto-Merge Feature
Implementation summary of the auto-merge feature for autonomous PR handling
Auto-Merge Feature - Implementation Summary
Overview
The auto-merge feature enables duyetbot-action to automatically merge PRs after successfully completing tasks and passing all verification checks. This completes the autonomous loop: Plan → Implement → Verify → PR → Auto-Merge → Done.
What It Does
The Autonomous Loop
Safety Features
- Verification Required: Only auto-merges when all local checks pass
- CI Integration: Waits for GitHub Actions checks to complete
- Required Checks: Configurable list of required CI check names
- Timeout Protection: Maximum wait time for CI checks
- Dry Run Support: Can be disabled for testing
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
AUTO_MERGE | Enable auto-merge | false |
REQUIRED_CHECKS | Comma-separated list of required CI checks | ci,test |
WAIT_FOR_CHECKS | Wait for CI checks before merging | true |
AUTO_MERGE_TIMEOUT | Max wait time for CI (milliseconds) | 600000 (10 min) |
AUTO_MERGE_APPROVE | Approve PR before merging | true |
AUTO_MERGE_DELETE_BRANCH | Delete branch after merge | true |
Config Object
Components
1. Auto-Merge Service (auto-merge.ts)
Standalone service for auto-merging PRs with CI check monitoring.
Key Methods:
autoMerge(prNumber, config)- Main entry pointwaitForChecks()- Polls for CI completionapprovePR()- Approves PR before mergingmergePR()- Merges and optionally deletes branch
2. GitHub Reporter Integration (github.ts)
Enhanced GitHubReporter with auto-merge capabilities.
New Methods:
autoMergePR(prNumber)- Auto-merge a PRwaitForChecks()- Wait for CI checksextractPRNumber()- Parse PR number from URL
Integration Point: Auto-merge triggered after successful PR creation when verificationPassed === true.
3. Config Extensions (config.ts)
Added autoMerge and selfImprovement configuration sections.
New Config Schema:
4. Report Context Extension (types.ts)
Added verificationPassed?: boolean to ReportContext for signaling successful verification.
File Structure
Usage Example
GitHub Actions Workflow
What Happens
- Agent receives task from GitHub Issue
- Implements solution with Claude Agent SDK
- Runs verification:
type-check,lint,test,build - Creates PR if all checks pass
- Polls GitHub for CI check completion
- Approves PR
- Merges PR
- Deletes feature branch
- Closes issue
API
AutoMergeService
Convenience Function
Error Handling
Auto-Merge Failures
Auto-merge will NOT proceed if:
- Merge Conflicts: PR has conflicts that need resolution
- CI Failures: Required checks fail
- Timeout: CI checks don't complete within timeout
- Permission Issues: Token lacks write permissions
Failure Behavior
On auto-merge failure:
- PR remains open for manual review
- Error logged but doesn't fail the task
- Issue can be manually closed later
Monitoring
Console Output
GitHub Actions Summary
The workflow automatically updates with auto-merge status in the step summary.
Security Considerations
- Token Permissions: Requires
reposcope with write access - Branch Protection: Should work with protected branches (token needs permissions)
- Required Checks: Always verify required checks match actual CI names
- Approval Limits: Respects any branch protection rules requiring approvals
Future Enhancements
- Support for multiple approval requirements
- Configurable merge strategies (squash, rebase)
- PR comment before merging for transparency
- Integration with status checks API for better reliability
- Rollback capability if merge causes issues