Help Center/ CodeArts Repo/ API Reference/ APIs/ V4/ MergeRequest/ Merging a Merge Request
Updated on 2026-01-27 GMT+08:00

Merging a Merge Request

Function

This API is used to merge a merge request.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

Authorization Information

Each account root user has all the permissions required to call all APIs, but IAM users must be assigned the following required identity policy-based permissions. For details about the required permissions, see Permissions Policies and Supported Actions.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

codeartsrepo:repository:mergeMergeRequest

Write

-

-

-

-

URI

PUT https://{hostURL}/v4/repositories/{repository_id}/merge-requests/{merge_request_iid}/merge

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

repository_id

Yes

Integer

Definition

You can query the project list to obtain the repository ID by calling the API used to query user's all repositories.

Constraints

N/A

Default Value

N/A

Value range:

1~2147483647

merge_request_iid

Yes

Integer

Definition

MR internal ID (IID).

Value range:

1~2147483647

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token. Obtain one by calling the IAM API Obtaining a User Token. The value of X-Subject-Token in the response header is a token.

Constraints

N/A

Range

1–100,000 characters.

Default Value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

squash_commit_message

No

String

Squash merge information

squash

No

Boolean

Squash merge

force_merge

No

Boolean

Force push

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

id

Integer

MR ID

iid

Integer

MR IID

repository_id

Integer

Target repository ID

title

String

MR title

description

String

MR description

state

String

MR status

created_at

String

Creation time

updated_at

String

Update time.

source_branch

String

Source branch

target_branch

String

Target branch

is_source_branch_protected

Boolean

Whether the source branch is a protected branch

devcloud_source_branch

String

Source branch

author

UserBasicExternalDto object

Author

source_repository_id

Integer

Source repository ID

target_repository_id

Integer

Target repository ID

source_project_id

String

Source project ID

target_project_id

String

Target project ID

labels

Array of objects

Label

work_in_progress

Boolean

Work in progress (WIP)

milestone

MilestoneBasicDto object

Milestone

merge_when_build_succeeds

Boolean

Automatically merged when the pipeline is successful

merge_status

String

Mergeable status

sha

String

Latest commit of the current MR

merge_commit_sha

String

Merge commit node

subscribed

Boolean

Subscription

merged_by

UserBasicExternalDto object

Merger

merged_at

String

Merge time

closed_by

UserBasicExternalDto object

Closer

closed_at

String

Close time

user_notes_count

Integer

Number of review comments

force_remove_source_branch

Boolean

Delete source branch after merge

web_url

String

Homepage URL

merge_request_diff

MergeRequestDiffExternalDto object

MR diff

merge_request_reviewers_count

Integer

Number of scorers

merge_request_review_count

Integer

Scoring

merge_request_reviewer_list

Array of MergeRequestReviewerExternalDto objects

Scorer list

merge_request_assignee_list

Array of UserBasicExternalDto objects

Merger list

notes

Integer

Review comment

codecheck_state

Integer

Code check status

codecheck_defect_count

Integer

Code check issues

merge_request_related_work_items

Array of MergeRequestRelatedWorkItemDto objects

Number of associated tickets of an MR

diverged_commits_count

Integer

Number of commits that a source branch is behind

moderation_result

Boolean

Approving result

moderation_time

Long

Timestamp of approving submission

Value range:

1~9223372036854775807

moderation_status

Integer

Approving status code

Value range:

1~2147483647

is_use_temp_branch

Boolean

Use temporary branch or not

approval_merge_request_approvers

Array of ApprovalUserDto objects

Approver

review_mode

String

MR mode

Enumeration values:

  • vote

  • approval

squash

Boolean

Squash merge

squash_commit_message

String

Squash commit information

rebase_in_progress

Boolean

Whether rebase is in progress

source_repository

ProjectSimpleDto object

Source repository

target_repository

ProjectSimpleDto object

Target repository

is_source_branch_exist

Boolean

Whether the source branch exists

merge_request_type

String

MR type

Table 5 MilestoneBasicDto

Parameter

Type

Description

id

Integer

Milestone ID

Value range:

1~2147483647

iid

Integer

Milestone IID

Value range:

1~2147483647

repository_id

Integer

Repository ID.

Value range:

1~2147483647

title

String

Milestone title

description

String

Milestone description

state

String

Status

created_at

String

Creation time

updated_at

String

Update time.

due_date

String

Expiration time

start_date

String

Start time

repository_path

String

Repository path

web_url

String

Homepage URL

Table 6 UserBasicExternalDto

Parameter

