Merge branch 'main' into lunny/add_reply_code_review

This commit is contained in:
Lunny Xiao
2026-05-25 21:58:27 -07:00
230 changed files with 2346 additions and 1495 deletions
+6 -5
View File
@@ -6,10 +6,11 @@ package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
)
// CmdPullsApprove approves a PR
@@ -19,12 +20,12 @@ var CmdPullsApprove = cli.Command{
Usage: "Approve a pull request",
Description: "Approve a pull request",
ArgsUsage: "<pull index> [<comment>]",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
return runPullReview(ctx, gitea.ReviewStateApproved, false)
return runPullReview(requestCtx, ctx, gitea.ReviewStateApproved, false)
},
Flags: flags.AllDefaultFlags,
}
+7 -7
View File
@@ -7,11 +7,11 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
@@ -33,7 +33,7 @@ var CmdPullsCheckout = cli.Command{
}, flags.AllDefaultFlags...),
}
func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error {
func runPullsCheckout(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -52,7 +52,7 @@ func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error {
return err
}
if err := task.PullCheckout(ctx.Login, ctx.Owner, ctx.Repo, ctx.Bool("branch"), idx, interact.PromptPassword); err != nil && !interact.IsQuitting(err) {
if err := task.PullCheckout(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, ctx.Bool("branch"), idx, interact.PromptPassword); err != nil && !interact.IsQuitting(err) {
return err
}
return nil
+8 -7
View File
@@ -8,12 +8,13 @@ import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
)
// CmdPullsClean removes the remote and local feature branches, if a PR is merged.
@@ -31,7 +32,7 @@ var CmdPullsClean = cli.Command{
}, flags.AllDefaultFlags...),
}
func runPullsClean(_ stdctx.Context, cmd *cli.Command) error {
func runPullsClean(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -48,7 +49,7 @@ func runPullsClean(_ stdctx.Context, cmd *cli.Command) error {
return err
}
if err := task.PullClean(ctx.Login, ctx.Owner, ctx.Repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword); err != nil && !interact.IsQuitting(err) {
if err := task.PullClean(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword); err != nil && !interact.IsQuitting(err) {
return err
}
return nil
+2 -2
View File
@@ -6,9 +6,9 @@ package pulls
import (
"context"
"code.gitea.io/tea/cmd/flags"
"gitea.dev/sdk"
"code.gitea.io/sdk/gitea"
"gitea.dev/tea/cmd/flags"
"github.com/urfave/cli/v3"
)
+11 -8
View File
@@ -6,12 +6,13 @@ package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/task"
)
// CmdPullsCreate creates a pull request
@@ -48,7 +49,7 @@ var CmdPullsCreate = cli.Command{
}, flags.IssuePRCreateFlags...),
}
func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
func runPullsCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -62,20 +63,21 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
// no args -> interactive mode
if ctx.IsInteractiveMode() {
if err := interact.CreatePull(ctx); err != nil && !interact.IsQuitting(err) {
if err := interact.CreatePull(requestCtx, ctx); err != nil && !interact.IsQuitting(err) {
return err
}
return nil
}
// else use args to create PR
opts, err := flags.GetIssuePRCreateFlags(ctx)
opts, err := flags.GetIssuePRCreateFlags(requestCtx, ctx)
if err != nil {
return err
}
if ctx.Bool("agit") {
return task.CreateAgitFlowPull(
requestCtx,
ctx,
ctx.String("remote"),
ctx.String("head"),
@@ -92,6 +94,7 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
}
return task.CreatePull(
requestCtx,
ctx,
ctx.String("base"),
ctx.String("head"),
+10 -10
View File
@@ -8,13 +8,13 @@ import (
"fmt"
"strings"
"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"
gitea "gitea.dev/sdk"
"code.gitea.io/sdk/gitea"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
@@ -40,7 +40,7 @@ use an empty string (eg. --milestone "").`,
),
}
func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error {
func runPullsEdit(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -72,7 +72,7 @@ func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error {
client := ctx.Login.Client()
for _, opts.Index = range indices {
pr, err := task.EditPull(ctx, client, *opts)
pr, err := task.EditPull(requestCtx, ctx, client, *opts)
if err != nil {
return err
}
@@ -87,7 +87,7 @@ func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error {
}
// editPullState abstracts the arg parsing to edit the given pull request
func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error {
func editPullState(requestCtx stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -106,7 +106,7 @@ func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullReques
client := ctx.Login.Client()
for _, index := range indices {
pr, _, err := client.EditPullRequest(ctx.Owner, ctx.Repo, index, opts)
pr, _, err := client.PullRequests.EditPullRequest(requestCtx, ctx.Owner, ctx.Repo, index, opts)
if err != nil {
return err
}
+8 -7
View File
@@ -8,11 +8,12 @@ import (
"fmt"
"slices"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/print"
"gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
)
var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{
@@ -31,7 +32,7 @@ var CmdPullsList = cli.Command{
}
// RunPullsList return list of pulls
func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
func RunPullsList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -46,7 +47,7 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
prs, _, err := client.ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
prs, _, err := client.PullRequests.ListRepoPullRequests(requestCtx, ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
ListOptions: flags.GetListOptions(cmd),
State: state,
})
@@ -66,7 +67,7 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
if pr.Head == nil || pr.Head.Sha == "" {
continue
}
ci, _, err := client.GetCombinedStatus(ctx.Owner, ctx.Repo, pr.Head.Sha)
ci, _, err := client.Repositories.GetCombinedStatus(requestCtx, ctx.Owner, ctx.Repo, pr.Head.Sha)
if err != nil {
fmt.Printf("error fetching CI status for PR #%d: %v\n", pr.Index, err)
continue
+10 -9
View File
@@ -6,13 +6,14 @@ package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
)
// CmdPullsMerge merges a PR
@@ -40,7 +41,7 @@ var CmdPullsMerge = cli.Command{
Usage: "Merge commit message",
},
}, flags.AllDefaultFlags...),
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -51,7 +52,7 @@ var CmdPullsMerge = cli.Command{
if ctx.Args().Len() != 1 {
// If no PR index is provided, try interactive mode
if err := interact.MergePull(ctx); err != nil && !interact.IsQuitting(err) {
if err := interact.MergePull(requestCtx, ctx); err != nil && !interact.IsQuitting(err) {
return err
}
return nil
@@ -62,7 +63,7 @@ var CmdPullsMerge = cli.Command{
return err
}
return task.PullMerge(ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
return task.PullMerge(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{
Style: gitea.MergeStyle(ctx.String("style")),
Title: ctx.String("title"),
Message: ctx.String("message"),
+6 -5
View File
@@ -6,10 +6,11 @@ package pulls
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
)
// CmdPullsReject requests changes to a PR
@@ -18,12 +19,12 @@ var CmdPullsReject = cli.Command{
Usage: "Request changes to a pull request",
Description: "Request changes to a pull request",
ArgsUsage: "<pull index> <reason>",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
return runPullReview(ctx, gitea.ReviewStateRequestChanges, true)
return runPullReview(requestCtx, ctx, gitea.ReviewStateRequestChanges, true)
},
Flags: flags.AllDefaultFlags,
}
+2 -2
View File
@@ -6,9 +6,9 @@ package pulls
import (
"context"
"code.gitea.io/tea/cmd/flags"
"gitea.dev/sdk"
"code.gitea.io/sdk/gitea"
"gitea.dev/tea/cmd/flags"
"github.com/urfave/cli/v3"
)
+4 -4
View File
@@ -6,8 +6,8 @@ package pulls
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"github.com/urfave/cli/v3"
)
@@ -18,12 +18,12 @@ var CmdPullsReply = cli.Command{
Usage: "Reply to a pull request review comment",
Description: "Reply to a pull request review comment",
ArgsUsage: "<pull index> <comment id> [<reply>]",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
return runPullReviewReply(ctx)
return runPullReviewReply(requestCtx, ctx)
},
Flags: flags.AllDefaultFlags,
}
+5 -5
View File
@@ -6,9 +6,9 @@ package pulls
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/task"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
"github.com/urfave/cli/v3"
)
@@ -19,12 +19,12 @@ var CmdPullsResolve = cli.Command{
Usage: "Resolve a review comment on a pull request",
Description: "Resolve a review comment on a pull request",
ArgsUsage: "<comment id>",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
return runResolveComment(ctx, task.ResolvePullReviewComment)
return runResolveComment(requestCtx, ctx, task.ResolvePullReviewComment)
},
Flags: flags.AllDefaultFlags,
}
+7 -7
View File
@@ -8,11 +8,11 @@ import (
"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"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/print"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
@@ -23,7 +23,7 @@ var CmdPullsReview = cli.Command{
Usage: "Interactively review a pull request",
Description: "Interactively review a pull request",
ArgsUsage: "<pull index>",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -48,7 +48,7 @@ var CmdPullsReview = cli.Command{
return err
}
if err := interact.ReviewPull(ctx, idx); err != nil && !interact.IsQuitting(err) {
if err := interact.ReviewPull(requestCtx, ctx, idx); err != nil && !interact.IsQuitting(err) {
return err
}
}
+7 -7
View File
@@ -7,11 +7,11 @@ 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"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/utils"
"github.com/urfave/cli/v3"
)
@@ -31,7 +31,7 @@ var CmdPullsReviewComments = cli.Command{
Flags: append([]cli.Flag{reviewCommentFieldsFlag}, flags.AllDefaultFlags...),
}
func runPullsReviewComments(_ stdctx.Context, cmd *cli.Command) error {
func runPullsReviewComments(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -49,7 +49,7 @@ func runPullsReviewComments(_ stdctx.Context, cmd *cli.Command) error {
return err
}
comments, err := task.ListPullReviewComments(ctx, idx)
comments, err := task.ListPullReviewComments(requestCtx, ctx, idx)
if err != nil {
return err
}
+15 -13
View File
@@ -4,24 +4,26 @@
package pulls
import (
stdctx "context"
"errors"
"fmt"
"io"
"strings"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/modules/config"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/theme"
"code.gitea.io/tea/modules/utils"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/config"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/interact"
"gitea.dev/tea/modules/task"
"gitea.dev/tea/modules/theme"
"gitea.dev/tea/modules/utils"
"charm.land/huh/v2"
)
// runPullReview handles the common logic for approving/rejecting pull requests
func runPullReview(ctx *context.TeaContext, state gitea.ReviewStateType, requireComment bool) error {
func runPullReview(requestCtx stdctx.Context, ctx *context.TeaContext, state gitea.ReviewStateType, requireComment bool) error {
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
@@ -45,11 +47,11 @@ func runPullReview(ctx *context.TeaContext, state gitea.ReviewStateType, require
comment := strings.Join(ctx.Args().Tail(), " ")
return task.CreatePullReview(ctx, idx, state, comment, nil)
return task.CreatePullReview(requestCtx, ctx, idx, state, comment, nil)
}
// runResolveComment handles the common logic for resolving/unresolving review comments
func runResolveComment(ctx *context.TeaContext, action func(*context.TeaContext, int64) error) error {
func runResolveComment(requestCtx stdctx.Context, ctx *context.TeaContext, action func(stdctx.Context, *context.TeaContext, int64) error) error {
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
@@ -63,11 +65,11 @@ func runResolveComment(ctx *context.TeaContext, action func(*context.TeaContext,
return err
}
return action(ctx, commentID)
return action(requestCtx, ctx, commentID)
}
// runPullReviewReply handles replying to a specific review comment on a pull request.
func runPullReviewReply(ctx *context.TeaContext) error {
func runPullReviewReply(requestCtx stdctx.Context, ctx *context.TeaContext) error {
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
@@ -91,7 +93,7 @@ func runPullReviewReply(ctx *context.TeaContext) error {
return err
}
return task.ReplyToPullReviewComment(ctx, idx, commentID, body)
return task.ReplyToPullReviewComment(requestCtx, ctx, idx, commentID, body)
}
func getCommentBody(ctx *context.TeaContext, extraArgs []string, promptTitle, noun string) (string, error) {
+1 -2
View File
@@ -4,7 +4,6 @@
package pulls
import (
"context"
"os"
"testing"
@@ -44,7 +43,7 @@ func TestReview(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
cmd := CmdPullsReview
args := append(tt.args, "--repo", "user/repo")
err := cmd.Run(context.Background(), args)
err := cmd.Run(t.Context(), args)
if tt.wantErr {
assert.Error(t, err)
if tt.errContains != "" {
+5 -5
View File
@@ -6,9 +6,9 @@ package pulls
import (
stdctx "context"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/task"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
"github.com/urfave/cli/v3"
)
@@ -19,12 +19,12 @@ var CmdPullsUnresolve = cli.Command{
Usage: "Unresolve a review comment on a pull request",
Description: "Unresolve a review comment on a pull request",
ArgsUsage: "<comment id>",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
return runResolveComment(ctx, task.UnresolvePullReviewComment)
return runResolveComment(requestCtx, ctx, task.UnresolvePullReviewComment)
},
Flags: flags.AllDefaultFlags,
}