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

获取仓库详情

功能介绍

获取仓库详情

调试

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

URI

GET /v4/repositories/{repository_id}

表1 路径参数

参数

是否必选

参数类型

描述

repository_id

Integer

参数解释:

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

约束限制:

不涉及。

取值范围:

1-2147483647

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:

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

约束限制:

必传。

取值范围:

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

默认取值:

不涉及。

响应参数

状态码:200

表3 响应Body参数

参数

参数类型

描述

id

Integer

参数解释:

仓库ID。

取值范围:

1-2147483647

description

String

参数解释:

仓库描述信息。

name

String

参数解释:

仓库名称。

name_with_namespace

String

参数解释:

仓库完整名称。

path

String

参数解释:

仓库路径。

path_with_namespace

String

参数解释:

仓库完整路径。

created_at

String

参数解释:

创建时间。

updated_at

String

参数解释:

更新时间。

archived

Boolean

参数解释:

是否归档。

ssh_url_to_repo

String

参数解释:

仓库ssh地址。

http_url_to_repo

String

参数解释:

仓库http地址。

project_id

String

参数解释:

仓库所属项目ID。

project_name

String

参数解释:

仓库所属项目名称。

develop_mode

String

参数解释:

仓库开发模式。

取值范围:

  • normal

  • CR

枚举值:

  • normal

  • CR

moderation_result

Boolean

参数解释:

审核状态。

default_branch

String

参数解释:

仓库默认分支

约束限制:

不涉及。

avatar_url

String

参数解释:

仓库图标url

约束限制:

不涉及。

star_count

Integer

参数解释:

关注数

约束限制:

不涉及。

取值范围:

1-2147483647

forks_count

Integer

参数解释:

fork数

约束限制:

不涉及。

取值范围:

1-2147483647

open_issues_count

Integer

参数解释:

开启issue数

约束限制:

不涉及。

取值范围:

1-2147483647

open_merge_requests_count

Integer

参数解释:

开启中的CR、MR数量

约束限制:

不涉及。

取值范围:

1-2147483647

last_activity_at

String

参数解释:

最后活跃时间

约束限制:

不涉及。

namespace

NamespaceBasicDto object

参数解释:

命名空间

约束限制:

不涉及。

empty_repo

Boolean

参数解释:

空仓库

约束限制:

不涉及。

starred

Boolean

参数解释:

是否已关注

约束限制:

不涉及。

visibility

String

参数解释:

仓库可见等级

约束限制:

不涉及。

security_tag

String

参数解释:

仓库保密等级

约束限制:

不涉及。

security

String

参数解释:

仓库保密等级

约束限制:

不涉及。

network_type

String

参数解释:

网络类型

约束限制:

不涉及。

owner

RepositoryUserBasicDto object

参数解释:

仓库所有者

约束限制:

不涉及。

creator

RepositoryUserBasicDto object

参数解释:

仓库创建者

约束限制:

不涉及。

creator_id

Integer

参数解释:

创建者ID

约束限制:

不涉及。

取值范围:

1-2147483647

forked_from_repository

RepositorySimpleDto object

参数解释:

fork仓库源仓

约束限制:

不涉及。

uuid

String

参数解释:

仓库唯一标识符。

约束限制:

不涉及。

ancestor_ids

Array of integers

参数解释:

祖先仓库ID列表。

约束限制:

不涉及。

取值范围:

1-2147483647

ancestor_names

Array of strings

参数解释:

祖先仓库名称列表。

约束限制:

不涉及。

import_status

String

参数解释:

导入状态。

约束限制:

不涉及。

import_url

String

参数解释:

导入源地址。

约束限制:

不涉及。

import_error

String

参数解释:

导入错误信息。

约束限制:

不涉及。

repo_type

String

参数解释:

仓库类型。

约束限制:

不涉及。

only_allow_merge_if_pipeline_succeeds

Boolean

参数解释:

是否仅在流水线成功时允许合并。

约束限制:

不涉及。

request_access_enabled

Boolean

参数解释:

是否启用访问请求。

约束限制:

不涉及。

only_allow_merge_if_all_discussions_are_resolved

Boolean

参数解释:

是否仅在所有检视意见解决时允许合并。

约束限制:

不涉及。

merge_method

String

参数解释:

合并方法。

约束限制:

不涉及。

fork_network_repositories

Array of RepositoryIdentityDto objects

参数解释:

fork关联仓库列表。

约束限制:

不涉及。

