mirror of
https://gitea.com/gitea/tea.git
synced 2026-06-06 03:08:44 +02:00
Move sdk from code.gitea.io/sdk/gitea to gitea.dev/sdk (#1006)
Reviewed-on: https://gitea.com/gitea/tea/pulls/1006 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
This commit is contained in:
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
@@ -20,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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-2
@@ -32,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
|
||||
@@ -49,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
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
+6
-4
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
@@ -49,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
|
||||
@@ -63,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"),
|
||||
@@ -93,6 +94,7 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
return task.CreatePull(
|
||||
requestCtx,
|
||||
ctx,
|
||||
ctx.String("base"),
|
||||
ctx.String("head"),
|
||||
|
||||
+5
-5
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
"gitea.dev/tea/modules/context"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+4
-4
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"slices"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea.dev/sdk"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
@@ -32,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
|
||||
@@ -47,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,
|
||||
})
|
||||
@@ -67,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
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
@@ -41,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
|
||||
@@ -52,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
|
||||
@@ -63,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"),
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
stdctx "context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
"github.com/urfave/cli/v3"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
@@ -19,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,
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ package pulls
|
||||
import (
|
||||
"context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/cmd/flags"
|
||||
"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,
|
||||
}
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -4,10 +4,11 @@
|
||||
package pulls
|
||||
|
||||
import (
|
||||
stdctx "context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
gitea "gitea.dev/sdk"
|
||||
|
||||
"gitea.dev/tea/modules/context"
|
||||
"gitea.dev/tea/modules/task"
|
||||
@@ -15,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
@@ -39,11 +40,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
|
||||
}
|
||||
@@ -57,5 +58,5 @@ func runResolveComment(ctx *context.TeaContext, action func(*context.TeaContext,
|
||||
return err
|
||||
}
|
||||
|
||||
return action(ctx, commentID)
|
||||
return action(requestCtx, ctx, commentID)
|
||||
}
|
||||
|
||||
@@ -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 != "" {
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user