更新时间:2025-09-28 GMT+08:00
分享

获取仓库MR列表

功能介绍

获取仓库MR列表

调试

您可以在API Explorer中调试该接口,支持自动认证鉴权。API Explorer可以自动生成SDK代码示例,并提供SDK代码示例调试功能。

URI

GET /v4/repositories/{repository_id}/merge-requests

表1 路径参数

参数

是否必选

参数类型

描述

repository_id

Integer

参数解释:

仓库的ID,通过查询用户所有仓库接口查询项目列表获取。

约束限制:

不涉及。

取值范围:

1-2147483647

表2 Query参数

参数

是否必选

参数类型

描述

offset

Integer

参数解释:

偏移量,从0开始。

取值范围:

0-2147483647

默认取值:

0

limit

Integer

参数解释:

返回数量。

取值范围:

1-100

默认取值:

20

state

String

参数解释:

返回指定状态的合并请求。

约束限制:

  • all,表示所有状态。

  • opened,表示开启中状态

  • closed,表示已关闭状态

  • merged,表示已合并状态

默认取值:

all

枚举值:

  • all

  • opened

  • closed

  • merged

order_by

String

参数解释:

排序方式。

取值范围:

  • created_at,创建时间。

  • updated_at,更新时间。

默认取值:

created_at

枚举值:

  • created_at

  • updated_at

sort

String

参数解释:

排序方式。

约束限制:

  • asc,升序。

  • desc,降序。

默认取值:

desc

枚举值:

  • asc

  • desc

author_id

String

参数解释:

返回由指定ID用户创建的合并请求。

多个ID以逗号','分隔,返回满足条件的合并请求并集。

source_branch

String

参数解释:

返回指定源分支的合并请求。

target_branch

String

参数解释:

返回指定目标分支的合并请求。

search

String

参数解释:

合并请求关键字搜索。

返回标题或者描述包含对应关键字的合并请求。

source_repository_id

Integer

参数解释:

查询指定源仓库的数据。

only_count

Boolean

参数解释:

是否仅返回合并请求计数。

取值范围:

  • true,仅返回合并请求计数。

  • false,返回合并请求详细信息。

默认取值:

false

labels

String

参数解释:

查询包含指定labels的合并请求。

取值范围:

1-2000

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

用户Token。 通过调用IAM服务获取用户Token接口获取(响应消息头中X-Subject-Token的值)。

约束限制:

必传。

取值范围:

字符串长度不少于1,不超过10万。

默认取值:

不涉及。

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

[数组元素]

Array of MergeRequestListBasicDto objects

合并请求基本信息

表5 MergeRequestListBasicDto

参数

参数类型

描述

id

Integer

参数解释:

合并请求ID。

iid

Integer

参数解释:

合并请求位于当前仓库序号。

title

String

参数解释:

合并请求标题。

source_branch

String

参数解释:

合并请求源分支。

target_branch

String

参数解释:

合并请求目标分支。

state

String

参数解释:

合并请求状态。

created_at

String

参数解释:

合并请求创建时间。

updated_at

String

参数解释:

合并请求更新时间。

source_repository_id

Integer

参数解释:

合并请求源仓库ID。

review_mode

String

参数解释:

合并请求检视模式。

author

UserBasicDto object

参数解释:

合并请求作者。

closed_at

String

参数解释:

合并请求关闭时间。

closed_by

UserBasicDto object

参数解释:

合并请求关闭人。

merged_at

String

参数解释:

合并请求合并时间。

merged_by

UserBasicDto object

参数解释:

合并请求合并人。

pipeline_status

String

参数解释:

合并请求流水线状态。

codequality_status

String

参数解释:

合并请求代码质量状态。

pipeline_status_with_code_quality

String

参数解释:

合并请求流水线状态。

notes

Integer

参数解释:

合并请求检视意见。

source_repository

ProjectSimpleDto object

参数解释:

合并请求源仓库信息。

target_repository

ProjectSimpleDto object

参数解释:

合并请求目标仓库信息。

web_url

String