permissions

PermissionsDto object

权限

repository_type

String

参数解释:

仓库类型。

约束限制:

不涉及。

statistics

RepositoryStatisticsDto object

参数解释:

项目统计信息。

约束限制:

不涉及。

branch_count

Integer

参数解释:

分支数量。

约束限制:

不涉及。

取值范围:

1-2147483647

tag_count

Integer

参数解释:

Tag数量。

约束限制:

不涉及。

取值范围:

1-2147483647

label_count

Integer

参数解释:

标签数量。

约束限制:

不涉及。

取值范围:

1-2147483647

member_count

Integer

参数解释:

成员数量。

约束限制:

不涉及。

取值范围:

1-2147483647

表4 NamespaceBasicDto

参数

参数类型

描述

id

Integer

参数解释:

命名空间ID。

约束限制:

不涉及。

取值范围:

1-2147483647

name

String

参数解释:

命名空间名称。

约束限制:

不涉及。

path

String

参数解释:

路径。

约束限制:

不涉及。

develop_mode

String

参数解释:

开发模式。

约束限制:

不涉及。

kind

String

参数解释:

类型。

约束限制:

不涉及。

full_path

String

参数解释:

完整路径。

约束限制:

不涉及。

full_name

String

参数解释:

完整名称。

约束限制:

不涉及。

parent_id

Integer

参数解释:

父级ID。

约束限制:

不涉及。

取值范围:

1-2147483647

visibility_level

Integer

参数解释:

可见级别。

约束限制:

不涉及。

取值范围:

1-2147483647

enable_file_control

Boolean

参数解释:

开启文件权限控制。

约束限制:

不涉及。

owner_id

Integer

参数解释:

所有人ID。

约束限制:

不涉及。

取值范围:

1-2147483647

表5 RepositoryUserBasicDto

参数

参数类型

描述

id

Integer

参数解释:

用户id

约束限制:

不涉及。

取值范围:

1-2147483647

name

String

参数解释:

用户名称

约束限制:

不涉及。

username

String

参数解释:

用户名

约束限制:

不涉及。

state

String

参数解释:

用户状态。

取值范围:

  • active,激活。

  • blocked,禁用。

枚举值:

  • active

  • blocked

service_license_status

Integer

参数解释:

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

约束限制:

不涉及。

取值范围:

1-2147483647

name_cn

String

参数解释:

用户中文名称

约束限制:

不涉及。

nick_name

String

参数解释:

用户昵称

约束限制:

不涉及。

tenant_name

String

参数解释:

租户名称

约束限制:

不涉及。

表6 RepositorySimpleDto

参数

参数类型

描述

id

Integer

参数解释:

仓库ID。

取值范围:

1-2147483647

description

String

参数解释:

仓库描述信息。

name

String

参数解释:

仓库名称。

name_with_namespace

String

参数解释:

仓库完整名称。

path

String

参数解释:

仓库路径。

path_with_namespace

String

参数解释:

仓库完整路径。

created_at

String

参数解释:

创建时间。

updated_at

String

参数解释:

更新时间。

archived

Boolean

参数解释:

是否归档。

ssh_url_to_repo

String

参数解释:

仓库ssh地址。

http_url_to_repo

String

参数解释:

仓库http地址。

project_id

String

参数解释:

仓库所属项目ID。

project_name

String

参数解释:

仓库所属项目名称。

develop_mode

String

参数解释:

仓库开发模式。

取值范围:

  • normal

  • CR

枚举值:

  • normal

  • CR

moderation_result

Boolean

参数解释:

审核状态。

表7 RepositoryIdentityDto

参数

参数类型

描述

id

Integer

参数解释:

项目ID。

约束限制:

不涉及。

取值范围:

1-2147483647

path_with_namespace

String

参数解释:

项目路径。

约束限制:

不涉及。

表8 PermissionsDto

参数

参数类型

描述

repository_access

MemberAccess object

参数解释:

仓库权限。

约束限制:

不涉及。

group_access

MemberAccess object

参数解释:

代码组权限。

约束限制:

不涉及。

表9 MemberAccess

参数

参数类型

描述

access_level

Integer

参数解释:

访问级别。

约束限制:

不涉及。

取值范围:

1-2147483647

notification_level

Integer

参数解释:

通知级别。

约束限制:

不涉及。

取值范围:

1-2147483647

表10 RepositoryStatisticsDto

参数

参数类型

描述

commit_count

Integer

参数解释:

