Overview
ThemergePullRequest
method allows you to programmatically merge an existing pull request on GitHub. It supports different merge methods (merge, squash, rebase) and allows customization of the commit message.
Method Signature
Parameters
MergePullRequestOptions
Parameter | Type | Required | Description |
---|---|---|---|
repository | string | Yes | The GitHub repository in format “owner/repo” |
pullNumber | number | Yes | The number of the pull request to merge |
commitTitle | string | No | Custom title for the merge commit |
commitMessage | string | No | Custom message for the merge commit |
mergeMethod | 'merge' | 'squash' | 'rebase' | No | The merge method to use (defaults to ‘merge’) |
Merge Methods
merge
: Creates a merge commit with all commits from the feature branchsquash
: Squashes all commits into a single commit before mergingrebase
: Rebases the commits onto the base branch
Return Value
MergePullRequestResult
Property | Type | Description |
---|---|---|
sha | string | The SHA of the merge commit |
merged | boolean | Whether the pull request was successfully merged |
message | string | A message describing the merge result |
Prerequisites
Before using this method, ensure:-
GitHub Configuration: You only need to configure GitHub credentials using secrets:
Note: Unlike other methods,
mergePullRequest
does NOT require agent or sandbox configuration. -
Pull Request State: The pull request must be:
- Open and not already merged
- Free of merge conflicts
- Passing all required status checks
- Approved if required by branch protection rules
Usage Examples
Basic Merge
Squash and Merge
Complete Workflow Example
Error Handling
The method will throw an error in the following cases:Configuration Errors
- Missing GitHub token or repository configuration
- Invalid repository URL format
Pull Request Errors
- 404: Pull request not found
- 405: Pull request is not mergeable (conflicts or failed checks)
- 422: Invalid merge parameters or validation failed
Example Error Handling
Notes
- No agent or sandbox required: This method only needs GitHub configuration
- The method requires appropriate GitHub permissions (write access to the repository)
- Branch protection rules will be enforced
- The merge will respect all repository settings and requirements
- After a successful merge, the source branch may be automatically deleted depending on repository settings
- This is a direct GitHub API call - no code execution or AI processing is involved
Related Methods
createPullRequest
- Create a new pull requestpushToBranch
- Push changes to a branchgenerateCode
- Generate code using AI agents