Closed
feat(discussions): 支持 获取项目讨论列表 API #467
aflyingtoAdd on  Jul 13Closed at  Aug 8
aflyingtoCollaborators
Jul 13 Create

背景

GitCode API 文档已提供 Discussions 页面相关 API,但 gitcode-cli 当前尚未适配。该 Issue 用于跟踪 CLI 对此接口的需求、设计与实现。

API 摘要

  • 标题: 获取项目讨论列表
  • Method: GET
  • Path: /api/v5/repos/{owner}/{repo}/discuss
  • Operation ID: get_api_v5_repos_{owner}_{repo}_discuss
  • Tags: Repositories, Repositories
  • Deprecated: false
  • Description: 无

Request Parameters

Name In Required Type Description
owner path yes string 仓库所属空间地址(企业、组织或个人的地址path)
repo path yes string 仓库路径(path)
access_token query no string 用户授权码
page query no string 当前的页码
per_page query no string 每页的数量,最大为 100,默认 20
sort query no string 可选。排序字段 created(创建时间), comment_size(评论数量),默认创建时间
direction query no string 可选。升序/降序(asc/desc),默认降序
search query no string 根据标题和描述搜索

Request Body

无。

Responses

200

  • Description: 成功响应
  • Headers: 无
  • Content-Types: application/json

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"
    ]
  }
}

原始 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"
  }
}

初步验收建议

  • 增加对应 API client/query 方法。
  • 建议设计项目级 discussion 读取命令,并支持 -R owner/repo。
  • 设计 agent-friendly 的 CLI 命令、帮助文本、JSON 输出和错误处理。
  • 单元测试覆盖参数映射、响应解析和错误路径。
  • 如做真实命令验证,只能使用 infra-test/* 仓库。
  • 不暴露或打印 token;文档中的 access_token 仅作为 API 参数记录,CLI 优先复用现有认证机制。
likedislike
AaflyingtoCollaborators
Jul 13 Added label: risk/mediumscope/apiscope/discussions, status/triage,type/feature
AaflyingtoCollaborators
Jul 13 Associated milestone: Discussions M1: 页面只读 API 适配
aflyingtoCollaborators
Aug 8 Comments:

验证记录(#467 + #468 项目讨论 list/detail)

  • 当前验证分支:main(HEAD 6a61458)
  • 验证方式:按 §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/repo repo 级 + --json + 分页/排序/搜索 + 404→exit3 + number<1 守卫)
  • 注册到 discussions 父命令;单测 + infra-test 实测 + docs 同步
likedislike
AaflyingtoCollaborators
Aug 8 Added label: status/in-progress, status/verified
AaflyingtoCollaborators
Aug 8 Associated pull request
AaflyingtoCollaborators
Aug 8 Close issue