mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-26 02:03:30 +02:00
feat(pulls): add resolve, unresolve and review-comments subcommands (#948)
## Summary - Add `tea pulls review-comments <pull-index>` subcommand to list PR review comments with configurable fields (supports table/json/csv/yaml output) - Add `tea pulls resolve <comment-id>` subcommand to mark a review comment as resolved - Add `tea pulls unresolve <comment-id>` subcommand to unmark a review comment as resolved - Follow existing approve/reject pattern with shared `runResolveComment` helper in `review_helpers.go` ## Usage ```bash # List review comments for PR #42 tea pulls review-comments 42 # Resolve comment #789 tea pulls resolve 789 # Unresolve comment #789 tea pulls unresolve 789 # Custom output fields tea pulls review-comments 42 --fields id,path,body,resolver --output json ``` ## New Files | File | Description | |------|-------------| | `cmd/pulls/review_comments.go` | `review-comments` subcommand | | `cmd/pulls/resolve.go` | `resolve` subcommand | | `cmd/pulls/unresolve.go` | `unresolve` subcommand | | `modules/task/pull_review_comment.go` | Task layer: list, resolve, unresolve via SDK | | `modules/print/pull_review_comment.go` | Print formatting with `printable` interface | ## Modified Files | File | Description | |------|-------------| | `cmd/pulls.go` | Register 3 new commands | | `cmd/pulls/review_helpers.go` | Add shared `runResolveComment` helper | ## Test Plan - [x] `go build ./...` passes - [x] `go vet ./...` passes - [x] `tea pulls review-comments <PR-index>` lists comments with IDs - [x] `tea pulls resolve <comment-id>` resolves successfully - [x] `tea pulls unresolve <comment-id>` unresolves successfully - [x] `--output json` produces valid JSON output Reviewed-on: https://gitea.com/gitea/tea/pulls/948 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com> Co-committed-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
63
cmd/pulls/review_comments.go
Normal file
63
cmd/pulls/review_comments.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
var reviewCommentFieldsFlag = flags.FieldsFlag(print.PullReviewCommentFields, []string{
|
||||
"id", "path", "line", "body", "reviewer", "resolver",
|
||||
})
|
||||
|
||||
// CmdPullsReviewComments lists review comments on a pull request
|
||||
var CmdPullsReviewComments = cli.Command{
|
||||
Name: "review-comments",
|
||||
Aliases: []string{"rc"},
|
||||
Usage: "List review comments on a pull request",
|
||||
Description: "List review comments on a pull request",
|
||||
ArgsUsage: "<pull index>",
|
||||
Action: runPullsReviewComments,
|
||||
Flags: append([]cli.Flag{reviewCommentFieldsFlag}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPullsReviewComments(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Args().Len() < 1 {
|
||||
return fmt.Errorf("pull request index is required")
|
||||
}
|
||||
|
||||
idx, err := utils.ArgToIndex(ctx.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
comments, err := task.ListPullReviewComments(ctx, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fields, err := reviewCommentFieldsFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return print.PullReviewCommentsList(comments, ctx.Output, fields)
|
||||
}
|
||||
Reference in New Issue
Block a user