From 2985824ab0fc7cc4ba2b242db18ed41e7a53f957 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Sat, 2 May 2026 17:01:40 +0000 Subject: [PATCH] Multiple PRs (#848) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an effort to allow tea pr review to work with multiple reviews. Fixes: #847 Reviewed-on: https://gitea.com/gitea/tea/pulls/848 Reviewed-by: Lunny Xiao Co-authored-by: Matěj Cepl Co-committed-by: Matěj Cepl --- cmd/pulls/review.go | 25 +++++++++++----- cmd/pulls/review_test.go | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 cmd/pulls/review_test.go diff --git a/cmd/pulls/review.go b/cmd/pulls/review.go index 58921fa..ea37b42 100644 --- a/cmd/pulls/review.go +++ b/cmd/pulls/review.go @@ -6,10 +6,12 @@ package pulls import ( stdctx "context" "fmt" + "os" "code.gitea.io/tea/cmd/flags" "code.gitea.io/tea/modules/context" "code.gitea.io/tea/modules/interact" + "code.gitea.io/tea/modules/print" "code.gitea.io/tea/modules/utils" "github.com/urfave/cli/v3" @@ -30,18 +32,27 @@ var CmdPullsReview = cli.Command{ return err } - if ctx.Args().Len() != 1 { - return fmt.Errorf("must specify a PR index") + if !ctx.Args().Present() { + return fmt.Errorf("must specify at least one PR index") } - idx, err := utils.ArgToIndex(ctx.Args().First()) - if err != nil { - return err + // This command is intentionally interactive. Fail early in CI / non-TTY + // contexts rather than hanging on prompts. + if os.Getenv("CI") != "" || !print.IsInteractive() || interact.IsStdinPiped() { + return fmt.Errorf("pull review requires an interactive terminal") } - if err := interact.ReviewPull(ctx, idx); err != nil && !interact.IsQuitting(err) { - return err + for _, arg := range ctx.Args().Slice() { + idx, err := utils.ArgToIndex(arg) + if err != nil { + return err + } + + if err := interact.ReviewPull(ctx, idx); err != nil && !interact.IsQuitting(err) { + return err + } } + return nil }, Flags: flags.AllDefaultFlags, diff --git a/cmd/pulls/review_test.go b/cmd/pulls/review_test.go new file mode 100644 index 0000000..566d692 --- /dev/null +++ b/cmd/pulls/review_test.go @@ -0,0 +1,62 @@ +// Copyright 2025 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package pulls + +import ( + "context" + "os" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestReview(t *testing.T) { + if os.Getenv("GITEA_TEA_TEST_URL") == "" { + t.Skip("GITEA_TEA_TEST_URL is not set, skipping test") + } + + tests := []struct { + name string + args []string + wantErr bool + errContains string + }{ + { + name: "no arguments", + args: []string{}, + wantErr: true, + errContains: "must specify at least one PR index", + }, + { + name: "one argument", + args: []string{"1"}, + wantErr: false, + }, + { + name: "two arguments", + args: []string{"1", "2"}, + wantErr: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cmd := CmdPullsReview + args := append(tt.args, "--repo", "user/repo") + err := cmd.Run(context.Background(), args) + if tt.wantErr { + assert.Error(t, err) + if tt.errContains != "" { + assert.Contains(t, err.Error(), tt.errContains) + } + return + } + // Don't assert no error, because we expect an error about the missing + // remote. Just assert that the error is not the one we're looking for. + if err != nil { + assert.NotContains(t, err.Error(), "must specify at least one PR index") + } + }) + } +}