Help Center/ CodeArts Repo/ API Reference/ APIs/ V4/ MergeRequest/ Obtaining the MR Associated with the Commit
Updated on 2026-01-27 GMT+08:00

Obtaining the MR Associated with the Commit

Function

This API is used to obtain the MR associated with the commit.

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:getMergeRequest

Read

-

-

-

-

URI

GET https://{hostURL}/v4/repositories/{repository_id}/commits/{sha}/merge-requests

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

sha

Yes

String

Definition

Commit ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

offset

No

Integer

Definition

Offset, which starts from 0.

Value range:

0~2147483647

Default value:

0

limit

No

Integer

Definition

Number of returned records.

Value range:

1~100

Default value:

20

Request Parameters

Table 3 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

Response Parameters

Status code: 200

Table 4 Response header parameters

Parameter

Type

Description

X-Total

String

Definition

Total number of MRs associated with a commit.

Table 5 Response body parameters

Parameter

Type

Description

[items]

Array of CommitMergeRequestDto objects

Details of the MR associated with the commit

Table 6 CommitMergeRequestDto

Parameter

Type

Description

id

Integer

Definition

MR ID.

iid

Integer

Definition

MR No.

title

String

Definition

MR title.

description

String

Definition

MR detailed description.

state

String

Definition

MR status.

created_at

String

Definition

Time when an MR was created.

updated_at

String

Definition

Time when an MR was last updated.

merged_by

UserBasicDto object

Definition

MR merger information.

merged_at

String

Definition

Time when an MR was merged.

closed_by

UserBasicDto object

Definition

MR closer information.

closed_at

String

Definition

Time when an MR was closed.

target_branch

String

Definition

MR target branch name.

source_branch

String

Definition

MR source branch name.

user_notes_count

Integer

Definition

Number of review comments of an MR.

upvotes

Integer

Definition

Number of positive scores of an MR.

downvotes

Integer

Definition

Number of negative scores of an MR.

author

UserBasicDto object

Definition

MR author information.

assignee

Array of UserBasicDto objects

Definition

List of selected mergers of an MR.

source_repository_id

Integer

Definition

Unique identifier of a source repository.

target_repository_id

Integer

Definition

Unique identifier of a target repository.

labels

Array of strings

Definition

List of labels associated with an MR.

work_in_progress

Boolean

Definition

Whether an MR is in progress.

milestone

MilestoneBasicDto object

Definition

Information about milestones associated with an MR.

merge_when_pipeline_succeeds

Boolean

Definition

Whether to automatically merge the request when the CI/CD pipeline is successful.

merge_status

String

Definition

Merge status of an MR.

sha

String

Definition

Commit hash of an MR.

merge_commit_sha

String

Definition

Hash value of the merge commit.

discussion_locked

Boolean

Definition

Whether the MR discussion is locked.

force_remove_source_branch

Boolean

Definition

Whether the source branch is forcibly deleted.

should_remove_source_branch

Boolean

Definition

Whether the source branch should be deleted.

allow_collaboration

Boolean

Definition

Whether collaborators can participate.

allow_maintainer_to_push

Boolean

Definition

Whether the maintainer can push code.

web_url

String

Definition

URL of an MR.

time_stats

IssuableTimeStatsDto object

Definition

MR time statistics.

squash

Boolean

Definition

Whether to squash commits into one when merging.

merge_request_type

String

Definition

MR type.

Table 7 UserBasicDto

Parameter

Type

Description

id

Integer

Definition

User ID.

Value range:

1~2147483647

name

String

Definition

Username.

username

String

Definition

Username.

state

String

Definition:

User status

Value range:

  • active: available account

  • blocked: locked user

  • error: The user is not found

Enumeration values:

  • active

  • blocked

  • error

service_license_status

Integer

Service-level permission status. 0: disabled; 1: enabled

avatar_url

String

User profile picture URL

avatar_path

String

User profile picture path

email

String

User email

name_cn

String

Username (CN)

web_url

String

User homepage

nick_name

String

User alias

tenant_name

String

Tenant name

error_message

String

Definition

When some query APIs detect that the user permission in the transfer parameter is insufficient or the user does not exist, the user is returned but the field is not empty for information.

Table 8 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 9 IssuableTimeStatsDto

Parameter

Type

Description

time_estimate

Integer

Estimated MR time consumption

Default value:

0

total_time_spent

Integer

Total MR time consumption

Default value:

0

human_time_estimate

String

Estimated MR manual time consumption

human_total_time_spent

String

Total MR manual time consumption

Status code: 401

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Definition

Error code.

error_msg

String

Definition

Error message.

Status code: 404

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Definition

Error code.

error_msg

String

Definition

Error message.

Example Requests

None

Example Responses

Status code: 200

ok

{
  "id" : 72674,
  "iid" : 7,
  "title" : "Create a file",
  "description" : "test",
  "state" : "opened",
  "created_at" : "2025-05-21T20:03:32.000+08:00",
  "updated_at" : "2025-06-17T23:30:02.000+08:00",
  "merged_by" : null,
  "merged_at" : null,
  "closed_by" : null,
  "closed_at" : "2025-05-21T12:03:32.000+08:00",
  "target_branch" : "master",
  "source_branch" : "ddd1",
  "user_notes_count" : 0,
  "upvotes" : 0,
  "downvotes" : 0,
  "author" : {
    "id" : 9124,
    "name" : "example_name",
    "username" : "c369c68f1ff84679b5a8ed904d8bff1c",
    "state" : "active",
    "service_license_status" : null,
    "name_cn" : "c369c68f1ff84679b5a8ed904d8bff1c",
    "nick_name" : null,
    "tenant_name" : null,
    "error_message" : null
  },
  "assignee" : null,
  "source_repository_id" : 2111983939,
  "target_repository_id" : 2111983939,
  "labels" : [ "Bug", "bug" ],
  "work_in_progress" : false,
  "milestone" : null,
  "merge_when_pipeline_succeeds" : false,
  "merge_status" : "can_be_merged",
  "sha" : "2ce8081da020a9bc394164925394b3de7609c7a0",
  "merge_commit_sha" : null,
  "discussion_locked" : null,
  "force_remove_source_branch" : false,
  "should_remove_source_branch" : false,
  "allow_collaboration" : null,
  "allow_maintainer_to_push" : null,
  "web_url" : "https://example.com/********/2111983939/7/mergedetail?source=ddd1&target=master",
  "time_stats" : {
    "time_estimate" : null,
    "total_time_spent" : 0,
    "human_time_estimate" : null,
    "human_total_time_spent" : null
  },
  "squash" : false,
  "merge_request_type" : "MergeRequest"
}

Status code: 401

Unauthorized

{
  "error_code" : "CH.00000002",
  "error_msg" : "Recognize authentication information failed."
}

Status Codes

Status Code

Description

200

ok

401

Unauthorized

404

Not Found

Error Codes

See Error Codes.