跳转至

获取单个分支

GET /api/v5/repos/{owner}/{repo}/branches/{branch}

该接口用于获取指定仓库中的单个分支信息,返回分支名称、描述、所指向提交的详细信息以及是否已合并、是否受保护、是否为默认分支等状态。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(组织或个人的地址 path)
repo path string 是 仓库路径(path)
branch path string 是 分支名称

响应参数

字段 类型 必返 可为空 说明
name string 是 否 分支名称
description string 是 否 分支描述
commit object 是 否 分支指向的提交信息
merged boolean 是 否 是否为已合并分支
protected boolean 是 否 是否为受保护分支
developers_can_push boolean 是 否 开发者是否可推送
developers_can_merge boolean 是 否 开发者是否可合并
can_push boolean 是 否 当前用户是否可推送
default boolean 是 否 是否为默认分支
created_at string 是 否 创建时间
creator object 是 否 创建人信息

commit 对象

字段 类型 必返 可为空 说明
commit.id string 是 否 提交 ID
commit.message string 是 否 提交信息
commit.parent_ids string[] 是 否 父提交 ID 列表
commit.authored_date string 是 否 提交创建时间
commit.author_name string 是 否 提交作者名称
commit.author_email string 是 否 提交作者邮箱
commit.author_user_name string 是 否 提交作者用户名
commit.committed_date string 是 否 提交时间
commit.committer_name string 是 否 提交者名称
commit.committer_email string 是 否 提交者邮箱
commit.committer_user_name string 是 否 提交者用户名
commit.short_id string 是 否 提交短 ID
commit.created_at string 是 否 创建时间
commit.title string 是 否 提交标题
commit.author_avatar_url string 是 否 提交作者头像地址
commit.committer_avatar_url string 是 否 提交者头像地址

creator 对象

字段 类型 必返 可为空 说明
creator.avatar_url string 是 否 头像地址
creator.id string 是 否 创建人 ID
creator.login string 是 否 创建人登录名
creator.name string 是 否 创建人名称

失败响应

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

404 资源不存在

{
  "error": "not_found",
  "message": "仓库或分支不存在"
}

上述失败响应仅为示例,错误字段名以后端实际返回为准。

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 仓库或分支不存在(Not found)

请求示例

参数说明

示例与本文档其余部分自洽,占位符含义如下:

<owner> 替换为仓库所属空间地址(组织或个人的地址 path); <repo> 替换为仓库路径(path); <branch> 替换为分支名称。

该接口允许匿名访问,示例中未携带令牌;如需以用户身份调用,也可在 URL 上追加 ?access_token=<token>(<token> 为你的 AtomGit 用户访问令牌)。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>", {
  headers: {
    "Accept": "application/json",
  },
});

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.get(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches/<branch>",
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "name": "dev",
  "description": "开发分支",
  "commit": {
    "id": "b6d44deb0ca73d7a50916d0fea02c72edd6c924e",
    "message": "dev新增文件",
    "parent_ids": [
      "13956ffeb5e5e1ce60c2ed91d3e579fc50b1f167",
      "3e42dcb9c09b39972c65536dad71651322470f28"
    ],
    "authored_date": "2024-04-15T14:38:50.000Z",
    "author_name": "csdntest13",
    "author_email": "csdntest13@noreply.gitcode.com",
    "author_user_name": "csdntest13",
    "committed_date": "2024-04-15T14:38:50.000Z",
    "committer_name": "csdntest13",
    "committer_email": "csdntest13@noreply.gitcode.com",
    "committer_user_name": "csdntest13",
    "short_id": "b6d44deb",
    "created_at": "2024-04-15T14:38:50.000Z",
    "title": "merge refs/merge-requests/56/head into dev",
    "author_avatar_url": "https://api.atomgit.com/avatar.png",
    "committer_avatar_url": "https://api.atomgit.com/avatar.png"
  },
  "merged": false,
  "protected": false,
  "developers_can_push": false,
  "developers_can_merge": false,
  "can_push": true,
  "default": false,
  "created_at": "2024-04-15T14:38:50.000Z",
  "creator": {
    "avatar_url": "https://api.atomgit.com/avatar.png",
    "id": "494",
    "login": "csdntest13",
    "name": "csdntest13"
  }
}

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
403 禁止访问
404 仓库或分支不存在
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc