根据类型搜索¶
GET /api/v5/search
按 type 指定的类型在全站范围内搜索,返回统一分页结构的结果列表;type 决定 content 中每个元素的结构(仓库、用户、组织、合并请求或 Issue)。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
type |
query | string | 是 | 搜索类型,枚举:repo、user、group、pullrequest、issue;大小写不敏感,取值不受支持时返回 400 |
q |
query | string | 否 | 搜索关键字;源码未做必填校验,可不传 |
repo_type |
query | string[] | 否 | 仓库类型:0 代码仓、1 模型仓、2 数据集仓;可传多个值 |
task |
query | string | 否 | 任务标签,如 text-generation;多个值用英文逗号隔开,仅模型仓搜索生效 |
library |
query | string | 否 | 框架库标签,如 transformers;多个值用英文逗号隔开,仅模型仓搜索生效 |
param.min |
query | string | 否 | 参数规模下限,如 1B;与 param.max 均不传时不带任何参数规模过滤 |
param.max |
query | string | 否 | 参数规模上限,如 7B |
s |
query | string | 否 | 排序字段,如 created_at、updated_at、star、fork;不传时按最佳匹配排序 |
o |
query | string | 否 | 排序顺序:asc 升序、desc 降序 |
p |
query | integer | 否 | 页码,默认 1 |
pp |
query | integer | 否 | 每页数量,默认 10 |
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
page_num |
integer | 是 | 否 | 当前页码 |
page_size |
integer | 是 | 否 | 每页返回条数 |
total |
integer | 是 | 否 | 命中的结果总数 |
page_count |
integer | 是 | 否 | 总页数,由 total 与 page_size 计算 |
content |
object[] | 是 | 否 | 搜索结果列表,元素结构随 type 变化,见下方各类型对象 |
所有类型共有的 content 元素字段
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].url |
string | 是 | 是 | 结果的页面地址 |
content[].created_at |
string | 是 | 是 | 创建时间,格式 yyyy-MM-dd HH:mm:ss(东八区) |
content[].updated_at |
string | 是 | 是 | 更新时间,格式 yyyy-MM-dd HH:mm:ss(东八区) |
type=repo 的 content 元素(仓库、模型仓、数据集仓、空间)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].id |
string | 是 | 是 | 仓库 id |
content[].name |
string | 是 | 是 | 仓库名称 |
content[].description |
string | 是 | 是 | 仓库描述 |
content[].project_type |
string | 是 | 是 | 项目类型:code / model / dataset / space / ugr |
content[].name_with_namespace |
string | 是 | 是 | 全路径名称,包含组织或个人名称 |
content[].path_with_namespace |
string | 是 | 是 | 全路径,包含组织或个人路径 |
content[].language |
string | 是 | 是 | 仓库语言 |
content[].show_recommend_icon |
boolean | 是 | 是 | 是否展示 GitHub 推荐图标 |
content[].import_star_count |
integer | 是 | 是 | 导入的镜像仓库星标数量 |
content[].namespace |
string | 是 | 是 | 仓库命名空间 |
content[].path |
string | 是 | 是 | 仓库 path |
content[].web_url |
string | 是 | 是 | 网络 URL |
content[].star_count |
integer | 是 | 是 | star 数量 |
content[].forks_count |
integer | 是 | 是 | Fork 数量 |
content[].default_branches |
string | 是 | 是 | 默认分支 |
content[].last_activity_at |
string | 是 | 是 | 最近活动时间 |
content[].main_language |
string | 是 | 是 | 主仓库语言 |
content[].license |
object | 是 | 是 | 仓库开源许可证信息,见下方 license 对象 |
content[].last_repository_updated_at |
string | 是 | 是 | 仓库最近更新时间 |
content[].repo_type |
string | 是 | 是 | 仓库类型:code / model / dataset / space |
content[].task |
object[] | 是 | 是 | 模型任务标签列表,见下方 task / library 元素 |
content[].library |
object[] | 是 | 是 | 模型框架标签列表,见下方 task / library 元素 |
content[].model_param_size |
string | 是 | 是 | 模型参数量 |
content[].archived |
boolean | 是 | 是 | 是否已归档 |
content[].avatar_url |
string | 是 | 是 | 项目头像 |
content[].visibility |
string | 是 | 是 | 可见性:public / private |
content[].creator |
object | 是 | 是 | 项目创建人,见下方 creator 对象 |
content[].license 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].license.key |
string | 是 | 是 | 许可证 key |
content[].license.name |
string | 是 | 是 | 许可证名称 |
content[].license.nickname |
string | 是 | 是 | 许可证别名 |
content[].license.html_url |
string | 是 | 是 | 许可证 HTML 链接 |
content[].license.source_url |
string | 是 | 是 | 许可证源码链接 |
content[].creator 对象¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].creator.id |
integer | 是 | 是 | 用户 id |
content[].creator.name |
string | 是 | 是 | 姓名 |
content[].creator.username |
string | 是 | 是 | 用户名 |
content[].creator.avatar_url |
string | 是 | 是 | 头像地址 |
content[].creator.web_url |
string | 是 | 是 | 用户主页地址 |
content[].creator.nick_name |
string | 是 | 是 | 昵称 |
content[].task / content[].library 元素¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].task[].code |
string | 是 | 是 | 标签编码 |
content[].task[].name |
string | 是 | 是 | 标签名称 |
Note: content[].library 的元素结构与 content[].task 完全一致,字段同为 code 与 name。
type=user 的 content 元素(用户)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].id |
string | 是 | 是 | 用户对象 id |
content[].username |
string | 是 | 是 | 用户名 |
content[].nickname |
string | 是 | 是 | 用户昵称 |
content[].avatar_url |
string | 是 | 是 | 头像地址 |
content[].description |
string | 是 | 是 | 用户简介 |
content[].location |
string | 是 | 是 | 所在地 |
type=group 的 content 元素(组织)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].id |
string | 是 | 是 | 组织 id |
content[].name |
string | 是 | 是 | 组织名称 |
content[].full_name |
string | 是 | 是 | 组织全名 |
content[].full_path |
string | 是 | 是 | 组织全路径 |
content[].description |
string | 是 | 是 | 组织描述 |
content[].avatar |
string | 是 | 是 | 组织头像 |
content[].visibility_level |
string | 是 | 是 | 可见性:public / private |
content[].follow_num |
integer | 是 | 是 | 关注数 |
content[].project_num |
integer | 是 | 是 | 项目数 |
content[].watch_num |
integer | 是 | 是 | Watch 数,仅强推组织返回 |
content[].fork_num |
integer | 是 | 是 | Fork 数,仅强推组织返回 |
content[].star_num |
integer | 是 | 是 | 星标数,仅强推组织返回 |
type=issue 的 content 元素(Issue)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].id |
string | 是 | 是 | Issue id |
content[].title |
string | 是 | 是 | Issue 标题 |
content[].description |
string | 是 | 是 | Issue 描述 |
content[].iid |
integer | 是 | 是 | 项目内 Issue 序号 |
content[].state |
string | 是 | 是 | 状态:opened / closed / rejected |
content[].author |
object | 是 | 是 | Issue 创建人,见下方 author 对象 |
content[].labels |
string[] | 是 | 是 | 标签列表 |
content[].path_with_namespace |
string | 是 | 是 | 项目全路径 |
content[].project_url |
string | 是 | 是 | 项目地址 |
content[].comment_num |
integer | 是 | 是 | 评论数 |
type=pullrequest 的 content 元素(合并请求)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].id |
string | 是 | 是 | PR id |
content[].iid |
integer | 是 | 是 | 项目内 PR 序号 |
content[].title |
string | 是 | 是 | PR 标题 |
content[].description |
string | 是 | 是 | PR 描述 |
content[].target_branch |
string | 是 | 是 | 目标分支 |
content[].source_branch |
string | 是 | 是 | 源分支 |
content[].comment_num |
integer | 是 | 是 | 评论数 |
content[].labels |
string[] | 是 | 是 | 标签列表 |
content[].state |
string | 是 | 是 | 状态:open / merged / closed |
content[].author |
object | 是 | 是 | PR 创建人,见下方 author 对象 |
content[].path_with_namespace |
string | 是 | 是 | 项目全路径 |
content[].project_url |
string | 是 | 是 | 项目地址 |
content[].author 对象(type=issue / type=pullrequest)¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
content[].author.id |
integer | 是 | 是 | 用户 id |
content[].author.name |
string | 是 | 是 | 姓名 |
content[].author.username |
string | 是 | 是 | 用户名 |
content[].author.avatar_url |
string | 是 | 是 | 头像地址 |
content[].author.web_url |
string | 是 | 是 | 用户主页地址 |
content[].author.nick_name |
string | 是 | 是 | 昵称 |
Note: 响应中的条目按白名单输出,只包含上表列出的字段;各 type 未使用的字段不会出现。
失败响应¶
type 取值不受支持(未命中 repo、user、group、pullrequest、issue)时,参数校验失败,由全局异常处理器返回 400:
400 参数错误
{
"error_code": 400,
"error_code_name": "PARAMETER_ERROR",
"error_message": "type 仅支持 repo、user、group、pullrequest、issue",
"trace_id": "0af7651916cd43dd8448eb211c80319c"
}
401 未认证
{
"error_code": 401,
"error_code_name": "UNAUTHORIZED",
"error_message": "缺少或无效的访问令牌",
"trace_id": "0af7651916cd43dd8448eb211c80319c"
}
该接口允许匿名访问,但若携带了无效的访问令牌,仍会返回 401。
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
400 |
参数错误(如 type 取值不受支持) |
401 |
未认证或凭证无效 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
请求示例¶
参数说明¶
示例按 type=repo 搜索,携带了必填参数 type。
<q>替换为要搜索的关键字,如vue;<token>替换为你的 AtomGit 用户访问令牌。该接口允许匿名访问,示例中不带认证头也能调用成功;若需要以特定用户身份搜索,可追加请求头Authorization: Bearer <token>。
cURL¶
curl -X GET 'https://api.atomgit.com/api/v5/search?type=repo&q=<q>&p=1&pp=10' \
-H 'Accept: application/json'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const params = new URLSearchParams({
type: "repo",
q: "<q>",
p: "1",
pp: "10",
});
const response = await fetch(`https://api.atomgit.com/api/v5/search?${params}`, {
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",
params={"type": "repo", "q": "<q>", "p": 1, "pp": 10},
headers={"Accept": "application/json"},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"page_num": 1,
"page_size": 10,
"total": 1,
"page_count": 1,
"content": [
{
"url": "https://api.atomgit.com/api/v5/repos/youlai/vue3-element-admin",
"created_at": "2024-11-07 18:11:23",
"updated_at": "2024-11-15 09:20:11",
"id": "3771502",
"name": "vue3-element-admin",
"description": "有来开源组织的 Vue3 后台管理框架",
"project_type": "code",
"name_with_namespace": "有来开源组织 / vue3-element-admin",
"path_with_namespace": "youlai/vue3-element-admin",
"language": "Vue",
"show_recommend_icon": false,
"import_star_count": 0,
"namespace": "youlai",
"path": "vue3-element-admin",
"web_url": "https://api.atomgit.com/youlai/vue3-element-admin",
"star_count": 128,
"forks_count": 32,
"default_branches": "master",
"last_activity_at": "2024-11-15 09:20:11",
"main_language": "Vue",
"license": {
"key": "mit",
"name": "MIT License",
"nickname": "MIT",
"html_url": "https://api.atomgit.com/youlai/vue3-element-admin/blob/master/LICENSE",
"source_url": "https://opensource.org/licenses/MIT"
},
"last_repository_updated_at": "2024-11-15 09:20:11",
"repo_type": "code",
"task": [],
"library": [],
"model_param_size": null,
"archived": false,
"avatar_url": "https://api.atomgit.com/avatar.png",
"visibility": "public",
"creator": {
"id": 6553,
"name": "有来技术",
"username": "youlai",
"avatar_url": "https://api.atomgit.com/avatar.png",
"web_url": "https://api.atomgit.com/youlai",
"nick_name": "有来技术"
}
}
]
}
错误码¶
| 错误码 | 说明 |
|---|---|
400 |
参数错误,如 type 取值不受支持,或参数类型错误 |
401 |
未认证或凭证无效(携带了无效的访问令牌) |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc