mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-09 10:45:04 +02:00
## 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>
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package print
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
)
|
|
|
|
// PullReviewCommentFields are all available fields to print with PullReviewCommentsList()
|
|
var PullReviewCommentFields = []string{
|
|
"id",
|
|
"body",
|
|
"reviewer",
|
|
"path",
|
|
"line",
|
|
"resolver",
|
|
"created",
|
|
"updated",
|
|
"url",
|
|
}
|
|
|
|
// PullReviewCommentsList prints a listing of pull review comments
|
|
func PullReviewCommentsList(comments []*gitea.PullReviewComment, output string, fields []string) error {
|
|
printables := make([]printable, len(comments))
|
|
for i, c := range comments {
|
|
printables[i] = &printablePullReviewComment{c}
|
|
}
|
|
t := tableFromItems(fields, printables, isMachineReadable(output))
|
|
return t.print(output)
|
|
}
|
|
|
|
type printablePullReviewComment struct {
|
|
*gitea.PullReviewComment
|
|
}
|
|
|
|
func (x printablePullReviewComment) FormatField(field string, machineReadable bool) string {
|
|
switch field {
|
|
case "id":
|
|
return fmt.Sprintf("%d", x.ID)
|
|
case "body":
|
|
return x.Body
|
|
case "reviewer":
|
|
if x.Reviewer != nil {
|
|
return formatUserName(x.Reviewer)
|
|
}
|
|
return ""
|
|
case "path":
|
|
return x.Path
|
|
case "line":
|
|
if x.LineNum != 0 {
|
|
return fmt.Sprintf("%d", x.LineNum)
|
|
}
|
|
if x.OldLineNum != 0 {
|
|
return fmt.Sprintf("%d", x.OldLineNum)
|
|
}
|
|
return ""
|
|
case "resolver":
|
|
if x.Resolver != nil {
|
|
return formatUserName(x.Resolver)
|
|
}
|
|
return ""
|
|
case "created":
|
|
return FormatTime(x.Created, machineReadable)
|
|
case "updated":
|
|
return FormatTime(x.Updated, machineReadable)
|
|
case "url":
|
|
return x.HTMLURL
|
|
}
|
|
return ""
|
|
}
|