跳转至

获取仓库贡献者统计信息

GET /api/v5/repos/{owner}/{repo}/contributors/statistic

该接口用于获取指定仓库的贡献者统计信息,返回每位贡献者的新增行数、删除行数、变更总数和提交次数等汇总数据,以及按日期细分的贡献明细,并支持按贡献者、时间范围及分支进行筛选。

访问令牌支持说明

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

是否允许匿名访问

此接口允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(企业、组织或个人的地址path)
repo path string 是 仓库路径(path)
author query string 否 过滤贡献者的用户名。支持指定用户名以获取该用户的贡献数据。默认情况下,返回所有用户的贡献数据
current_user query boolean 否 是否只返回当前用户的数据。true 表示只返回当前用户的贡献数据,false 或省略则返回所有用户的贡献数据;当为 true 时,优先级高于 author 参数,默认 false
since query string 否 起始日期,格式为 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss,用来限定返回的贡献数据的起始时间
until query string 否 结束日期,格式为 YYYY-MM-DD 或 YYYY-MM-DD HH:mm:ss,用来限定返回的贡献数据的结束时间
ref_name query string 否 指定要获取贡献数据的 ref_name(分支名称、commit id、tag 名称),不传或为空时使用默认分支

响应参数

字段 类型 必返 可为空 说明
name string 是 否 贡献者用户名
email string 是 否 贡献者邮箱
overview object 是 否 贡献者的汇总统计
contributions array 是 否 按日期细分的贡献明细列表

overview 对象

字段 类型 必返 可为空 说明
overview.additions integer 是 否 新增行数
overview.deletions integer 是 否 删除行数
overview.total_changes integer 是 否 变更总数
overview.commit_count integer 是 否 提交次数

contributions[] 对象

字段 类型 必返 可为空 说明
contributions.date string 是 否 贡献日期
contributions.additions integer 是 否 当日新增行数
contributions.deletions integer 是 否 当日删除行数
contributions.total_changes integer 是 否 当日变更总数
contributions.commit_count integer 是 否 当日提交次数

失败响应

只有 200 成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数格式错误或缺少必填参数"
}

404 资源不存在

{
  "error": "not_found",
  "message": "仓库不存在或没有访问权限"
}

具体错误字段名以后端实际返回为准。

HTTP 响应状态码

状态码 说明
200 成功(OK)
304 未修改(Not modified)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 资源不存在(Not found)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path); <repo> 替换为仓库路径(path); <token> 替换为你的 AtomGit 用户访问令牌(可选,允许匿名访问时可不携带,也可携带令牌)。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contributors/statistic?author=<username>&since=2024-01-01&until=2024-12-31&current_user=false' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/contributors/statistic?author=<username>&since=2024-01-01&until=2024-12-31",
  {
    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>/contributors/statistic",
    params={
        "author": "<username>",
        "since": "2024-01-01",
        "until": "2024-12-31",
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

[
  {
    "name": "test",
    "email": "aa@ss.com",
    "overview": {
      "additions": 762,
      "deletions": 0,
      "total_changes": 762,
      "commit_count": 8
    },
    "contributions": [
      {
        "date": "2024-12-05",
        "additions": 759,
        "deletions": 0,
        "total_changes": 759,
        "commit_count": 5
      },
      {
        "date": "2024-12-08",
        "additions": 2,
        "deletions": 0,
        "total_changes": 2,
        "commit_count": 2
      },
      {
        "date": "2024-12-09",
        "additions": 1,
        "deletions": 0,
        "total_changes": 1,
        "commit_count": 1
      }
    ]
  }
]

错误码

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

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