Type

Description

id

Integer

User ID

Value range:

1~2147483647

name

String

Name

username

String

Username

state

String

Status

avatar_url

String

Profile picture URL

web_url

String

Homepage URL

nick_name

String

User alias

tenant_name

String

Tenant name

Table 7 MergeRequestDiffExternalDto

Parameter

Type

Description

id

Integer

Diff ID of an MR

Value range:

1~2147483647

state

String

Status

merge_request_id

Integer

MR ID

Value range:

1~2147483647

created_at

String

Creation time

updated_at

String

Update time.

base_commit_sha

String

Base commit node

real_size

String

Number of diff files

head_commit_sha

String

Head commit node

start_commit_sha

String

Start commit node

commits_count

Integer

Number of commits

Value range:

1~2147483647

external_diff

String

External diff file

external_diff_store

Integer

External difference storage

Value range:

1~2147483647

stored_externally

Boolean

External storage or not

added_lines

Integer

Number of new lines

Value range:

0~2147483647

removed_lines

Integer

Number of deleted lines

Value range:

0~2147483647

Table 8 MergeRequestReviewerExternalDto

Parameter

Type

Description

id

Integer

Scorer ID

Value range:

1~2147483647

username

String

Scorer name

name

String

Scorer name

nick_name

String

Scorer alias

state

Boolean

Scorer status

score

Integer

Scoring

Value range:

-2~2

tenant_name

String

Tenant name

Table 9 MergeRequestRelatedWorkItemDto

Parameter

Type

Description

id

Integer

Association ID

Value range:

1~2147483647

user_id

String

User ID

repo_id

Integer

Repository ID

Value range:

1~2147483647

merge_request_id

Integer

MR ID

Value range:

1~2147483647

target_branch

String

Target branch

source_branch

String

Source branch

merge_request_title

String

MR title

merge_request_url

String

MR URL

merge_request_state

String

MR status

related_id

String

Associated ticket ID

related_title

String

Associated ticket title

related_url

String

Associated ticket URL

result

Integer

Association result

message

String

Association result information

create_at

String

Creation time

update_at

String

Update time.

subject

String

Topic

tracker

Object

Ticket follower

status

Object

Status

Table 10 ApprovalUserDto

Parameter

Type

Description

id

Integer

User ID

Value range:

1~2147483647

username

String

Username

name

String

Username

nick_name

String

User alias

name_cn

String

Name (CN)

email

String

Email

state

String

Status

updated_at

String

Update time

avatar_url

String

Profile picture URL

tenant_name

String

Tenant name

approver_comment

String

Approving comments

Table 11 ProjectSimpleDto

Parameter

Type

Description

id

Integer

Repository ID.

description

String

Repository description

name

String

Repository name

name_with_namespace

String

Organization name/Organization name.../Repository name

path

String

Repository path

path_with_namespace

String

Complete repository path

created_at

String

Creation time

updated_at

String

Update time.

archived

Boolean

Archived or not

is_kia

Boolean

Confidential or not

ssh_url_to_repo

String

Repository SSH address

http_url_to_repo

String

Repository HTTP address

web_url

String

Repository page link

readme_url

String

Link to the readme file of the repository

project_id

String

Project ID

project_name

String

Project name

develop_mode

String

Repository development modes: normal and CR

moderation_result

Boolean

Approving status

Status code: 401

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Definition

Error code.

error_msg

String

Definition

Error message.

Example Requests

/v4/repositories/123/merge-requests/{merge_request_iid}/merge

{
  "squash_commit_message" : "squash_commit_message",
  "squash" : true,
  "force_merge" : false
}

Example Responses

Status code: 200

OK

