Closed
feat(discussions): 支持 获取项目讨论列表 API #467
aflyingtoAdd on Jul 13Closed at Aug 8
aflyingto
Aug 8 Comments:
Aug 8 Comments:
验证记录(#467 + #468 项目讨论 list/detail)
- 当前验证分支:
main(HEAD6a61458) - 验证方式:按 §9/§5.9.B 查
gc-api-doc确认官方端点;CLI 当前 discussions 仅有组织级(#463/#464 已合入),无项目级命令
gc-api-doc 确认的端点
| issue | method | path | params |
|---|---|---|---|
| #467 list | GET | /api/v5/repos/{owner}/{repo}/discuss |
page, per_page, sort(created/comment_size), direction(asc/desc), search |
| #468 detail | GET | /api/v5/repos/{owner}/{repo}/discuss/{number} |
number |
- response 200:list=array,detail=object
- 字段与组织讨论完全一致(id/number/title/created_at/updated_at/author/is_*/comment_total/category/namespace/labels;detail 额外 md_content/vote/vote_options)→ 复用已合入的
Discussion结构,仅新增 api 函数(path 改/repos/{owner}/{repo}/discuss)
实现方案
api/queries_discussions.go:新增ListRepoDiscussions/GetRepoDiscussion(复用Discussion结构)pkg/cmd/discussions/project/:project子命令组 +list/view(-R owner/reporepo 级 +--json+ 分页/排序/搜索 + 404→exit3 + number<1 守卫)- 注册到 discussions 父命令;单测 + infra-test 实测 + docs 同步


背景
GitCode API 文档已提供 Discussions 页面相关 API,但 gitcode-cli 当前尚未适配。该 Issue 用于跟踪 CLI 对此接口的需求、设计与实现。
API 摘要
GET/api/v5/repos/{owner}/{repo}/discussget_api_v5_repos_{owner}_{repo}_discussRepositories,RepositoriesfalseRequest Parameters
ownerrepoaccess_tokenpageper_pagesortdirectionsearchRequest Body
无。
Responses
200
application/jsonapplication/json schema
{ "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "number": { "type": "integer" }, "title": { "type": "string" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" }, "author": { "type": "object", "properties": { "avatar_url": { "type": "string" }, "id": { "type": "string" }, "object_id": { "type": "string" }, "login": { "type": "string" }, "name": { "type": "string" } }, "required": [ "avatar_url", "id", "object_id", "login", "name" ] }, "is_lock": { "type": "integer", "description": "是否锁定" }, "is_pin": { "type": "integer", "description": "是否置顶" }, "is_category_pin": { "type": "integer", "description": "是否类型下置顶" }, "is_closed": { "type": "integer", "description": "是否关闭" }, "is_answered": { "type": "integer", "description": "是否采纳答案" }, "comment_total": { "type": "integer", "description": "评论数量" }, "category": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "icon": { "type": "string" }, "description": { "type": "string" }, "type": { "type": "integer" } }, "required": [ "id", "name", "icon", "description", "type" ] }, "namespace": { "type": "object", "properties": { "id": { "type": "integer" }, "kind": { "type": "string" }, "full_path": { "type": "string" } }, "required": [ "id", "kind", "full_path" ] }, "labels": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "color": { "type": "string" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" } }, "required": [ "id", "name", "color", "created_at", "updated_at" ] }, "description": "标签" } }, "required": [ "id", "number", "title", "created_at", "updated_at", "author", "is_lock", "is_pin", "is_category_pin", "is_closed", "is_answered", "comment_total", "category", "namespace", "labels" ] } }原始 OpenAPI Operation
{ "deprecated": false, "description": "", "operationId": "get_api_v5_repos_{owner}_{repo}_discuss", "tags": [ "Repositories", "Repositories" ], "parameters": [ { "name": "owner", "in": "path", "description": "仓库所属空间地址(企业、组织或个人的地址path)", "required": true, "example": "", "schema": { "type": "string" } }, { "name": "repo", "in": "path", "description": "仓库路径(path)", "required": true, "example": "", "schema": { "type": "string" } }, { "name": "access_token", "in": "query", "description": "用户授权码", "required": false, "example": "", "schema": { "type": "string" } }, { "name": "page", "in": "query", "description": "当前的页码", "required": false, "schema": { "type": "string" } }, { "name": "per_page", "in": "query", "description": "每页的数量,最大为 100,默认 20", "required": false, "schema": { "type": "string" } }, { "name": "sort", "in": "query", "description": "可选。排序字段 created(创建时间), comment_size(评论数量),默认创建时间", "required": false, "schema": { "type": "string" } }, { "name": "direction", "in": "query", "description": "可选。升序/降序(asc/desc),默认降序", "required": false, "schema": { "type": "string" } }, { "name": "search", "in": "query", "description": "根据标题和描述搜索", "required": false, "schema": { "type": "string" } } ], "responses": { "200": { "description": "成功响应", "content": { "application/json": { "schema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "number": { "type": "integer" }, "title": { "type": "string" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" }, "author": { "type": "object", "properties": { "avatar_url": { "type": "string" }, "id": { "type": "string" }, "object_id": { "type": "string" }, "login": { "type": "string" }, "name": { "type": "string" } }, "required": [ "avatar_url", "id", "object_id", "login", "name" ] }, "is_lock": { "type": "integer", "description": "是否锁定" }, "is_pin": { "type": "integer", "description": "是否置顶" }, "is_category_pin": { "type": "integer", "description": "是否类型下置顶" }, "is_closed": { "type": "integer", "description": "是否关闭" }, "is_answered": { "type": "integer", "description": "是否采纳答案" }, "comment_total": { "type": "integer", "description": "评论数量" }, "category": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "icon": { "type": "string" }, "description": { "type": "string" }, "type": { "type": "integer" } }, "required": [ "id", "name", "icon", "description", "type" ] }, "namespace": { "type": "object", "properties": { "id": { "type": "integer" }, "kind": { "type": "string" }, "full_path": { "type": "string" } }, "required": [ "id", "kind", "full_path" ] }, "labels": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "color": { "type": "string" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" } }, "required": [ "id", "name", "color", "created_at", "updated_at" ] }, "description": "标签" } }, "required": [ "id", "number", "title", "created_at", "updated_at", "author", "is_lock", "is_pin", "is_category_pin", "is_closed", "is_answered", "comment_total", "category", "namespace", "labels" ] } } } }, "headers": {} } }, "security": [], "method": "get", "path": "/api/v5/repos/{owner}/{repo}/discuss", "servers": [ { "url": "https://api.gitcode.com", "description": "正式环境" } ], "securitySchemes": {}, "info": { "title": "GicodeOpenAPI", "description": "", "version": "1.0.0" }, "postman": { "name": "获取项目讨论列表", "description": { "content": "", "type": "text/plain" }, "url": { "path": [ "api", "v5", "repos", ":owner", ":repo", "discuss" ], "host": [ "{{baseUrl}}" ], "query": [ { "disabled": false, "description": { "content": "用户授权码", "type": "text/plain" }, "key": "access_token", "value": "" }, { "disabled": false, "description": { "content": "当前的页码", "type": "text/plain" }, "key": "page", "value": "" }, { "disabled": false, "description": { "content": "每页的数量,最大为 100,默认 20", "type": "text/plain" }, "key": "per_page", "value": "" }, { "disabled": false, "description": { "content": "可选。排序字段 created(创建时间), comment_size(评论数量),默认创建时间", "type": "text/plain" }, "key": "sort", "value": "" }, { "disabled": false, "description": { "content": "可选。升序/降序(asc/desc),默认降序", "type": "text/plain" }, "key": "direction", "value": "" }, { "disabled": false, "description": { "content": "根据标题和描述搜索", "type": "text/plain" }, "key": "search", "value": "" } ], "variable": [ { "disabled": false, "description": { "content": "(Required) 仓库所属空间地址(企业、组织或个人的地址path)", "type": "text/plain" }, "type": "any", "value": "", "key": "owner" }, { "disabled": false, "description": { "content": "(Required) 仓库路径(path)", "type": "text/plain" }, "type": "any", "value": "", "key": "repo" } ] }, "header": [ { "key": "Accept", "value": "application/json" } ], "method": "GET" } }初步验收建议
infra-test/*仓库。access_token仅作为 API 参数记录,CLI 优先复用现有认证机制。