提交数量。

约束限制:

不涉及。

取值范围:

1-2147483647

storage_size

Double

参数解释:

存储大小。

约束限制:

不涉及。

取值范围:

1.0-1024000.0

repository_size

Double

参数解释:

仓库大小。

约束限制:

不涉及。

取值范围:

1.0-1024000.0

lfs_objects_size

Double

参数解释:

LFS对象大小。

约束限制:

不涉及。

取值范围:

1.0-1024000.0

tenant_repo_size_limit

Long

参数解释:

租户仓库大小限制。

约束限制:

不涉及。

取值范围:

1-2147483647

请求示例

响应示例

状态码:200

获取仓库详情

{
  "id" : 2111993598,
  "description" : null,
  "name" : "test_import",
  "name_with_namespace" : "22d9c8e7fe464697bc2a358df175dd29 / g111 / g22 / g3 / g4 / g5 / test_import",
  "path" : "test_import",
  "path_with_namespace" : "22d9c8e7fe464697bc2a358df175dd29/g111/g22/g3/g4/g5/test_import",
  "created_at" : "2025-01-14T20:13:56.000+08:00",
  "updated_at" : "2025-01-14T20:13:56.000+08:00",
  "archived" : false,
  "ssh_url_to_repo" : "git@repo.com:22d9c8e7fe464697bc2a358df175dd29/g111/g22/g3/g4/g5/test_import.git",
  "http_url_to_repo" : "https://repo.com/22d9c8e7fe464697bc2a358df175dd29/g111/g22/g3/g4/g5/test_import.git",
  "project_id" : "22d9c8e7fe464697bc2a358df175dd29",
  "project_name" : "SubscriptionTest",
  "develop_mode" : "normal",
  "moderation_result" : true,
  "default_branch" : "master",
  "star_count" : 0,
  "forks_count" : 0,
  "open_merge_requests_count" : 0,
  "last_activity_at" : "2025-01-14T20:13:56.000+08:00",
  "namespace" : {
    "id" : 2111853526,
    "name" : "g5",
    "path" : "g5",
    "develop_mode" : "normal",
    "kind" : "group",
    "full_path" : "22d9c8e7fe464697bc2a358df175dd29/g111/g22/g3/g4/g5",
    "full_name" : null,
    "parent_id" : 2111853525,
    "visibility_level" : 0,
    "enable_file_control" : null,
    "owner_id" : null
  },
  "empty_repo" : false,
  "starred" : false,
  "visibility" : "private",
  "security" : "internal",
  "owner" : { },
  "creator" : {
    "id" : 9124,
    "name" : "test_user",
    "username" : "c369c68f1ff84679b5a8ed904d8bff1c",
    "state" : "active",
    "service_license_status" : null,
    "name_cn" : "test_user",
    "nick_name" : "beta_dv",
    "tenant_name" : "test_tenant"
  },
  "creator_id" : 9124,
  "statistics" : { },
  "branch_count" : 2,
  "tag_count" : 0,
  "member_count" : 8,
  "import_status" : "none",
  "import_url" : "https://gitee.com/api-review-test-group/return-test.git",
  "import_error" : null,
  "repo_type" : "normal",
  "only_allow_merge_if_pipeline_succeeds" : false,
  "only_allow_merge_if_all_discussions_are_resolved" : false,
  "merge_method" : "merge",
  "fork_network_repositories" : [ ],
  "permissions" : {
    "repository_access" : {
      "access_level" : 50,
      "notification_level" : 3
    },
    "group_access" : {
      "access_level" : 50,
      "notification_level" : 3
    }
  },
  "repository_type" : null,
  "uuid" : "b166cca9cf9442a0b82159769d6aec4c",
  "ancestor_ids" : [ 2111851014, 2111853523, 2111853524, 2111853525, 2111853526 ],
  "ancestor_names" : [ "g111", "g22", "g3", "g4", "g5" ]
}

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 ShowRepositorySolution {

    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();
        ShowRepositoryRequest request = new ShowRepositoryRequest();
        request.withRepositoryId({repository_id});
        try {
            ShowRepositoryResponse response = client.showRepository(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 = ShowRepositoryRequest()
        request.repository_id = {repository_id}
        response = client.show_repository(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.ShowRepositoryRequest{}
	request.RepositoryId = int32({repository_id})
	response, err := client.ShowRepository(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多

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

状态码

状态码

描述

200

获取仓库详情

错误码

请参见错误码

相关文档