获取项目所有分支¶
GET /api/v5/repos/{owner}/{repo}/branches
该接口用于获取指定项目(仓库)下的全部分支列表,支持按名称或更新时间排序及分页查询,返回每个分支的名称、描述、指向的提交、是否默认分支、创建时间、创建人及保护状态等信息。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(组织或个人的地址path) |
repo |
path | string | 是 | 仓库路径(path) |
sort |
query | string | 否 | 排序字段,枚举:name / updated |
direction |
query | string | 否 | 排序方向,枚举:asc / desc |
page |
query | integer | 否 | 当前的页码 |
per_page |
query | integer | 否 | 每页的数量,最大为 100,默认 20 |
响应参数¶
响应体为分支对象数组(array<object>)。每个分支对象的字段如下:
branch 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
name |
string | 是 | 否 | 分支名称 |
description |
string | 是 | 否 | 分支描述 |
commit |
object | 是 | 否 | 分支所指向的提交对象 |
default_branch |
boolean | 是 | 否 | 是否为默认分支 |
created_at |
string | 是 | 否 | 分支创建时间 |
creator |
object | 是 | 否 | 创建人对象 |
protected |
boolean | 是 | 否 | 分支是否受保护 |
commit 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.commit |
object | 是 | 否 | 提交详情对象 |
commit.sha |
string | 是 | 否 | 提交的 SHA 值 |
commit.url |
string | 是 | 否 | 提交详情地址 |
commit.commit 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.commit.author |
object | 是 | 否 | 提交作者对象 |
commit.commit.committer |
object | 是 | 否 | 提交者对象 |
commit.commit.message |
string | 是 | 否 | 提交信息 |
commit.commit.author 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.commit.author.name |
string | 是 | 否 | 作者名称 |
commit.commit.author.date |
string | 是 | 否 | 提交时间 |
commit.commit.author.email |
string | 是 | 否 | 作者邮箱 |
commit.commit.committer 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
commit.commit.committer.name |
string | 是 | 否 | 提交者名称 |
commit.commit.committer.date |
string | 是 | 否 | 提交时间 |
commit.commit.committer.email |
string | 是 | 否 | 提交者邮箱 |
creator 对象
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
creator.avatar_url |
string | 是 | 否 | 创建人头像地址 |
creator.id |
string | 是 | 否 | 创建人 ID |
creator.login |
string | 是 | 否 | 创建人登录名 |
creator.name |
string | 是 | 否 | 创建人名称 |
失败响应¶
本接口可能的失败响应如下:
400 参数错误
401 未认证
Note: 以上错误字段名以后端实际返回为准。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(Bad request) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
仓库不存在(Not found) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);- 本接口允许匿名访问,可不携带认证凭证;如需更高权限,也可在查询串中携带 AtomGit 用户访问令牌(
access_token=<token>)。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches?sort=updated&direction=desc&page=1&per_page=20' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/branches",
{
method: "GET",
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",
headers={
"Accept": "application/json",
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
[
{
"name": "main",
"description": "默认分支",
"commit": {
"commit": {
"author": {
"name": "octocat",
"date": "2024-04-16T08:41:20.000Z",
"email": "octocat@noreply.atomgit.com"
},
"committer": {
"name": "octocat",
"date": "2024-04-16T08:41:20.000Z",
"email": "octocat@noreply.atomgit.com"
},
"message": "提交测试类"
},
"sha": "1d45587145552af003cd32cc6fde9ac9d9e5fd42",
"url": "https://api.atomgit.com/api/v5/repos/octocat/hello-world/commits/1d45587145552af003cd32cc6fde9ac9d9e5fd42"
},
"default_branch": true,
"created_at": "2024-04-16T08:41:20.000Z",
"creator": {
"avatar_url": "https://api.atomgit.com/avatars/octocat.png",
"id": "10001",
"login": "octocat",
"name": "octocat"
},
"protected": true
}
]
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误或请求无法解析 |
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
403 |
禁止访问 |
404 |
仓库或路径不存在 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc