跳转至

获取代码量贡献

GET /api/v5/{owner}/{repo}/repository/commit_statistics

该接口用于获取指定仓库中某个分支的代码量贡献统计,包括提交记录以及各用户的代码新增与删除行数、提交次数等信息,可通过作者、日期范围等条件筛选统计结果。

访问令牌支持说明

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

是否允许匿名访问

此接口允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(组织或个人的地址 path)
repo path string 是 仓库路径(path)
branch_name query string 是 分支名
author query string 否 作者用户名
only_self query boolean 否 是否仅查询个人
since query string 否 仅返回此日期及以后的提交
until query string 否 仅返回此日期及之前的提交
access_token query string 否 用户授权码

响应参数

字段 类型 必返 可为空 说明
commits object[] 是 否 提交记录列表
statistics object[] 是 否 代码量贡献统计列表
total integer 是 否 统计数据条数

commits 对象

字段 类型 必返 可为空 说明
commits.author_name string 是 否 作者用户名
commits.date string 是 否 提交日期

statistics 对象

字段 类型 必返 可为空 说明
statistics.project_id integer 是 否 仓库 ID
statistics.branch string 是 否 分支名
statistics.user_name string 是 否 用户名
statistics.nick_name string 是 否 昵称
statistics.add_lines integer 是 否 新增代码行数
statistics.delete_lines integer 是 否 删除代码行数
statistics.commit_count integer 是 否 提交次数

失败响应

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 branch_name 不能为空"
}

401 未认证

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

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 资源不存在(Not found)
405 请求方法不支持(Method not allowed)
429 请求过于频繁,触发限流(Too many requests)
500 系统内部错误(Internal server error)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(组织或个人的地址 path);<repo> 替换为仓库路径(path);<branch_name> 替换为要统计的分支名。可选查询参数 author / only_self / since / until / access_token 可按需追加。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/<owner>/<repo>/repository/commit_statistics?branch_name=<branch_name>' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/<owner>/<repo>/repository/commit_statistics?branch_name=<branch_name>", {
  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/<owner>/<repo>/repository/commit_statistics",
    params={"branch_name": "<branch_name>"},
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "commits": [
    {
      "author_name": "tester",
      "date": "2024-11-12"
    },
    {
      "author_name": "tester",
      "date": "2024-01-15"
    }
  ],
  "statistics": [
    {
      "project_id": 1359,
      "branch": "main",
      "user_name": "tester",
      "nick_name": "测试",
      "add_lines": 4370,
      "delete_lines": 351,
      "commit_count": 123
    }
  ],
  "total": 1
}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效(缺少/无效的访问凭证)
403 禁止访问(无权限)
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

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