feat(comments): add pagination support to comment list API and CLI

Add --limit, --offset, and --since flags to `multica issue comment list`
to prevent context window overflow when issues have many comments.

The API endpoint now accepts limit, offset, and since (RFC3339) query
parameters. When paginating, the response includes an X-Total-Count
header with the total number of comments.
This commit is contained in:
Jiayuan 2026-04-03 23:53:00 +08:00
parent fc6405e4be
commit 0bbc6bc1c5
4 changed files with 286 additions and 5 deletions

View file

@ -162,6 +162,9 @@ func init() {
// issue comment list
issueCommentListCmd.Flags().String("output", "table", "Output format: table or json")
issueCommentListCmd.Flags().Int("limit", 0, "Maximum number of comments to return (0 = all)")
issueCommentListCmd.Flags().Int("offset", 0, "Number of comments to skip")
issueCommentListCmd.Flags().String("since", "", "Only return comments created after this timestamp (RFC3339)")
// issue runs
issueRunsCmd.Flags().String("output", "table", "Output format: table or json")
@ -536,8 +539,24 @@ func runIssueCommentList(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
params := url.Values{}
if v, _ := cmd.Flags().GetInt("limit"); v > 0 {
params.Set("limit", fmt.Sprintf("%d", v))
}
if v, _ := cmd.Flags().GetInt("offset"); v > 0 {
params.Set("offset", fmt.Sprintf("%d", v))
}
if v, _ := cmd.Flags().GetString("since"); v != "" {
params.Set("since", v)
}
path := "/api/issues/" + args[0] + "/comments"
if len(params) > 0 {
path += "?" + params.Encode()
}
var comments []map[string]any
if err := client.GetJSON(ctx, "/api/issues/"+args[0]+"/comments", &comments); err != nil {
if err := client.GetJSON(ctx, path, &comments); err != nil {
return fmt.Errorf("list comments: %w", err)
}