{
  "id" : 1242586,
  "iid" : 1,
  "title" : "Update README.md",
  "description" : "merge \\asfd\\ into \\master\\\\n Update README.md",
  "state" : "opened",
  "created_at" : "2024-08-14T14:17:39.000+08:00",
  "updated_at" : "2025-01-06T15:38:31.000+08:00",
  "source_branch" : "asfd",
  "target_branch" : "master",
  "is_source_branch_protected" : false,
  "devcloud_source_branch" : "asfd",
  "author" : {
    "id" : 1130646,
    "name" : "example_name",
    "username" : "7806db92698840d794a70e53e1295cb7",
    "state" : "active",
    "avatar_url" : null,
    "web_url" : "https://example.com/7806db92698840d794a70e53e1295cb7",
    "nick_name" : "example_name",
    "tenant_name" : "example_name"
  },
  "source_repository_id" : 2663641,
  "target_repository_id" : 2663641,
  "source_project_id" : "07c8683c4bb0445393c5eab0ea354003",
  "target_project_id" : "07c8683c4bb0445393c5eab0ea354003",
  "labels" : [ ],
  "work_in_progress" : false,
  "merge_when_build_succeeds" : false,
  "merge_status" : "can_be_merged",
  "sha" : "2032553aab2bbe1855687885da9165412b3fa3a4",
  "subscribed" : true,
  "user_notes_count" : 0,
  "force_remove_source_branch" : false,
  "web_url" : "https://example.com/********/2663641/1/mergedetail?source\\u003dasfd\\u0026target\\u003dmaster",
  "merge_request_diff" : {
    "id" : 1286204,
    "state" : "collected",
    "merge_request_id" : 1242586,
    "created_at" : "2024-08-14T14:17:39.000+08:00",
    "updated_at" : "2024-08-14T14:17:39.000+08:00",
    "base_commit_sha" : "cdb34fb2431d57aaf6701b4026425acde1d8a84c",
    "real_size" : 1,
    "head_commit_sha" : "2032553aab2bbe1855687885da9165412b3fa3a4",
    "start_commit_sha" : "cdb34fb2431d57aaf6701b4026425acde1d8a84c",
    "commits_count" : 1,
    "external_diff" : "diff-1286204",
    "external_diff_store" : 1,
    "stored_externally" : true,
    "added_lines" : 1,
    "removed_lines" : 1
  },
  "merge_request_reviewers_count" : 0,
  "merge_request_review_count" : 0,
  "merge_request_reviewer_list" : [ ],
  "merge_request_assignee_list" : [ ],
  "notes" : 0,
  "codecheck_state" : 7,
  "codecheck_defect_count" : 0,
  "merge_request_related_work_items" : [ ],
  "diverged_commits_count" : 0,
  "moderation_result" : true,
  "moderation_time" : 0,
  "moderation_status" : 0,
  "is_use_temp_branch" : false,
  "approval_merge_request_approvers" : [ ],
  "review_mode" : "approval",
  "squash" : false,
  "source_repository" : {
    "id" : 2663641,
    "description" : null,
    "name" : "mr_test",
    "name_with_namespace" : "07c8683c4bb0445393c5eab0ea354003 / mr_test",
    "path" : "mr_test",
    "path_with_namespace" : "07c8683c4bb0445393c5eab0ea354003/mr_test",
    "created_at" : "2024-08-05T11:32:27.000+08:00",
    "updated_at" : "2024-08-05T11:32:27.000+08:00",
    "archived" : false,
    "is_kia" : false,
    "ssh_url_to_repo" : "git@example.com:07c8683c4bb0445393c5eab0ea354003/mr_test.git",
    "http_url_to_repo" : "https://example.com/07c8683c4bb0445393c5eab0ea354003/mr_test.git",
    "web_url" : "https://example.com/07c8683c4bb0445393c5eab0ea354003/mr_test",
    "project_id" : "07c8683c4bb0445393c5eab0ea354003",
    "project_name" : "sll_test",
    "develop_mode" : "normal",
    "moderation_result" : true
  },
  "target_repository" : {
    "id" : 2663641,
    "description" : null,
    "name" : "mr_test",
    "name_with_namespace" : "07c8683c4bb0445393c5eab0ea354003 / mr_test",
    "path" : "mr_test",
    "path_with_namespace" : "07c8683c4bb0445393c5eab0ea354003/mr_test",
    "created_at" : "2024-08-05T11:32:27.000+08:00",
    "updated_at" : "2024-08-05T11:32:27.000+08:00",
    "archived" : false,
    "is_kia" : false,
    "ssh_url_to_repo" : "git@example.com:07c8683c4bb0445393c5eab0ea354003/mr_test.git",
    "http_url_to_repo" : "https://example.com/07c8683c4bb0445393c5eab0ea354003/mr_test.git",
    "web_url" : "https://example.com/07c8683c4bb0445393c5eab0ea354003/mr_test",
    "project_id" : "07c8683c4bb0445393c5eab0ea354003",
    "project_name" : "sll_test",
    "develop_mode" : "normal",
    "moderation_result" : true
  },
  "is_source_branch_exist" : true,
  "merge_request_type" : "MergeRequest"
}

Status code: 401

Unauthorized

{
  "error_code" : "DEV.00000003",
  "error_msg" : "Authentication information expired."
}

Status Codes

Status Code

Description

200

OK

401

Unauthorized

Error Codes

See Error Codes.