跳转至

搜索仓库

GET /api/v5/search/repositories

用户调用此接口,搜索平台上的仓库。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
access_token query string 是 用户授权码
q query string 是 搜索关键字
page query integer 否 当前页码,最大为 100,默认 1
per_page query integer 否 每页的数量,最大为 50,默认 30
sort query string 否 排序字段,枚举:last_push_at(更新时间)、stars_count(收藏数)、forks_count(Fork 数)、watches_count(关注数),默认为最佳匹配
order query string 否 排序顺序(如 asc / desc),默认 desc
owner query string 否 仓库所属空间地址(企业、组织或个人的地址 path)
fork query boolean 否 是否搜索含 fork 的仓库,默认 false
language query string 否 筛选指定语言的仓库

响应参数

响应体为一个仓库对象数组,每个数组元素的结构如下表所示。

字段 类型 必返 可为空 说明
id integer 是 否 仓库 ID
full_name string 是 否 仓库完整名称(如 gh_mirrors/al/allure2)
human_name string 否 是 人类可读名称
url string 是 否 仓库 API URL
namespace object 是 否 命名空间信息
path string 是 否 仓库路径
name string 是 否 仓库名称
description string 否 是 仓库描述
status string 是 否 仓库状态
ssh_url_to_repo string 是 否 SSH 克隆地址
http_url_to_repo string 是 否 HTTP 克隆地址
web_url string 是 否 仓库网页地址
created_at string 是 否 创建时间
updated_at string 是 否 更新时间
homepage string 否 是 主页地址
members string[] 否 是 成员列表
forks_count integer 是 否 Fork 数目
stargazers_count integer 是 否 Star 数目
relation string 否 是 关联信息
permission object 是 否 当前用户对该仓库的权限
internal boolean 是 否 是否为内部仓库
open_issues_count integer 是 否 打开的 Issue 数目
has_issue boolean 是 否 是否存在 Issue
watchers_count integer 是 否 关注(Watch)数目
enterprise object 否 是 所属企业信息,非企业仓库为 null
default_branch string 是 否 默认分支
fork boolean 是 否 是否为 Fork 仓库
pushed_at string 是 否 最近推送时间
owner object 是 否 仓库所有者信息
issue_template_source string 否 是 Issue 模板来源
private boolean 是 否 是否私有
public boolean 是 否 是否公开
has_wiki boolean 否 是 是否存在 wiki
language string 否 是 仓库主语言
license string 否 是 开源许可证
watched boolean 否 是 当前用户是否已关注
recommend boolean 否 是 是否推荐仓库
repo_type string 否 是 仓库类型:code(代码仓)、model(模型仓)、dataset(数据集仓)、space(Space)

namespace 对象

字段 类型 必返 可为空 说明
namespace.id integer 是 否 命名空间 ID
namespace.type string 是 否 命名空间类型(如 enterprise / user)
namespace.name string 是 否 命名空间名称
namespace.path string 是 否 命名空间路径
namespace.html_url string 是 否 命名空间网页地址
namespace.full_name string 否 是 命名空间全名
namespace.full_path string 否 是 命名空间全路径

permission 对象

字段 类型 必返 可为空 说明
permission.pull boolean 否 是 是否有拉取(pull)权限
permission.push boolean 是 否 是否有推送(push)权限
permission.admin boolean 否 是 是否有管理员(admin)权限

enterprise 对象

字段 类型 必返 可为空 说明
enterprise.id integer 是 否 企业 ID
enterprise.path string 是 否 企业路径
enterprise.name string 是 否 企业名称
enterprise.url string 否 是 企业 URL
enterprise.avatar_url string 否 是 企业头像地址
enterprise.html_url string 是 否 企业网页地址
enterprise.type string 是 否 企业类型

owner 对象

字段 类型 必返 可为空 说明
owner.id string 是 否 所有者 ID
owner.login string 是 否 登录名
owner.name string 是 否 所有者名称
owner.avatar_url string 否 是 头像地址
owner.html_url string 否 是 个人/组织网页地址
owner.type string 是 否 类型(如 User)
owner.url string 否 是 用户 API URL
owner.objectId string 否 是 对象 ID
owner.email string 否 是 邮箱

失败响应

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

400 参数错误

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

401 未认证

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

说明:错误响应的字段名以后端实际返回为准。

HTTP 响应状态码

状态码 说明
200 成功(OK)
304 未修改(Not modified)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 请求路径不存在
429 请求过于频繁,触发限流
500 系统内部错误

请求示例

参数说明

<q> 替换为搜索关键字(必填);<token> 替换为你的 AtomGit 用户访问令牌;<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path)。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/search/repositories?q=<q>&access_token=<token>' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const params = new URLSearchParams({
  q: "<q>",
  access_token: "<token>",
});

const response = await fetch(`https://api.atomgit.com/api/v5/search/repositories?${params.toString()}`, {
  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/search/repositories",
    params={
        "q": "<q>",
        "access_token": "<token>",
    },
    headers={
        "Accept": "application/json",
    },
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

[
  {
    "id": 1431191,
    "full_name": "gh_mirrors/al/allure2",
    "human_name": "GitHub 加速计划 / al / allure2",
    "url": "https://api.atomgit.com/api/v5/repos/gh_mirrors/al/allure2",
    "namespace": {
      "id": 2192652,
      "type": "enterprise",
      "name": "al",
      "path": "al",
      "html_url": "https://api.atomgit.com/al"
    },
    "path": "allure2",
    "name": "allure2",
    "description": "Allure Report is a flexible, lightweight multi-language test reporting tool. It provides clear graphical reports.",
    "status": "开始",
    "ssh_url_to_repo": "git@atomgit.com:gh_mirrors/al/allure2.git",
    "http_url_to_repo": "https://api.atomgit.com/gh_mirrors/al/allure2.git",
    "web_url": "https://api.atomgit.com/gh_mirrors/al/allure2",
    "created_at": "2023-12-18T00:42:15.557+08:00",
    "updated_at": "2024-11-05T10:54:59.948+08:00",
    "homepage": "https://api.atomgit.com/gh_mirrors/al/allure2",
    "members": ["Gitcode-Assistant", "coco_gitcode", "gitshumei"],
    "forks_count": 0,
    "stargazers_count": 9,
    "relation": "",
    "permission": {
      "push": false
    },
    "internal": false,
    "open_issues_count": 0,
    "has_issue": false,
    "watchers_count": 4,
    "enterprise": {
      "id": 2192652,
      "path": "al",
      "html_url": "https://api.atomgit.com/al",
      "type": "enterprise"
    },
    "default_branch": "main",
    "fork": false,
    "pushed_at": "2024-08-06T23:34:38.476+08:00",
    "owner": {
      "id": "69090",
      "login": "coco_gitcode",
      "name": "GitCode优质项目",
      "type": "User"
    },
    "issue_template_source": "project",
    "private": false,
    "public": true
  }
]

错误码

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

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