参数解释:

合并请求URL地址。

added_lines

Integer

参数解释:

合并请求新增代码行数。

removed_lines

Integer

参数解释:

合并请求删除代码行数。

merge_request_type

String

参数解释:

合并请求检视模式。

source_git_url

String

参数解释:

合并请求git地址。

labels

Array of Map<String,Object> objects

参数解释:

合并请求标签。

score

Integer

参数解释:

合并请求分数。

min_merged_score

Integer

参数解释:

合并请求最小合入分数。

source_product_id

String

参数解释:

合并请求源项目ID。

target_product_id

String

参数解释:

合并请求目标项目ID。

product_name

String

参数解释:

合并请求项目名。

notes_count

NotesCountDto object

参数解释:

合并请求检视意见计数。

moderation_result

Boolean

参数解释:

合并请求审核结果。

moderation_time

Long

参数解释:

合并请求审核时间。

moderation_status

Integer

参数解释:

合并请求审核状态。

表6 UserBasicDto

参数

参数类型

描述

id

Integer

参数解释:

用户id。

取值范围:

1-2147483647

name

String

参数解释:

用户名称。

username

String

参数解释:

用户名。

state

String

参数解释:

用户状态。

取值范围:

  • active: 可用账户。

  • blocked: 被锁定用户。

  • error: 未查询到该用户。

枚举值:

  • active

  • blocked

  • error

service_license_status

Integer

服务级权限状态 0:停用 1:启用

avatar_url

String

用户头像url

avatar_path

String

用户头像路径

email

String

用户邮箱

name_cn

String

用户中文名称

web_url

String

用户个人首页

nick_name

String

用户昵称

tenant_name

String

租户名称

error_message

String

参数解释:

部分查询接口校验到传参里的用户权限不足或不存在时,返回该用户但该字段不为空用于提示。

表7 ProjectSimpleDto

参数

参数类型

描述

id

Integer

仓库id

description

String

仓库描述信息

name

String

仓库名称

name_with_namespace

String

组织名/组织名.../仓库名

path

String

仓库路径

path_with_namespace

String

仓库完整路径

created_at

String

创建时间

updated_at

String

更新时间

archived

Boolean

是否归档

is_kia

Boolean

是否机密

ssh_url_to_repo

String

仓库ssh地址

http_url_to_repo

String

仓库http地址

web_url

String

仓库页面链接

readme_url

String

仓库readme文件链接

project_id

String

项目id

project_name

String

项目名称

develop_mode

String

仓库开发模式:normal、CR

moderation_result

Boolean

审核状态

表8 NotesCountDto

参数

参数类型

描述

notes_count

Integer

检视意见总数

unresolved_notes_count

Integer

未解决的检视意见数量

already_resolved_count

Integer

已解决的检视意见数量

need_resolved_count

Integer

需要解决的检视意见总数

状态码:401

表9 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码。

error_msg

String

参数解释:

错误信息。

状态码:404

表10 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码。

error_msg

String

参数解释:

错误信息。

请求示例

响应示例

状态码:200

OK

