Merge a pull request¶
PUT /api/v5/repos/{owner}/{repo}/pulls/{number}/merge
This endpoint merges the pull request with the specified number in the specified repository. It supports merging through merge, squash, or rebase, allows you to customize the merge title and description, and supports options such as force merge and squash branch merge. On success it returns the merge commit SHA and merge result information.
Access token support¶
- AtomGit user access tokens (AtomGit user access tokens)
Whether anonymous access is allowed¶
This endpoint does not allow anonymous access.
Request parameters¶
| Parameter | Location | Type | Required | Description |
|---|---|---|---|---|
owner |
path | string | Yes | The namespace address the repository belongs to (the address path of an enterprise, organization, or personal namespace) |
repo |
path | string | Yes | Repository path (path) |
number |
path | integer | Yes | Which PR, that is, the ordinal number of the PR in this repository |
access_token |
query | string | Yes | User authorization code |
Request Body:
The request body is a JSON object (Content-Type: application/json); form submission can also be used.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"merge_method": {
"description": "Method for merging the PR: merge (merges all commits), squash (squash branch merge), and rebase (rebase and merge). Defaults to merge.",
"type": "string",
"enum": ["merge", "squash", "rebase"],
"default": "merge"
},
"title": {
"description": "Merge title",
"type": "string"
},
"description": {
"description": "Merge description",
"type": "string"
},
"force_merge": {
"description": "Whether to force merge",
"type": "boolean"
},
"squash": {
"description": "Whether to perform a squash branch merge; defaults to `false`",
"type": "boolean",
"default": false
},
"squash_commit_message": {
"description": "Description for the squash branch merge",
"type": "string"
}
},
"required": []
}
Response parameters¶
| Field | Type | Always returned | Nullable | Description |
|---|---|---|---|---|
sha |
string | No | Yes | The commit SHA produced after a successful merge |
merged |
boolean | Yes | No | Whether the merge succeeded |
message |
string | Yes | Yes | Merge result information |
Error response¶
Besides the success response, callers also need to understand the failure return shape. This endpoint returns an error response on authentication failure, parameter errors, and when the PR cannot be merged; for
405, the response body structure is the same as the success response (sha/merged/message). The actual error field names are as returned by the backend.
400 Parameter error
{
"error": "invalid_request",
"message": "Parameter validation failed or request body parsing failed"
}
401 Unauthenticated
405 PR cannot be merged
For
405,messagemay also be "cannot be merged automatically" (there is a merge conflict) or the specific error information returned by the backend.
HTTP response status codes¶
| Status code | Description |
|---|---|
200 |
Success (OK) |
400 |
Parameter error (Bad Request) |
401 |
Authentication required (Requires authentication) |
403 |
Forbidden (Forbidden) |
405 |
Method not allowed or PR cannot be merged (Method Not Allowed) |
Request example¶
Parameter descriptions¶
<owner>is replaced with the namespace address the repository belongs to (the address path of an enterprise, organization, or personal namespace);<repo>with the repository path (path);<number>with the PR number;<token>with your AtomGit user access token.
cURL¶
curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/merge?access_token=<token>' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{
"merge_method": "merge",
"title": "Merge title",
"description": "Merge description",
"force_merge": false,
"squash": false,
"squash_commit_message": "Description for the squash branch merge"
}'
JavaScript¶
// Native fetch (Node.js 18+ / browser)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/merge?access_token=<token>",
{
method: "PUT",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
merge_method: "merge",
title: "Merge title",
description: "Merge description",
force_merge: false,
squash: false,
squash_commit_message: "Description for the squash branch merge",
}),
},
);
if (!response.ok) {
throw new Error(`Request failed: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.put(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pulls/<number>/merge",
params={"access_token": "<token>"},
headers={
"Content-Type": "application/json",
"Accept": "application/json",
},
json={
"merge_method": "merge",
"title": "Merge title",
"description": "Merge description",
"force_merge": False,
"squash": False,
"squash_commit_message": "Description for the squash branch merge",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
Response example¶
Status code: 200
{
"sha": "c20ac9624d2811a9313af29769dcf581b60c3044",
"merged": true,
"message": "Pull request merged successfully"
}
Error codes¶
| Error code | Description |
|---|---|
401 |
Unauthenticated or invalid credentials (missing/invalid access credentials) |
403 |
Insufficient permission; access forbidden |
400 |
Parameter error or the request cannot be parsed |
404 |
Request path does not exist |
405 |
Request method not supported or the PR cannot be merged |
429 |
Too many requests; rate limit triggered |
500 |
Internal system error |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc