Skip to content

Update Pull Request settings

PUT /api/v5/repos/{owner}/{repo}/pull_request_settings

This endpoint updates the Pull Request settings of the specified repository. You can configure multiple rules such as the merge method, the number of reviewers and approvers, the conditions for merging based on pipelines and discussions, Squash merge, CLA validation, lightweight merge requests, and closing related issues after merge. Fields that are not passed keep their original settings. On success, the updated merge request settings are returned.

Access token support

  • AtomGit user access tokens (AtomGit user access tokens)

Anonymous access allowed?

This endpoint does not allow anonymous access.

Request parameters

Parameter Location Type Required Description
owner path string Yes Address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual)
repo path string Yes Repository path (path)
access_token query string Yes User authorization code

Request Body:

The request body is a JSON object, and all fields are optional (fields that are not passed keep their original settings).

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "approval_required_reviewers_enable": {
      "description": "Whether to enable the approval-required reviewers feature",
      "type": "boolean"
    },
    "approval_required_reviewers": {
      "description": "Number of approvers required (minimum reviewer count); value range 0~5; pass 0 to disable the reviewer feature",
      "type": "integer",
      "minimum": 0,
      "maximum": 5
    },
    "only_allow_merge_if_all_discussions_are_resolved": {
      "description": "Merge only when all review issues are resolved",
      "type": "boolean"
    },
    "only_allow_merge_if_pipeline_succeeds": {
      "description": "Whether merging is allowed only after the pipeline succeeds",
      "type": "boolean"
    },
    "disable_merge_by_self": {
      "description": "Prohibit merging your own merge requests",
      "type": "boolean"
    },
    "can_force_merge": {
      "description": "Allow administrators to force merge",
      "type": "boolean"
    },
    "add_notes_after_merged": {
      "description": "Allow continued code review and comments after the merge request is merged",
      "type": "boolean"
    },
    "mark_auto_merged_mr_as_closed": {
      "description": "Whether to mark the state of automatically merged MRs as closed",
      "type": "boolean"
    },
    "can_reopen": {
      "description": "Whether a closed merge request can be reopened",
      "type": "boolean"
    },
    "delete_source_branch_when_merged": {
      "description": "Whether to delete the source branch when merging; the source branch is deleted by default",
      "type": "boolean"
    },
    "disable_squash_merge": {
      "description": "Prohibit Squash merge",
      "type": "boolean"
    },
    "auto_squash_merge": {
      "description": "Enable Squash merge by default for new merge requests",
      "type": "boolean"
    },
    "merge_method": {
      "description": "Merge mode (choose one of three): merge via merge commit (merge); merge via merge commit recording a semi-linear history (rebase_merge); fast-forward merge (ff)",
      "type": "string",
      "enum": ["merge", "rebase_merge", "ff"]
    },
    "squash_merge_with_no_merge_commit": {
      "description": "Squash merge does not create a Merge node",
      "type": "boolean"
    },
    "merged_commit_author": {
      "description": "Generate the Merge Commit using the MR (merger/creator): pass merged_by to use the PR merger; pass created_by to use the PR creator",
      "type": "string",
      "enum": ["merged_by", "created_by"]
    },
    "approval_required_approvers": {
      "description": "Number of approvers required",
      "type": "integer",
      "maximum": 1000
    },
    "approval_approver_ids": {
      "description": "Project reviewers; user_ids separated by commas",
      "type": "string"
    },
    "approval_tester_ids": {
      "description": "Project testers; user_ids separated by commas",
      "type": "string"
    },
    "approval_required_testers": {
      "description": "Minimum number of testers that must pass",
      "type": "integer"
    },
    "is_check_cla": {
      "description": "Whether to validate CLA",
      "type": "boolean"
    },
    "is_allow_lite_merge_request": {
      "description": "Whether lightweight Pull Requests are enabled",
      "type": "boolean"
    },
    "lite_merge_request_prefix_title": {
      "description": "Title prefix for lightweight PRs",
      "type": "string"
    },
    "close_issue_when_mr_merged": {
      "description": "When creating a Pull Request, select \"Close related issues after merge\" by default; this parameter has no effect when the \"Close related issues after merge\" option is disabled",
      "type": "boolean"
    },
    "forbidden_pr_related_issue_closed": {
      "description": "Prohibit a PR from being associated with a closed issue (when this is true, close_issue_when_mr_merged is forced to false)",
      "type": "boolean"
    }
  }
}

Response parameters

Field Type Always returned Nullable Description
merge_request_setting object Yes No Merge request settings
only_allow_merge_if_all_discussions_are_resolved boolean Yes Yes Allow merging only when all discussions are resolved
only_allow_merge_if_pipeline_succeeds boolean Yes Yes Allow merging only when the pipeline succeeds
merge_method string Yes Yes Merge method; enum: merge / rebase_merge / ff
only_allow_merge_if_vote_bigger_than integer Yes Yes Allow merging only when the vote count is greater than the specified value

merge_request_setting object

Field Type Always returned Nullable Description
merge_request_setting.id integer Yes Yes Setting ID
merge_request_setting.project_id integer Yes Yes Project ID
merge_request_setting.disable_merge_by_self boolean Yes Yes Prohibit merging your own merge requests
merge_request_setting.created_at string Yes Yes Creation time
merge_request_setting.updated_at string Yes Yes Update time
merge_request_setting.can_force_merge boolean Yes Yes Allow administrators to force merge
merge_request_setting.disable_squash_merge boolean Yes Yes Prohibit Squash merge
merge_request_setting.approval_required_reviewers integer Yes Yes Number of approvers required (minimum reviewer count)
merge_request_setting.approval_required_approvers integer Yes Yes Number of approvers required
merge_request_setting.add_notes_after_merged boolean Yes Yes Allow continued code review and comments after the merge request is merged
merge_request_setting.merged_commit_author string Yes Yes User who generates the Merge Commit; enum: merged_by / created_by
merge_request_setting.mark_auto_merged_mr_as_closed boolean Yes Yes Whether to mark the state of automatically merged MRs as closed
merge_request_setting.delete_source_branch_when_merged boolean Yes Yes Whether to delete the source branch when merging
merge_request_setting.auto_squash_merge boolean Yes Yes Enable Squash merge by default for new merge requests
merge_request_setting.squash_merge_with_no_merge_commit boolean Yes Yes Squash merge does not create a Merge node
merge_request_setting.close_issue_when_mr_merged boolean Yes Yes Whether to close related issues when merging
merge_request_setting.can_reopen boolean Yes Yes Whether a closed merge request can be reopened
merge_request_setting.is_check_cla boolean Yes Yes Whether to validate CLA
merge_request_setting.approval_approvers object[] Yes Yes Project approver list (array of user objects)
merge_request_setting.approval_testers object[] Yes Yes Project tester list (array of user objects)
merge_request_setting.approval_required_testers integer Yes Yes Minimum number of testers that must pass
merge_request_setting.is_allow_lite_merge_request boolean Yes Yes Whether lightweight Pull Requests are enabled
merge_request_setting.forbidden_pr_related_issue_closed boolean No Yes Whether the "Close related issues after merge" option is disabled

Error response

400 Parameter error

When both forbidden_pr_related_issue_closed and close_issue_when_mr_merged are true, a parameter error is returned:

{
  "error": "invalid_request",
  "message": "The option Close associated issues after merging has been disabled."
}

401 Unauthenticated

{
  "error": "unauthorized",
  "message": "Missing or invalid access token"
}

HTTP response status codes

Status code Description
200 Success (OK)
401 Authentication required (Requires authentication)
403 Forbidden
404 Request path does not exist (Not found)
429 Too many requests (Rate limited)
500 Internal system error (Internal server error)

Request example

Parameter description

Replace <owner> with the address path of the namespace the repository belongs to (the address path of an enterprise, organization, or individual); replace <repo> with the repository path (path); replace <token> with your AtomGit user access token.

cURL

curl -X PUT 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pull_request_settings?access_token=<token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "merge_method": "merge",
    "disable_merge_by_self": false,
    "can_force_merge": true
  }'

JavaScript

// Native fetch (Node.js 18+ / browser)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/pull_request_settings?access_token=<token>",
  {
    method: "PUT",
    headers: {
      "Accept": "application/json",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      merge_method: "merge",
      disable_merge_by_self: false,
      can_force_merge: true,
    }),
  }
);

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>/pull_request_settings",
    params={"access_token": "<token>"},
    json={
        "merge_method": "merge",
        "disable_merge_by_self": False,
        "can_force_merge": True,
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

Response example

Status code: 200

{
  "merge_request_setting": {
    "id": 1431,
    "project_id": 2745002,
    "disable_merge_by_self": false,
    "created_at": "2024-03-28T10:04:13.523+08:00",
    "updated_at": "2024-11-13T21:30:45.261+08:00",
    "can_force_merge": false,
    "disable_squash_merge": true,
    "approval_required_reviewers": 0,
    "approval_required_approvers": 0,
    "add_notes_after_merged": false,
    "merged_commit_author": "merged_by",
    "mark_auto_merged_mr_as_closed": false,
    "delete_source_branch_when_merged": false,
    "auto_squash_merge": false,
    "squash_merge_with_no_merge_commit": false,
    "close_issue_when_mr_merged": false,
    "can_reopen": true,
    "is_check_cla": false,
    "approval_approvers": [],
    "approval_testers": [],
    "approval_required_testers": 0,
    "is_allow_lite_merge_request": false
  },
  "only_allow_merge_if_all_discussions_are_resolved": false,
  "only_allow_merge_if_pipeline_succeeds": false,
  "merge_method": "merge"
}

Error codes

Error code Description
400 Parameter error or the request cannot be parsed
401 Unauthenticated or invalid credentials (missing/invalid access credentials)
403 Forbidden
404 Request path does not exist
405 Request method not supported
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