{
  "id" : 72674,
  "iid" : 7,
  "title" : "新建文件",
  "source_branch" : "ddd1",
  "target_branch" : "master",
  "state" : "opened",
  "created_at" : "2025-05-21T12:03:32.000+08:00",
  "updated_at" : "2025-06-17T15:30:02.000+08:00",
  "source_repository_id" : 2111983939,
  "review_mode" : "approval",
  "author" : {
    "id" : 9124,
    "name" : "test",
    "username" : "c369c68f1ff84679b5a8ed904d8bff1c",
    "state" : "active",
    "service_license_status" : null,
    "name_cn" : "test",
    "nick_name" : "beta_dv",
    "tenant_name" : "example_name",
    "error_message" : null
  },
  "closed_at" : "2025-05-21T12:03:32.000+08:00",
  "closed_by" : null,
  "merged_at" : null,
  "merged_by" : null,
  "pipeline_status" : "",
  "codequality_status" : null,
  "pipeline_status_with_code_quality" : "",
  "notes" : 0,
  "web_url" : "https://example.com/********/2111983939/7/mergedetail?source=ddd1&target=master",
  "added_lines" : 0,
  "removed_lines" : 0,
  "merge_request_type" : "MergeRequest",
  "source_git_url" : "git@example.com:3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
  "labels" : [ {
    "color" : "#000",
    "name" : "Bug",
    "description" : "456",
    "id" : 8,
    "title" : "Bug",
    "type" : null,
    "textColor" : "#FFFFFF"
  }, {
    "color" : "#000",
    "name" : "bug",
    "description" : "456",
    "id" : 7,
    "title" : "bug",
    "type" : null,
    "textColor" : "#FFFFFF"
  } ],
  "score" : 0,
  "min_merged_score" : null,
  "source_project_id" : "3e1f6634946144c2b1ccb46fb8152b8f",
  "target_project_id" : null,
  "product_name" : null,
  "notes_count" : null,
  "moderation_result" : null,
  "moderation_time" : null,
  "moderation_status" : null,
  "source_repository" : {
    "id" : 2111983939,
    "description" : "ddd",
    "name" : "dddd",
    "name_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f / dddd",
    "path" : "dddd",
    "path_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "created_at" : "2024-11-30T17:46:46.000+08:00",
    "updated_at" : "2024-11-30T17:46:46.000+08:00",
    "archived" : false,
    "ssh_url_to_repo" : "git@example.com:3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "http_url_to_repo" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "project_id" : null,
    "project_name" : null,
    "develop_mode" : null,
    "moderation_result" : null
  },
  "target_repository" : {
    "id" : 2111983939,
    "description" : "ddd",
    "name" : "dddd",
    "name_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f / dddd",
    "path" : "dddd",
    "path_with_namespace" : "3e1f6634946144c2b1ccb46fb8152b8f/dddd",
    "created_at" : "2024-11-30T17:46:46.000+08:00",
    "updated_at" : "2024-11-30T17:46:46.000+08:00",
    "archived" : false,
    "ssh_url_to_repo" : "git@example.com:3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "http_url_to_repo" : "https://example.com/3e1f6634946144c2b1ccb46fb8152b8f/dddd.git",
    "project_id" : null,
    "project_name" : null,
    "develop_mode" : null,
    "moderation_result" : null
  }
}

状态码:401

Unauthorized

{
  "error_code" : "CH.00000002",
  "error_msg" : "认证信息无法识别"
}

状态码:404

Not Found

{
  "error_code" : "CH.00402000",
  "error_msg" : "该仓库不存在,请检查后重试。"
}

SDK代码示例

SDK代码示例如下。

Java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.codehub.v4.region.CodeHubRegion;
import com.huaweicloud.sdk.codehub.v4.*;
import com.huaweicloud.sdk.codehub.v4.model.*;


public class ListRepositoryMergeRequestsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        CodeHubClient client = CodeHubClient.newBuilder()
                .withCredential(auth)
                .withRegion(CodeHubRegion.valueOf("<YOUR REGION>"))
                .build();
        ListRepositoryMergeRequestsRequest request = new ListRepositoryMergeRequestsRequest();
        request.withRepositoryId({repository_id});
        try {
            ListRepositoryMergeRequestsResponse response = client.listRepositoryMergeRequests(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcodehub.v4.region.codehub_region import CodeHubRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcodehub.v4 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]

    credentials = BasicCredentials(ak, sk)

    client = CodeHubClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CodeHubRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListRepositoryMergeRequestsRequest()
        request.repository_id = {repository_id}
        response = client.list_repository_merge_requests(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

Go

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    codehub "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codehub/v4"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codehub/v4/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/codehub/v4/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := codehub.NewCodeHubClient(
        codehub.CodeHubClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListRepositoryMergeRequestsRequest{}
	request.RepositoryId = int32({repository_id})
	response, err := client.ListRepositoryMergeRequests(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

401

Unauthorized

404

Not Found

错误码

请参见错误码

相关文档