已关闭
feat(discussions): 支持 获取组织讨论评论列表 API #465
aflyingto创建于  7月13日关闭于  8月8日
aflyingto成员
7月13日 创建

背景

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

API 摘要

  • 标题: 获取组织讨论评论列表
  • Method: GET
  • Path: /api/v5/orgs/{org}/discuss/{number}/comment
  • Operation ID: get_api_v5_orgs_{org}_discuss_{number}_comment
  • Tags: Organizations, Repositories
  • Deprecated: false
  • Description: 无

Request Parameters

Name In Required Type Description
org path yes string 组织的path
number path yes string 讨论的编号
access_token query no string 用户授权码
page query no string 当前的页码
per_page query no string 每页的数量,最大为 100,默认 20
order query no string 排序,按创建时间升序(time_asc);按创建时间降序(time_desc),按热度值降序(hot_desc)

Request Body

无。

Responses

200

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

application/json schema

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "created_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"
        ]
      },
      "content": {
        "type": "string"
      },
      "md_content": {
        "type": "string"
      },
      "is_hide": {
        "type": "integer"
      },
      "reply_total": {
        "type": "integer"
      },
      "like_total": {
        "type": "integer"
      },
      "is_like": {
        "type": "boolean"
      },
      "is_deleted": {
        "type": "integer"
      },
      "is_remark": {
        "type": "integer"
      }
    }
  }
}

原始 OpenAPI Operation

{
  "deprecated": false,
  "description": "",
  "operationId": "get_api_v5_orgs_{org}_discuss_{number}_comment",
  "tags": [
    "Organizations",
    "Repositories"
  ],
  "parameters": [
    {
      "name": "org",
      "in": "path",
      "description": "组织的path",
      "required": true,
      "schema": {
        "type": "string"
      }
    },
    {
      "name": "number",
      "in": "path",
      "description": "讨论的编号",
      "required": true,
      "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": "order",
      "in": "query",
      "description": "排序,按创建时间升序(time_asc);按创建时间降序(time_desc),按热度值降序(hot_desc)",
      "required": false,
      "schema": {
        "type": "string"
      }
    }
  ],
  "responses": {
    "200": {
      "description": "成功响应",
      "content": {
        "application/json": {
          "schema": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "created_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"
                  ]
                },
                "content": {
                  "type": "string"
                },
                "md_content": {
                  "type": "string"
                },
                "is_hide": {
                  "type": "integer"
                },
                "reply_total": {
                  "type": "integer"
                },
                "like_total": {
                  "type": "integer"
                },
                "is_like": {
                  "type": "boolean"
                },
                "is_deleted": {
                  "type": "integer"
                },
                "is_remark": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "headers": {}
    }
  },
  "security": [],
  "method": "get",
  "path": "/api/v5/orgs/{org}/discuss/{number}/comment",
  "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",
        "orgs",
        ":org",
        "discuss",
        ":number",
        "comment"
      ],
      "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": "排序,按创建时间升序(time_asc);按创建时间降序(time_desc),按热度值降序(hot_desc)",
            "type": "text/plain"
          },
          "key": "order",
          "value": ""
        }
      ],
      "variable": [
        {
          "disabled": false,
          "description": {
            "content": "(Required) 组织的path",
            "type": "text/plain"
          },
          "type": "any",
          "value": "",
          "key": "org"
        },
        {
          "disabled": false,
          "description": {
            "content": "(Required) 讨论的编号",
            "type": "text/plain"
          },
          "type": "any",
          "value": "",
          "key": "number"
        }
      ]
    },
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "method": "GET"
  }
}

初步验收建议

  • 增加对应 API client/query 方法。
  • 建议设计组织级 discussion 读取命令,或在 discussions 命令中支持 --org。
  • 设计 agent-friendly 的 CLI 命令、帮助文本、JSON 输出和错误处理。
  • 单元测试覆盖参数映射、响应解析和错误路径。
  • 如做真实命令验证,只能使用 infra-test/* 仓库。
  • 不暴露或打印 token;文档中的 access_token 仅作为 API 参数记录,CLI 优先复用现有认证机制。
likedislike
Aaflyingto成员
7月13日 添加了label:risk/mediumscope/apiscope/discussions, status/triage,type/feature
Aaflyingto成员
7月13日 关联了里程碑:Discussions M1: 页面只读 API 适配
aflyingto成员
8月8日 评论:

验证记录(#465/#466/#469/#470 讨论评论 + 回复)

  • 当前验证分支:main(HEAD 7cfee80)
  • 验证方式:按 §9/§5.9.B 查 gc-api-doc 确认 4 端点;CLI 当前 discussions 仅有 list/view(#463/#464/#467/#468 已合入),无 comments/replies 命令

gc-api-doc 确认的端点

issue method path params
#465 org 评论 GET /api/v5/orgs/{org}/discuss/{number}/comment page, per_page, order(time_asc/time_desc/hot_desc)
#466 org 回复 GET /api/v5/orgs/{org}/discuss/{number}/comment/{comment_id}/reply page, per_page
#469 项目评论 GET /api/v5/repos/{owner}/{repo}/discuss/{number}/comment page, per_page, order
#470 项目回复 GET /api/v5/repos/{owner}/{repo}/discuss/{number}/comment/{comment_id}/reply page, per_page
  • response 200:均为 array;评论与回复 schema 完全一致
  • 字段:id(string), created_at(string), author(object, 同讨论 author), content(string), md_content(string), is_hide(int), reply_total(int), like_total(int), is_like(bool), is_deleted(int), is_remark(int)
  • 项目端点 schema 与组织一致(仅 path 不同)→ 复用 DiscussionComment 结构

实现方案

  • api/queries_discussions.go:新增 DiscussionComment 结构 + 4 个 api 函数(ListOrg/RepoDiscussionComments + ListOrg/RepoDiscussionCommentReplies,复用 opts)
  • pkg/cmd/discussions/comments/:comments 子命令组(org scope:list/replies,--org)+ 共享 PrintComments
  • pkg/cmd/discussions/project/comments/:project comments 子命令组(list/replies,-R,复用 PrintComments)
  • 注册 + 单测 + infra-test/gitcode-cli 实测 + docs
likedislike
Aaflyingto成员
8月8日 添加了label:status/in-progress, status/verified
Aaflyingto成员
8月8日 关联了pull request:feat(discussions): discussion comments + replies (org+project) (#465,#466,#469,#470)
Aaflyingto成员
8月8日 关闭了 issue