跳转至

列出授权用户 watch 了的仓库

GET /api/v5/user/subscriptions

用户调用此接口,进行列出授权用户 watch 了的仓库操作。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
access_token query string 是 用户授权码
sort query string 否 排序方式,取值 created(按仓库创建时间)或 last_push(按最后推送时间),默认按创建时间排序
direction query string 否 排序方向,取值 asc / desc,默认降序
page query integer 否 当前的页码
per_page query integer 否 每页的数量,最大为 100,默认 20

响应参数

响应体为仓库(repository)对象数组,每个数组元素的结构如下:

repository 对象

字段 类型 必返 可为空 说明
id integer 是 否 仓库 Id
full_name string 是 否 仓库全路径
human_name string 是 否 仓库全名称
url string 是 否 仓库详情访问地址
namespace object 是 否 仓库所属命名空间
path string 是 否 仓库路径
name string 是 否 仓库名称
parentfull_name string 是 是 父仓库名称
description string 是 是 仓库描述
status string 是 是 仓库状态,0:开始(表示仓库未归档),2:关闭(表示仓库已归档)
ssh_url_to_repo string 是 否 仓库 SSH git 地址
http_url_to_repo string 是 否 仓库 HTTP git 地址
web_url string 是 否 仓库 Web 访问地址
created_at string 是 否 创建时间
updated_at string 是 否 更新时间
homepage string 是 是 仓库主页
members string[] 是 是 仓库成员列表
parent object 是 是 父仓库信息
forks_count integer 是 否 fork 数量
stargazers_count integer 是 否 star 数量
relation string 是 是 当前用户相对于仓库的角色
permission object 是 否 当前用户对仓库的权限
internal integer 是 否 是否内部开源
open_issues_count integer 是 否 开启的 issue 数量
has_issue integer 是 否 是否有 issue
has_issues integer 是 否 是否开启 issue 功能
watchers_count integer 是 否 watch 数量
enterprise object 是 是 所属企业信息
default_branch string 是 否 默认分支
fork integer 是 否 是否 fork 仓库
pushed_at string 是 是 最近一次代码推送时间
owner object 是 否 仓库创建者信息
issue_template_source string 是 是 Issue 模板来源,取值 project(使用仓库 Issue Template 作为模板)或 enterprise(使用企业工作项作为模板)
project_creator string 是 是 仓库创建人
private integer 是 否 是否私有仓库
public integer 是 否 是否公开仓库

repository.namespace 对象

字段 类型 必返 可为空 说明
namespace.id integer 是 否 命名空间 Id
namespace.type string 是 否 命名空间类型
namespace.name string 是 否 命名空间名称
namespace.path string 是 否 命名空间路径
namespace.html_url string 是 否 命名空间访问地址

repository.parent 对象

字段 类型 必返 可为空 说明
parent.full_name string 是 否 父仓库全路径
parent.human_name string 是 否 父仓库全名称

repository.permission 对象

字段 类型 必返 可为空 说明
permission.pull integer 是 否 是否具有 pull 权限
permission.push integer 是 否 是否具有 push 权限
permission.admin integer 是 否 是否具有 admin 权限

repository.enterprise 对象

字段 类型 必返 可为空 说明
enterprise.id integer 是 否 企业 Id
enterprise.path string 是 否 企业路径
enterprise.html_url string 是 否 企业访问地址
enterprise.type string 是 否 企业类型

repository.owner 对象

字段 类型 必返 可为空 说明
owner.id string 是 否 创建者 Id
owner.login string 是 否 创建者登录名
owner.name string 是 否 创建者姓名
owner.type string 是 否 创建者类型

失败响应

认证失败(401)与参数错误(400)时,后端返回错误信息,错误字段名以后端实际返回为准。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数错误"
}

401 未认证

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

HTTP 响应状态码

状态码 说明
200 成功(OK)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)

请求示例

参数说明

示例通过查询参数 access_token 进行认证;<token> 替换为你的 AtomGit 用户访问令牌。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/user/subscriptions?access_token=<token>&sort=created&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/user/subscriptions?access_token=<YOUR-TOKEN>&sort=created&direction=desc&page=1&per_page=20", {
  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/user/subscriptions",
    params={
        "access_token": "<YOUR-TOKEN>",
        "sort": "created",
        "direction": "desc",
        "page": 1,
        "per_page": 20,
    },
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

[
  {
    "id": 777621,
    "full_name": "xiaogang/private-new2",
    "human_name": "xiaogang / private-new2",
    "url": "https://api.atomgit.com/api/v5/repos/xiaogang/private-new2",
    "namespace": {
      "id": 137117,
      "type": "user",
      "name": "xiaogang",
      "path": "xiaogang",
      "html_url": "https://api.atomgit.com/xiaogang"
    },
    "path": "private-new2",
    "name": "private-new2",
    "parentfull_name": "xiaogang_test/private-new",
    "description": "特朗普",
    "status": "开始",
    "ssh_url_to_repo": "ssh://git@atomgit.com:2222/xiaogang/private-new2.git",
    "http_url_to_repo": "https://api.atomgit.com/xiaogang/private-new2.git",
    "web_url": "https://api.atomgit.com/xiaogang/private-new2",
    "created_at": "2024-12-11T17:41:14.536+08:00",
    "updated_at": "2024-12-11T17:41:14.536+08:00",
    "homepage": "https://api.atomgit.com/xiaogang/private-new2",
    "members": ["xiaogang"],
    "parent": {
      "full_name": "xiaogang_test/private-new",
      "human_name": "xiaogang_test / private-new"
    },
    "forks_count": 0,
    "stargazers_count": 1,
    "relation": "master",
    "permission": {
      "pull": true,
      "push": true,
      "admin": true
    },
    "internal": false,
    "open_issues_count": 0,
    "has_issue": false,
    "has_issues": false,
    "watchers_count": 0,
    "enterprise": {
      "id": 137117,
      "path": "xiaogang",
      "html_url": "https://api.atomgit.com/xiaogang",
      "type": "user"
    },
    "default_branch": "main",
    "fork": true,
    "pushed_at": "2024-12-20T19:14:34.979+08:00",
    "owner": {
      "id": "496",
      "login": "xiaogang",
      "name": "肖刚",
      "type": "User"
    },
    "issue_template_source": "project",
    "project_creator": "xiaogang",
    "private": false,
    "public": true
  }
]

错误码

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

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