文档首页/ 代码托管 CodeArts Repo/ API参考/ 应用示例/ 示例3:查询某仓库对应的分支
更新时间:2023-05-06 GMT+08:00

示例3:查询某仓库对应的分支

场景描述

本章以软件开发生产线用户为例,指导您通过API查询指定仓库的分支列表。

API的调用方法请参见如何调用API

前提条件

用户已经在软件开发生产线控制台中开启了代码托管服务。

总体思路

先通过用户token查询仓库列表,再通过仓库短ID,查询指定仓库的分支列表,步骤如下:

  1. 查询用户的所有仓库
  2. 查询某仓库对应的分支

步骤1:查询用户的所有仓库

  • 接口信息:
    URI:GET v2/projects/repositories 
  • 请求示例:
    GET  https://codehub-ext.ap-southeast-3.myhuaweicloud.com/v2/projects/repositories
  • 响应示例:
    {
     "result": {
      "total": 40,
      "repositories": [
       {
        "star": false,
        "status": 5,
        "userRole": null,
        "repository_uuid": "25c88b23d4dc400fa7b3e2a152e4d53c",
        "repository_id": 522140,
        "repository_name": "1111111111111",
        "ssh_url": "git@codehub.devcloud.cn-north-208.ulanqab.huawei.com:testzxq00001/1111111111111.git",
        "https_url": "https://codehub.devcloud.cn-north-208.ulanqab.huawei.com/testzxq00001/1111111111111.git",
        "group_name": "testzxq00001",
        "web_url": "https://devcloud.cn-north-208.ulanqab.huawei.com/codehub/522140/home",
        "visibility_level": 0,
        "created_at": "2020-07-22 10:45:56",
        "updated_at": "2020-07-22 10:45:56",
        "repository_size": "0.16M",
        "lfs_size": "0.00M",
        "creator_name": "devcloud_codehub_l00314597_01",
        "domain_name": "devcloud_codehub_l00314597_01",
        "is_owner": 1,
        "iam_user_uuid": "a618e34bd5704be3ae3395dfede06041",
        "project_uuid": "a689e057c2304abfa35d4ff65630a90a",
        "project_is_deleted": "false"
       }
      ]
     },
     "status": "success"}

步骤2:查询分支列表

  • 接口信息:
    URI:GET v1/repositories/{repository_id}/branches
  • 请求示例:
    GET  https://codehub-ext.ap-southeast-3.myhuaweicloud.com/v1/repositories/522140/branches
  • 响应示例:
    {
     "result": {
      "total": 1,
      "branches": [
       {
        "name": "master",
        "is_protected": false
       }
      ]
     },
     "status": "success"
    }