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:
Lunny Xiao
2026-05-26 04:51:09 +00:00
parent 579099f9d9
commit 28ba9b915b
179 changed files with 617 additions and 599 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ jobs:
passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }}
- name: get SDK version
id: sdk_version
run: echo "version=$(go list -f '{{.Version}}' -m code.gitea.io/sdk/gitea)" >> "$GITHUB_OUTPUT"
run: echo "version=$(go list -f '{{.Version}}' -m gitea.dev/sdk)" >> "$GITHUB_OUTPUT"
- name: goreleaser
uses: goreleaser/goreleaser-action@v7
with:
+1 -1
View File
@@ -24,7 +24,7 @@ jobs:
passphrase: ${{ secrets.GPGSIGN_PASSPHRASE }}
- name: get SDK version
id: sdk_version
run: echo "version=$(go list -f '{{.Version}}' -m code.gitea.io/sdk/gitea)" >> "$GITHUB_OUTPUT"
run: echo "version=$(go list -f '{{.Version}}' -m gitea.dev/sdk)" >> "$GITHUB_OUTPUT"
- name: goreleaser
uses: goreleaser/goreleaser-action@v7
with:
+1 -1
View File
@@ -124,7 +124,7 @@ import (
// local packages
"code.gitea.io/gitea/models"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
// external packages
"github.com/foo/bar"
+1 -1
View File
@@ -24,7 +24,7 @@ endif
TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION))
TAGS ?=
SDK ?= $(shell $(GO) list -f '{{.Version}}' -m code.gitea.io/sdk/gitea)
SDK ?= $(shell $(GO) list -f '{{.Version}}' -m gitea.dev/sdk)
LDFLAGS := -X "gitea.dev/tea/modules/version.Version=$(TEA_VERSION)" -X "gitea.dev/tea/modules/version.Tags=$(TAGS)" -X "gitea.dev/tea/modules/version.SDK=$(SDK)" -s -w
# override to allow passing additional goflags via make CLI
+1 -1
View File
@@ -97,7 +97,7 @@ ABOUT
More info about Gitea itself on https://about.gitea.com.
```
- tea uses [code.gitea.io/sdk](https://code.gitea.io/sdk) and interacts with the Gitea API.
- tea uses [gitea.dev/sdk](https://gitea.dev/sdk) and interacts with the Gitea API.
## Installation
+1 -1
View File
@@ -61,7 +61,7 @@ func runRunsDelete(ctx stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.DeleteRepoActionRun(c.Owner, c.Repo, runID)
_, err = client.Actions.DeleteRepoRun(ctx, c.Owner, c.Repo, runID)
if err != nil {
return fmt.Errorf("failed to delete run: %w", err)
}
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"fmt"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -106,7 +106,7 @@ func RunRunsList(ctx stdctx.Context, cmd *cli.Command) error {
// Build list options
listOpts := flags.GetListOptions(cmd)
runs, _, err := client.ListRepoActionRuns(c.Owner, c.Repo, gitea.ListRepoActionRunsOptions{
runs, _, err := client.Actions.ListRepoRuns(ctx, c.Owner, c.Repo, gitea.ListRepoActionRunsOptions{
ListOptions: listOpts,
Status: cmd.String("status"),
Branch: cmd.String("branch"),
+2 -3
View File
@@ -4,12 +4,11 @@
package runs
import (
stdctx "context"
"os"
"testing"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v3"
@@ -107,6 +106,6 @@ func TestRunRunsListRequiresRepoContext(t *testing.T) {
}
require.NoError(t, cmd.Set("login", "test"))
err = RunRunsList(stdctx.Background(), cmd)
err = RunRunsList(t.Context(), cmd)
require.ErrorContains(t, err, "remote repository required")
}
+9 -9
View File
@@ -9,7 +9,7 @@ import (
"strconv"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -69,10 +69,10 @@ func runRunsLogs(ctx stdctx.Context, cmd *cli.Command) error {
}
if follow {
return followJobLogs(client, c, jobID, "")
return followJobLogs(ctx, client, c, jobID, "")
}
logs, _, err := client.GetRepoActionJobLogs(c.Owner, c.Repo, jobID)
logs, _, err := client.Actions.GetRepoRunJobLogs(ctx, c.Owner, c.Repo, jobID)
if err != nil {
return fmt.Errorf("failed to get logs for job %d: %w", jobID, err)
}
@@ -83,7 +83,7 @@ func runRunsLogs(ctx stdctx.Context, cmd *cli.Command) error {
}
// Otherwise, fetch all jobs and their logs
jobs, _, err := client.ListRepoActionRunJobs(c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{
jobs, _, err := client.Actions.ListRepoJobsByRun(ctx, c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
@@ -102,7 +102,7 @@ func runRunsLogs(ctx stdctx.Context, cmd *cli.Command) error {
// If following with single job, follow it
if follow && len(jobs.Jobs) == 1 {
return followJobLogs(client, c, jobs.Jobs[0].ID, jobs.Jobs[0].Name)
return followJobLogs(ctx, client, c, jobs.Jobs[0].ID, jobs.Jobs[0].Name)
}
// Fetch logs for each job
@@ -115,7 +115,7 @@ func runRunsLogs(ctx stdctx.Context, cmd *cli.Command) error {
fmt.Printf("Status: %s\n", job.Status)
fmt.Println("---")
logs, _, err := client.GetRepoActionJobLogs(c.Owner, c.Repo, job.ID)
logs, _, err := client.Actions.GetRepoRunJobLogs(ctx, c.Owner, c.Repo, job.ID)
if err != nil {
fmt.Printf("Error fetching logs: %v\n", err)
continue
@@ -128,7 +128,7 @@ func runRunsLogs(ctx stdctx.Context, cmd *cli.Command) error {
}
// followJobLogs continuously fetches and displays logs for a running job
func followJobLogs(client *gitea.Client, c *context.TeaContext, jobID int64, jobName string) error {
func followJobLogs(requestCtx stdctx.Context, client *gitea.Client, c *context.TeaContext, jobID int64, jobName string) error {
var lastLogLength int
if jobName != "" {
@@ -140,7 +140,7 @@ func followJobLogs(client *gitea.Client, c *context.TeaContext, jobID int64, job
for {
// Fetch job status
job, _, err := client.GetRepoActionJob(c.Owner, c.Repo, jobID)
job, _, err := client.Actions.GetRepoRunJob(requestCtx, c.Owner, c.Repo, jobID)
if err != nil {
return fmt.Errorf("failed to get job: %w", err)
}
@@ -149,7 +149,7 @@ func followJobLogs(client *gitea.Client, c *context.TeaContext, jobID int64, job
isRunning := job.Status == "in_progress" || job.Status == "queued" || job.Status == "pending"
// Fetch logs
logs, _, err := client.GetRepoActionJobLogs(c.Owner, c.Repo, jobID)
logs, _, err := client.Actions.GetRepoRunJobLogs(requestCtx, c.Owner, c.Repo, jobID)
if err != nil {
return fmt.Errorf("failed to get logs: %w", err)
}
+3 -4
View File
@@ -8,8 +8,7 @@ import (
"fmt"
"strconv"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
@@ -54,7 +53,7 @@ func runRunsView(ctx stdctx.Context, cmd *cli.Command) error {
}
// Fetch run details
run, _, err := client.GetRepoActionRun(c.Owner, c.Repo, runID)
run, _, err := client.Actions.GetRepoRun(ctx, c.Owner, c.Repo, runID)
if err != nil {
return fmt.Errorf("failed to get run: %w", err)
}
@@ -64,7 +63,7 @@ func runRunsView(ctx stdctx.Context, cmd *cli.Command) error {
// Fetch and print jobs if requested
if cmd.Bool("jobs") {
jobs, _, err := client.ListRepoActionRunJobs(c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{
jobs, _, err := client.Actions.ListRepoJobsByRun(ctx, c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+2 -2
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -62,7 +62,7 @@ func runSecretsCreate(ctx stdctx.Context, cmd *cli.Command) error {
return err
}
_, err = client.CreateRepoActionSecret(c.Owner, c.Repo, secretName, gitea.CreateOrUpdateSecretOption{
_, err = client.Actions.CreateRepoSecret(ctx, c.Owner, c.Repo, secretName, gitea.CreateOrUpdateSecretOption{
Data: secretValue,
})
if err != nil {
+1 -1
View File
@@ -56,7 +56,7 @@ func runSecretsDelete(ctx stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.DeleteRepoActionSecret(c.Owner, c.Repo, secretName)
_, err = client.Actions.DeleteRepoSecret(ctx, c.Owner, c.Repo, secretName)
if err != nil {
return err
}
+2 -2
View File
@@ -6,7 +6,7 @@ package secrets
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -38,7 +38,7 @@ func RunSecretsList(ctx stdctx.Context, cmd *cli.Command) error {
}
client := c.Login.Client()
secrets, _, err := client.ListRepoActionSecret(c.Owner, c.Repo, gitea.ListRepoActionSecretOption{
secrets, _, err := client.Actions.ListRepoSecrets(ctx, c.Owner, c.Repo, gitea.ListRepoActionSecretOption{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+1 -2
View File
@@ -4,7 +4,6 @@
package secrets
import (
stdctx "context"
"os"
"testing"
@@ -94,6 +93,6 @@ func TestRunSecretsListRequiresRepoContext(t *testing.T) {
}
require.NoError(t, cmd.Set("login", "test"))
err = RunSecretsList(stdctx.Background(), cmd)
err = RunSecretsList(t.Context(), cmd)
require.ErrorContains(t, err, "remote repository required")
}
+1 -1
View File
@@ -56,7 +56,7 @@ func runVariablesDelete(ctx stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.DeleteRepoActionVariable(c.Owner, c.Repo, variableName)
_, err = client.Actions.DeleteRepoVariable(ctx, c.Owner, c.Repo, variableName)
if err != nil {
return err
}
+1 -1
View File
@@ -42,7 +42,7 @@ func RunVariablesList(ctx stdctx.Context, cmd *cli.Command) error {
if name := cmd.String("name"); name != "" {
// Get specific variable
variable, _, err := client.GetRepoActionVariable(c.Owner, c.Repo, name)
variable, _, err := client.Actions.GetRepoVariable(ctx, c.Owner, c.Repo, name)
if err != nil {
return err
}
+1 -2
View File
@@ -4,7 +4,6 @@
package variables
import (
stdctx "context"
"os"
"testing"
@@ -94,6 +93,6 @@ func TestRunVariablesListRequiresRepoContext(t *testing.T) {
}
require.NoError(t, cmd.Set("login", "test"))
err = RunVariablesList(stdctx.Background(), cmd)
err = RunVariablesList(t.Context(), cmd)
require.ErrorContains(t, err, "remote repository required")
}
+1 -1
View File
@@ -69,7 +69,7 @@ func runVariablesSet(ctx stdctx.Context, cmd *cli.Command) error {
return err
}
_, err = client.CreateRepoActionVariable(c.Owner, c.Repo, variableName, variableValue)
_, err = client.Actions.CreateRepoVariable(ctx, c.Owner, c.Repo, variableName, variableValue)
if err != nil {
return err
}
+1 -1
View File
@@ -55,7 +55,7 @@ func runWorkflowsDisable(ctx stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.DisableRepoActionWorkflow(c.Owner, c.Repo, workflowID)
_, err = client.Actions.DisableRepoWorkflow(ctx, c.Owner, c.Repo, workflowID)
if err != nil {
return fmt.Errorf("failed to disable workflow: %w", err)
}
+7 -7
View File
@@ -9,7 +9,7 @@ import (
"strings"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -87,7 +87,7 @@ func runWorkflowsDispatch(ctx stdctx.Context, cmd *cli.Command) error {
Inputs: inputs,
}
details, _, err := client.DispatchRepoActionWorkflow(c.Owner, c.Repo, workflowID, opt, true)
details, _, err := client.Actions.DispatchRepoWorkflow(ctx, c.Owner, c.Repo, workflowID, opt, true)
if err != nil {
return fmt.Errorf("failed to dispatch workflow: %w", err)
}
@@ -95,7 +95,7 @@ func runWorkflowsDispatch(ctx stdctx.Context, cmd *cli.Command) error {
print.ActionWorkflowDispatchResult(details)
if cmd.Bool("follow") && details != nil && details.WorkflowRunID > 0 {
return followDispatchedRun(client, c, details.WorkflowRunID)
return followDispatchedRun(ctx, client, c, details.WorkflowRunID)
}
return nil
@@ -107,7 +107,7 @@ const (
)
// followDispatchedRun waits for the dispatched run to start, then follows its logs
func followDispatchedRun(client *gitea.Client, c *context.TeaContext, runID int64) error {
func followDispatchedRun(ctx stdctx.Context, client *gitea.Client, c *context.TeaContext, runID int64) error {
fmt.Printf("\nWaiting for run %d to start...\n", runID)
var jobs *gitea.ActionWorkflowJobsResponse
@@ -115,7 +115,7 @@ func followDispatchedRun(client *gitea.Client, c *context.TeaContext, runID int6
time.Sleep(followPollInterval)
var err error
jobs, _, err = client.ListRepoActionRunJobs(c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{})
jobs, _, err = client.Actions.ListRepoJobsByRun(ctx, c.Owner, c.Repo, runID, gitea.ListRepoActionJobsOptions{})
if err != nil {
return fmt.Errorf("failed to get jobs: %w", err)
}
@@ -136,14 +136,14 @@ func followDispatchedRun(client *gitea.Client, c *context.TeaContext, runID int6
deadline := time.Now().Add(followMaxDuration)
var lastLogLength int
for time.Now().Before(deadline) {
job, _, err := client.GetRepoActionJob(c.Owner, c.Repo, jobID)
job, _, err := client.Actions.GetRepoRunJob(ctx, c.Owner, c.Repo, jobID)
if err != nil {
return fmt.Errorf("failed to get job: %w", err)
}
isRunning := job.Status == "in_progress" || job.Status == "queued" || job.Status == "pending"
logs, _, logErr := client.GetRepoActionJobLogs(c.Owner, c.Repo, jobID)
logs, _, logErr := client.Actions.GetRepoRunJobLogs(ctx, c.Owner, c.Repo, jobID)
if logErr != nil && isRunning {
time.Sleep(followPollInterval)
continue
+1 -1
View File
@@ -38,7 +38,7 @@ func runWorkflowsEnable(ctx stdctx.Context, cmd *cli.Command) error {
client := c.Login.Client()
workflowID := cmd.Args().First()
_, err = client.EnableRepoActionWorkflow(c.Owner, c.Repo, workflowID)
_, err = client.Actions.EnableRepoWorkflow(ctx, c.Owner, c.Repo, workflowID)
if err != nil {
return fmt.Errorf("failed to enable workflow: %w", err)
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -36,7 +36,7 @@ func RunWorkflowsList(ctx stdctx.Context, cmd *cli.Command) error {
}
client := c.Login.Client()
resp, _, err := client.ListRepoActionWorkflows(c.Owner, c.Repo)
resp, _, err := client.Actions.ListRepoWorkflows(ctx, c.Owner, c.Repo)
if err != nil {
return fmt.Errorf("failed to list workflows: %w", err)
}
+1 -1
View File
@@ -40,7 +40,7 @@ func runWorkflowsView(ctx stdctx.Context, cmd *cli.Command) error {
client := c.Login.Client()
workflowID := cmd.Args().First()
wf, _, err := client.GetRepoActionWorkflow(c.Owner, c.Repo, workflowID)
wf, _, err := client.Actions.GetRepoWorkflow(ctx, c.Owner, c.Repo, workflowID)
if err != nil {
return fmt.Errorf("failed to get workflow: %w", err)
}
+3 -3
View File
@@ -20,7 +20,7 @@ var CmdAdmin = cli.Command{
Usage: "Operations requiring admin access on the Gitea instance",
Aliases: []string{"a"},
Category: catMisc,
Action: func(_ stdctx.Context, cmd *cli.Command) error {
Action: func(requestCtx stdctx.Context, cmd *cli.Command) error {
return cli.ShowSubcommandHelp(cmd)
},
Commands: []*cli.Command{
@@ -47,13 +47,13 @@ var cmdAdminUsers = cli.Command{
Flags: users.CmdUserList.Flags,
}
func runAdminUserDetail(_ stdctx.Context, cmd *cli.Command, u string) error {
func runAdminUserDetail(requestCtx stdctx.Context, cmd *cli.Command, u string) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
client := ctx.Login.Client()
user, _, err := client.GetUserInfo(u)
user, _, err := client.Users.GetUserInfo(requestCtx, u)
if err != nil {
return err
}
+5 -5
View File
@@ -11,7 +11,7 @@ import (
"strings"
"syscall"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -83,7 +83,7 @@ var CmdUserCreate = cli.Command{
}
// RunUserCreate creates a new user
func RunUserCreate(_ stdctx.Context, cmd *cli.Command) error {
func RunUserCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -177,7 +177,7 @@ func RunUserCreate(_ stdctx.Context, cmd *cli.Command) error {
createOpts.Visibility = vis
// Create the user
user, _, err := client.AdminCreateUser(createOpts)
user, _, err := client.Admin.CreateUser(requestCtx, createOpts)
if err != nil {
return err
}
@@ -202,13 +202,13 @@ func RunUserCreate(_ stdctx.Context, cmd *cli.Command) error {
}
// Update user with admin/restricted/prohibit-login settings
_, err = client.AdminEditUser(username, editOpts)
_, err = client.Admin.EditUser(requestCtx, username, editOpts)
if err != nil {
return fmt.Errorf("user created but failed to update admin/restricted/prohibit-login status: %w", err)
}
// Refresh user info to reflect the changes
user, _, err = client.GetUserInfo(username)
user, _, err = client.Users.GetUserInfo(requestCtx, username)
if err != nil {
return fmt.Errorf("user updated but failed to retrieve updated user info: %w", err)
}
+3 -3
View File
@@ -31,7 +31,7 @@ var CmdUserDelete = cli.Command{
}
// RunUserDelete deletes a user
func RunUserDelete(_ stdctx.Context, cmd *cli.Command) error {
func RunUserDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -45,7 +45,7 @@ func RunUserDelete(_ stdctx.Context, cmd *cli.Command) error {
username := ctx.Args().First()
// Get user details first to show what we're deleting
user, _, err := client.GetUserInfo(username)
user, _, err := client.Users.GetUserInfo(requestCtx, username)
if err != nil {
return fmt.Errorf("failed to get user info: %w", err)
}
@@ -67,7 +67,7 @@ func RunUserDelete(_ stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.AdminDeleteUser(username)
_, err = client.Admin.DeleteUser(requestCtx, username)
if err != nil {
return fmt.Errorf("failed to delete user: %w", err)
}
+5 -6
View File
@@ -11,8 +11,7 @@ import (
"strings"
"syscall"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/print"
@@ -135,7 +134,7 @@ var CmdUserEdit = cli.Command{
}
// RunUserEdit edits an existing user
func RunUserEdit(_ stdctx.Context, cmd *cli.Command) error {
func RunUserEdit(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -149,7 +148,7 @@ func RunUserEdit(_ stdctx.Context, cmd *cli.Command) error {
username := ctx.Args().First()
// Verify the user exists before attempting an update.
_, _, err = client.GetUserInfo(username)
_, _, err = client.Users.GetUserInfo(requestCtx, username)
if err != nil {
return fmt.Errorf("failed to get user info: %w", err)
}
@@ -358,13 +357,13 @@ func RunUserEdit(_ stdctx.Context, cmd *cli.Command) error {
}
// Update the user
_, err = client.AdminEditUser(username, editOpts)
_, err = client.Admin.EditUser(requestCtx, username, editOpts)
if err != nil {
return fmt.Errorf("failed to update user: %w", err)
}
// Refresh user info to reflect the changes
updatedUser, _, err := client.GetUserInfo(username)
updatedUser, _, err := client.Users.GetUserInfo(requestCtx, username)
if err != nil {
return fmt.Errorf("user updated but failed to retrieve updated user info: %w", err)
}
+3 -3
View File
@@ -6,7 +6,7 @@ package users
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -33,7 +33,7 @@ var CmdUserList = cli.Command{
}
// RunUserList list users
func RunUserList(_ stdctx.Context, cmd *cli.Command) error {
func RunUserList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -45,7 +45,7 @@ func RunUserList(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
users, _, err := client.AdminListUsers(gitea.AdminListUsersOptions{
users, _, err := client.Admin.ListUsers(requestCtx, gitea.AdminListUsersOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"fmt"
"strings"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
)
func parseUserVisibility(visibility string) (*gitea.VisibleType, error) {
+1 -1
View File
@@ -104,7 +104,7 @@ type preparedAPIRequest struct {
Body []byte
}
func runApi(_ stdctx.Context, cmd *cli.Command) error {
func runApi(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
+1 -1
View File
@@ -296,7 +296,7 @@ func runApiWithArgs(t *testing.T, args []string) (method string, body []byte, er
}
fullArgs := append([]string{"api", "--login", "testLogin"}, args...)
runErr := cmd.Run(stdctx.Background(), fullArgs)
runErr := cmd.Run(t.Context(), fullArgs)
return capturedMethod, capturedBody, runErr
}
+3 -3
View File
@@ -27,7 +27,7 @@ var CmdReleaseAttachmentCreate = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error {
func runReleaseAttachmentCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -46,7 +46,7 @@ func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("release tag needed to create attachment")
}
release, err := releases.GetReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
release, err := releases.GetReleaseByTag(requestCtx, ctx.Owner, ctx.Repo, tag, client)
if err != nil {
return err
}
@@ -59,7 +59,7 @@ func runReleaseAttachmentCreate(_ stdctx.Context, cmd *cli.Command) error {
filePath := filepath.Base(asset)
if _, _, err = ctx.Login.Client().CreateReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
if _, _, err = ctx.Login.Client().Releases.CreateReleaseAttachment(requestCtx, ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
file.Close()
return err
}
+5 -5
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/cmd/releases"
@@ -32,7 +32,7 @@ var CmdReleaseAttachmentDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
func runReleaseAttachmentDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -56,14 +56,14 @@ func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
return nil
}
release, err := releases.GetReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
release, err := releases.GetReleaseByTag(requestCtx, ctx.Owner, ctx.Repo, tag, client)
if err != nil {
return err
}
var existing []*gitea.Attachment
for page := 1; ; {
page_attachments, resp, err := client.ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
page_attachments, resp, err := client.Releases.ListReleaseAttachments(requestCtx, ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
})
if err != nil {
@@ -87,7 +87,7 @@ func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("release does not have attachment named '%s'", name)
}
_, err = client.DeleteReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, attachment.ID)
_, err = client.Releases.DeleteReleaseAttachment(requestCtx, ctx.Owner, ctx.Repo, release.ID, attachment.ID)
if err != nil {
return err
}
+4 -5
View File
@@ -7,8 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/cmd/releases"
"gitea.dev/tea/modules/context"
@@ -31,7 +30,7 @@ var CmdReleaseAttachmentList = cli.Command{
}
// RunReleaseAttachmentList list release attachments
func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error {
func RunReleaseAttachmentList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -46,12 +45,12 @@ func RunReleaseAttachmentList(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("release tag needed to list attachments")
}
release, err := releases.GetReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
release, err := releases.GetReleaseByTag(requestCtx, ctx.Owner, ctx.Repo, tag, client)
if err != nil {
return err
}
attachments, _, err := ctx.Login.Client().ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
attachments, _, err := ctx.Login.Client().Releases.ListReleaseAttachments(requestCtx, ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+4 -4
View File
@@ -6,7 +6,7 @@ package branches
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -37,7 +37,7 @@ var CmdBranchesList = cli.Command{
}
// RunBranchesList list branches
func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
func RunBranchesList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -53,14 +53,14 @@ func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
var branches []*gitea.Branch
var protections []*gitea.BranchProtection
branches, _, err = ctx.Login.Client().ListRepoBranches(owner, ctx.Repo, gitea.ListRepoBranchesOptions{
branches, _, err = ctx.Login.Client().Repositories.ListRepoBranches(requestCtx, owner, ctx.Repo, gitea.ListRepoBranchesOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
return err
}
protections, _, err = ctx.Login.Client().ListBranchProtections(owner, ctx.Repo, gitea.ListBranchProtectionsOptions{
protections, _, err = ctx.Login.Client().Repositories.ListBranchProtections(requestCtx, owner, ctx.Repo, gitea.ListBranchProtectionsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+4 -4
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -44,7 +44,7 @@ var CmdBranchesUnprotect = cli.Command{
}
// RunBranchesProtect function to protect/unprotect a list of branches
func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error {
func RunBranchesProtect(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -67,7 +67,7 @@ func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error {
var err error
command := ctx.Command.Name
if command == "protect" {
_, _, err = ctx.Login.Client().CreateBranchProtection(owner, ctx.Repo, gitea.CreateBranchProtectionOption{
_, _, err = ctx.Login.Client().Repositories.CreateBranchProtection(requestCtx, owner, ctx.Repo, gitea.CreateBranchProtectionOption{
BranchName: branch,
RuleName: "",
EnablePush: false,
@@ -93,7 +93,7 @@ func RunBranchesProtect(_ stdctx.Context, cmd *cli.Command) error {
UnprotectedFilePatterns: "",
})
} else if command == "unprotect" {
_, err = ctx.Login.Client().DeleteBranchProtection(owner, ctx.Repo, branch)
_, err = ctx.Login.Client().Repositories.DeleteBranchProtection(requestCtx, owner, ctx.Repo, branch)
} else {
return fmt.Errorf("command %s is not supported", command)
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -33,7 +33,7 @@ var CmdBranchesRename = cli.Command{
}
// RunBranchesRename function to rename a branch
func RunBranchesRename(_ stdctx.Context, cmd *cli.Command) error {
func RunBranchesRename(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -54,7 +54,7 @@ func RunBranchesRename(_ stdctx.Context, cmd *cli.Command) error {
owner = ctx.String("owner")
}
successful, _, err := ctx.Login.Client().RenameRepoBranch(owner, ctx.Repo, oldBranchName, gitea.RenameRepoBranchOption{
successful, _, err := ctx.Login.Client().Repositories.RenameRepoBranch(requestCtx, owner, ctx.Repo, oldBranchName, gitea.RenameRepoBranchOption{
Name: newBranchName,
})
if err != nil {
+1
View File
@@ -88,6 +88,7 @@ func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error {
}
_, err = task.RepoClone(
ctx,
dir,
login,
owner,
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"io"
"strings"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/config"
@@ -36,7 +36,7 @@ var CmdAddComment = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runAddComment(_ stdctx.Context, cmd *cli.Command) error {
func runAddComment(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -83,7 +83,7 @@ func runAddComment(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
comment, _, err := client.CreateIssueComment(ctx.Owner, ctx.Repo, idx, gitea.CreateIssueCommentOption{
comment, _, err := client.Issues.CreateIssueComment(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.CreateIssueCommentOption{
Body: body,
})
if err != nil {
+1 -1
View File
@@ -8,7 +8,7 @@ import (
"io"
"time"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
)
type detailLabelData struct {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"errors"
"fmt"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"github.com/urfave/cli/v3"
)
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"io"
"testing"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v3"
@@ -75,7 +75,7 @@ func TestPaginationFlags(t *testing.T) {
},
Flags: PaginationFlags,
}
err := cmd.Run(context.Background(), tc.args)
err := cmd.Run(t.Context(), tc.args)
require.NoError(t, err)
})
}
@@ -118,7 +118,7 @@ func TestPaginationFailures(t *testing.T) {
ErrWriter: io.Discard,
}
t.Run(tc.name, func(t *testing.T) {
err := cmd.Run(context.Background(), tc.args)
err := cmd.Run(t.Context(), tc.args)
require.ErrorContains(t, err, tc.expectedError.Error())
// require.ErrorIs(t, err, tc.expectedError)
})
@@ -140,7 +140,7 @@ func TestGetListOptionsDoesNotLeakBetweenCommands(t *testing.T) {
Flags: PaginationFlags,
}
require.NoError(t, cmd.Run(context.Background(), args))
require.NoError(t, cmd.Run(t.Context(), args))
}
run([]string{"test", "--page", "5", "--limit", "10"})
+5 -4
View File
@@ -4,11 +4,12 @@
package flags
import (
stdctx "context"
"fmt"
"strings"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/modules/context"
"gitea.dev/tea/modules/task"
@@ -131,7 +132,7 @@ var IssuePRCreateFlags = append([]cli.Flag{
}, issuePRFlags...)
// GetIssuePRCreateFlags parses all IssuePREditFlags
func GetIssuePRCreateFlags(ctx *context.TeaContext) (*gitea.CreateIssueOption, error) {
func GetIssuePRCreateFlags(requestCtx stdctx.Context, ctx *context.TeaContext) (*gitea.CreateIssueOption, error) {
opts := gitea.CreateIssueOption{
Title: ctx.String("title"),
Body: ctx.String("description"),
@@ -155,7 +156,7 @@ func GetIssuePRCreateFlags(ctx *context.TeaContext) (*gitea.CreateIssueOption, e
if client == nil {
client = ctx.Login.Client()
}
if opts.Labels, err = task.ResolveLabelNames(client, ctx.Owner, ctx.Repo, labelNames); err != nil {
if opts.Labels, err = task.ResolveLabelNames(requestCtx, client, ctx.Owner, ctx.Repo, labelNames); err != nil {
return nil, err
}
}
@@ -164,7 +165,7 @@ func GetIssuePRCreateFlags(ctx *context.TeaContext) (*gitea.CreateIssueOption, e
if client == nil {
client = ctx.Login.Client()
}
ms, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestoneName)
ms, _, err := client.Repositories.GetMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, milestoneName)
if err != nil {
return nil, fmt.Errorf("milestone '%s' not found", milestoneName)
}
+15 -15
View File
@@ -8,7 +8,7 @@ import (
"fmt"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/cmd/issues"
@@ -38,12 +38,12 @@ type issueData struct {
}
type issueDetailClient interface {
GetIssue(owner, repo string, index int64) (*gitea.Issue, *gitea.Response, error)
GetIssueReactions(owner, repo string, index int64) ([]*gitea.Reaction, *gitea.Response, error)
GetIssue(ctx stdctx.Context, owner, repo string, index int64) (*gitea.Issue, *gitea.Response, error)
ListIssueReactions(ctx stdctx.Context, owner, repo string, index int64, opt gitea.ListIssueReactionsOptions) ([]*gitea.Reaction, *gitea.Response, error)
}
type issueCommentClient interface {
ListIssueComments(owner, repo string, index int64, opt gitea.ListIssueCommentOptions) ([]*gitea.Comment, *gitea.Response, error)
ListIssueComments(ctx stdctx.Context, owner, repo string, index int64, opt gitea.ListIssueCommentOptions) ([]*gitea.Comment, *gitea.Response, error)
}
type commentData = detailCommentData
@@ -79,13 +79,13 @@ func runIssues(ctx stdctx.Context, cmd *cli.Command) error {
return issues.RunIssuesList(ctx, cmd)
}
func runIssueDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
func runIssueDetail(requestCtx stdctx.Context, cmd *cli.Command, index string) error {
ctx, idx, err := resolveIssueDetailContext(cmd, index)
if err != nil {
return err
}
return runIssueDetailWithClient(ctx, idx, ctx.Login.Client())
return runIssueDetailWithClient(requestCtx, ctx, idx, ctx.Login.Client().Issues)
}
func resolveIssueDetailContext(cmd *cli.Command, index string) (*context.TeaContext, int64, error) {
@@ -108,12 +108,12 @@ func resolveIssueDetailContext(cmd *cli.Command, index string) (*context.TeaCont
return ctx, idx, nil
}
func runIssueDetailWithClient(ctx *context.TeaContext, idx int64, client issueDetailClient) error {
issue, _, err := client.GetIssue(ctx.Owner, ctx.Repo, idx)
func runIssueDetailWithClient(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, client issueDetailClient) error {
issue, _, err := client.GetIssue(requestCtx, ctx.Owner, ctx.Repo, idx)
if err != nil {
return err
}
reactions, _, err := client.GetIssueReactions(ctx.Owner, ctx.Repo, idx)
reactions, _, err := client.ListIssueReactions(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.ListIssueReactionsOptions{})
if err != nil {
return err
}
@@ -121,14 +121,14 @@ func runIssueDetailWithClient(ctx *context.TeaContext, idx int64, client issueDe
if ctx.IsSet("output") {
switch ctx.String("output") {
case "json":
return runIssueDetailAsJSON(ctx, issue)
return runIssueDetailAsJSON(requestCtx, ctx, issue)
}
}
print.IssueDetails(issue, reactions)
if issue.Comments > 0 {
err = interact.ShowCommentsMaybeInteractive(ctx, idx, issue.Comments)
err = interact.ShowCommentsMaybeInteractive(requestCtx, ctx, idx, issue.Comments)
if err != nil {
return fmt.Errorf("error loading comments: %v", err)
}
@@ -137,17 +137,17 @@ func runIssueDetailWithClient(ctx *context.TeaContext, idx int64, client issueDe
return nil
}
func runIssueDetailAsJSON(ctx *context.TeaContext, issue *gitea.Issue) error {
return runIssueDetailAsJSONWithClient(ctx, issue, ctx.Login.Client())
func runIssueDetailAsJSON(requestCtx stdctx.Context, ctx *context.TeaContext, issue *gitea.Issue) error {
return runIssueDetailAsJSONWithClient(requestCtx, ctx, issue, ctx.Login.Client().Issues)
}
func runIssueDetailAsJSONWithClient(ctx *context.TeaContext, issue *gitea.Issue, c issueCommentClient) error {
func runIssueDetailAsJSONWithClient(requestCtx stdctx.Context, ctx *context.TeaContext, issue *gitea.Issue, c issueCommentClient) error {
opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)}
comments := []*gitea.Comment{}
if ctx.Bool("comments") {
var err error
comments, _, err = c.ListIssueComments(ctx.Owner, ctx.Repo, issue.Index, opts)
comments, _, err = c.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, issue.Index, opts)
if err != nil {
return err
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -30,7 +30,7 @@ var CmdIssuesClose = cli.Command{
}
// editIssueState abstracts the arg parsing to edit the given issue
func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error {
func editIssueState(requestCtx stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOption) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -49,7 +49,7 @@ func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOpti
client := ctx.Login.Client()
for _, index := range indices {
issue, _, err := client.EditIssue(ctx.Owner, ctx.Repo, index, opts)
issue, _, err := client.Issues.EditIssue(requestCtx, ctx.Owner, ctx.Repo, index, opts)
if err != nil {
return err
}
+4 -5
View File
@@ -25,7 +25,7 @@ var CmdIssuesCreate = cli.Command{
Flags: flags.IssuePRCreateFlags,
}
func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error {
func runIssuesCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -35,20 +35,19 @@ func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error {
}
if ctx.IsInteractiveMode() {
err := interact.CreateIssue(ctx.Login, ctx.Owner, ctx.Repo)
err := interact.CreateIssue(requestCtx, ctx.Login, ctx.Owner, ctx.Repo)
if err != nil && !interact.IsQuitting(err) {
return err
}
return nil
}
opts, err := flags.GetIssuePRCreateFlags(ctx)
opts, err := flags.GetIssuePRCreateFlags(requestCtx, ctx)
if err != nil {
return err
}
return task.CreateIssue(
ctx.Login,
return task.CreateIssue(requestCtx, ctx.Login,
ctx.Owner,
ctx.Repo,
*opts,
+3 -3
View File
@@ -30,7 +30,7 @@ use an empty string (eg. --milestone "").`,
Flags: flags.IssuePREditFlags,
}
func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
func runIssuesEdit(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -57,7 +57,7 @@ func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
for _, opts.Index = range indices {
if ctx.IsInteractiveMode() {
var err error
opts, err = interact.EditIssue(*ctx, opts.Index)
opts, err = interact.EditIssue(requestCtx, *ctx, opts.Index)
if err != nil {
if interact.IsQuitting(err) {
return nil // user quit
@@ -66,7 +66,7 @@ func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
}
}
issue, err := task.EditIssue(ctx, client, *opts)
issue, err := task.EditIssue(requestCtx, ctx, client, *opts)
if err != nil {
return err
}
+4 -4
View File
@@ -8,7 +8,7 @@ import (
"errors"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -33,7 +33,7 @@ var CmdIssuesList = cli.Command{
}
// RunIssuesList list issues
func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
func RunIssuesList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -72,7 +72,7 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
milestones, _ := flags.MilestoneFilterFlag.GetValues(cmd)
var issues []*gitea.Issue
if ctx.Repo != "" {
issues, _, err = ctx.Login.Client().ListRepoIssues(owner, ctx.Repo, gitea.ListIssueOption{
issues, _, err = ctx.Login.Client().Issues.ListRepoIssues(requestCtx, owner, ctx.Repo, gitea.ListIssueOption{
ListOptions: flags.GetListOptions(cmd),
State: state,
Type: kind,
@@ -92,7 +92,7 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
if ctx.IsSet("assignee") {
return errors.New("--assignee requires --repo (global issue search does not support assignee filter)")
}
issues, _, err = ctx.Login.Client().ListIssues(gitea.ListIssueOption{
issues, _, err = ctx.Login.Client().Issues.ListIssues(requestCtx, gitea.ListIssueOption{
ListOptions: flags.GetListOptions(cmd),
State: state,
Type: kind,
+1 -1
View File
@@ -6,7 +6,7 @@ package issues
import (
"context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"github.com/urfave/cli/v3"
+7 -6
View File
@@ -5,12 +5,13 @@ package cmd
import (
"bytes"
stdctx "context"
"encoding/json"
"fmt"
"testing"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v3"
@@ -32,7 +33,7 @@ type fakeIssueCommentClient struct {
comments []*gitea.Comment
}
func (f *fakeIssueCommentClient) ListIssueComments(owner, repo string, index int64, _ gitea.ListIssueCommentOptions) ([]*gitea.Comment, *gitea.Response, error) {
func (f *fakeIssueCommentClient) ListIssueComments(_ stdctx.Context, owner, repo string, index int64, _ gitea.ListIssueCommentOptions) ([]*gitea.Comment, *gitea.Response, error) {
f.owner = owner
f.repo = repo
f.index = index
@@ -47,14 +48,14 @@ type fakeIssueDetailClient struct {
reactions []*gitea.Reaction
}
func (f *fakeIssueDetailClient) GetIssue(owner, repo string, index int64) (*gitea.Issue, *gitea.Response, error) {
func (f *fakeIssueDetailClient) GetIssue(_ stdctx.Context, owner, repo string, index int64) (*gitea.Issue, *gitea.Response, error) {
f.owner = owner
f.repo = repo
f.index = index
return f.issue, nil, nil
}
func (f *fakeIssueDetailClient) GetIssueReactions(owner, repo string, index int64) ([]*gitea.Reaction, *gitea.Response, error) {
func (f *fakeIssueDetailClient) ListIssueReactions(_ stdctx.Context, owner, repo string, index int64, _ gitea.ListIssueReactionsOptions) ([]*gitea.Reaction, *gitea.Response, error) {
f.owner = owner
f.repo = repo
f.index = index
@@ -221,7 +222,7 @@ func TestRunIssueDetailAsJSON(t *testing.T) {
require.NoError(t, testContext.Set("comments", "false"))
}
err := runIssueDetailAsJSONWithClient(&testContext, &testCase.issue, client)
err := runIssueDetailAsJSONWithClient(t.Context(), &testContext, &testCase.issue, client)
require.NoError(t, err, "Failed to run issue detail as JSON")
if testCase.flagComments {
@@ -351,7 +352,7 @@ func TestRunIssueDetailUsesOwnerFlag(t *testing.T) {
reactions: []*gitea.Reaction{},
}
err = runIssueDetailWithClient(teaCtx, idx, client)
err = runIssueDetailWithClient(t.Context(), teaCtx, idx, client)
require.NoError(t, err, "Expected runIssueDetail to succeed")
assert.Equal(t, expectedOwner, client.owner)
assert.Equal(t, expectedRepo, client.repo)
+4 -4
View File
@@ -10,7 +10,7 @@ import (
"os"
"strings"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -45,7 +45,7 @@ var CmdLabelCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
func runLabelCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -56,7 +56,7 @@ func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
labelFile := ctx.String("file")
if len(labelFile) == 0 {
_, _, err := ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
_, _, err := ctx.Login.Client().Repositories.CreateLabel(requestCtx, ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
Name: ctx.String("name"),
Color: ctx.String("color"),
Description: ctx.String("description"),
@@ -78,7 +78,7 @@ func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
if color == "" || name == "" {
log.Printf("Line %d ignored because lack of enough fields: %s\n", i, line)
} else {
_, _, err = ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
_, _, err = ctx.Login.Client().Repositories.CreateLabel(requestCtx, ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
Name: name,
Color: color,
Description: description,
+3 -3
View File
@@ -30,7 +30,7 @@ var CmdLabelDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error {
func runLabelDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -43,12 +43,12 @@ func runLabelDelete(_ stdctx.Context, cmd *cli.Command) error {
client := ctx.Login.Client()
// Verify the label exists first
label, _, err := client.GetRepoLabel(ctx.Owner, ctx.Repo, labelID)
label, _, err := client.Repositories.GetRepoLabel(requestCtx, ctx.Owner, ctx.Repo, labelID)
if err != nil {
return fmt.Errorf("failed to get label %d: %w", labelID, err)
}
_, err = client.DeleteLabel(ctx.Owner, ctx.Repo, labelID)
_, err = client.Repositories.DeleteLabel(requestCtx, ctx.Owner, ctx.Repo, labelID)
if err != nil {
return fmt.Errorf("failed to delete label '%s' (id: %d): %w", label.Name, labelID, err)
}
+3 -3
View File
@@ -6,7 +6,7 @@ package labels
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -35,7 +35,7 @@ var CmdLabelsList = cli.Command{
}
// RunLabelsList list labels.
func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error {
func RunLabelsList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -45,7 +45,7 @@ func RunLabelsList(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
labels, _, err := client.Repositories.ListRepoLabels(requestCtx, ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+3 -3
View File
@@ -6,7 +6,7 @@ package labels
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -40,7 +40,7 @@ var CmdLabelUpdate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error {
func runLabelUpdate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -66,7 +66,7 @@ func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error {
pDescription = &description
}
_, _, err = ctx.Login.Client().EditLabel(ctx.Owner, ctx.Repo, id, gitea.EditLabelOption{
_, _, err = ctx.Login.Client().Repositories.EditLabel(requestCtx, ctx.Owner, ctx.Repo, id, gitea.EditLabelOption{
Name: pName,
Color: pColor,
Description: pDescription,
+4 -3
View File
@@ -110,10 +110,10 @@ var CmdLoginAdd = cli.Command{
Action: runLoginAdd,
}
func runLoginAdd(_ context.Context, cmd *cli.Command) error {
func runLoginAdd(requestCtx context.Context, cmd *cli.Command) error {
// if no args create login interactive
if cmd.NumFlags() == 0 {
if err := interact.CreateLogin(); err != nil && !interact.IsQuitting(err) {
if err := interact.CreateLogin(requestCtx); err != nil && !interact.IsQuitting(err) {
return fmt.Errorf("error adding login: %w", err)
}
return nil
@@ -137,7 +137,7 @@ func runLoginAdd(_ context.Context, cmd *cli.Command) error {
opts.RedirectURL = cmd.String("redirect-url")
}
return auth.OAuthLoginWithFullOptions(opts)
return auth.OAuthLoginWithFullOptions(requestCtx, opts)
}
sshAgent := false
@@ -147,6 +147,7 @@ func runLoginAdd(_ context.Context, cmd *cli.Command) error {
// else use args to add login
return task.CreateLogin(
requestCtx,
cmd.String("name"),
cmd.String("token"),
cmd.String("user"),
+1 -1
View File
@@ -23,7 +23,7 @@ var CmdLoginSetDefault = cli.Command{
Flags: []cli.Flag{&flags.OutputFlag},
}
func runLoginSetDefault(_ context.Context, cmd *cli.Command) error {
func runLoginSetDefault(requestCtx context.Context, cmd *cli.Command) error {
if cmd.Args().Len() == 0 {
l, err := config.GetDefaultLogin()
if err != nil {
+1 -1
View File
@@ -23,7 +23,7 @@ var CmdLoginDelete = cli.Command{
}
// RunLoginDelete runs the action of a login delete command
func RunLoginDelete(_ context.Context, cmd *cli.Command) error {
func RunLoginDelete(requestCtx context.Context, cmd *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
return err
+1 -1
View File
@@ -28,7 +28,7 @@ var CmdLoginEdit = cli.Command{
Flags: []cli.Flag{&flags.OutputFlag},
}
func runLoginEdit(_ context.Context, _ *cli.Command) error {
func runLoginEdit(requestCtx context.Context, _ *cli.Command) error {
ymlPath := config.GetConfigPath()
if e, ok := os.LookupEnv("EDITOR"); ok && e != "" {
cmd := exec.Command(e, ymlPath)
+3 -3
View File
@@ -29,14 +29,14 @@ var CmdLoginHelper = cli.Command{
Name: "store",
Description: "Command drops",
Aliases: []string{"erase"},
Action: func(_ context.Context, _ *cli.Command) error {
Action: func(requestCtx context.Context, _ *cli.Command) error {
return nil
},
},
{
Name: "setup",
Description: "Setup helper to tea authenticate",
Action: func(_ context.Context, _ *cli.Command) error {
Action: func(requestCtx context.Context, _ *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
return err
@@ -64,7 +64,7 @@ var CmdLoginHelper = cli.Command{
Usage: "Use a specific login",
},
},
Action: func(_ context.Context, cmd *cli.Command) error {
Action: func(requestCtx context.Context, cmd *cli.Command) error {
wants := map[string]string{}
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
+1 -1
View File
@@ -25,7 +25,7 @@ var CmdLoginList = cli.Command{
}
// RunLoginList list all logins
func RunLoginList(_ context.Context, cmd *cli.Command) error {
func RunLoginList(requestCtx context.Context, cmd *cli.Command) error {
logins, err := config.GetLogins()
if err != nil {
return err
+2 -2
View File
@@ -22,7 +22,7 @@ var CmdLoginOAuthRefresh = cli.Command{
Action: runLoginOAuthRefresh,
}
func runLoginOAuthRefresh(_ context.Context, cmd *cli.Command) error {
func runLoginOAuthRefresh(requestCtx context.Context, cmd *cli.Command) error {
var loginName string
// Get login name from args or use default
@@ -62,7 +62,7 @@ func runLoginOAuthRefresh(_ context.Context, cmd *cli.Command) error {
fmt.Printf("Token refresh failed: %s\n", err)
fmt.Println("Opening browser for re-authentication...")
if err := auth.ReauthenticateLogin(login); err != nil {
if err := auth.ReauthenticateLogin(requestCtx, login); err != nil {
return fmt.Errorf("re-authentication failed: %s", err)
}
+2 -2
View File
@@ -40,7 +40,7 @@ func runMilestones(ctx stdctx.Context, cmd *cli.Command) error {
return milestones.RunMilestonesList(ctx, cmd)
}
func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error {
func runMilestoneDetail(requestCtx stdctx.Context, cmd *cli.Command, name string) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -50,7 +50,7 @@ func runMilestoneDetail(_ stdctx.Context, cmd *cli.Command, name string) error {
}
client := ctx.Login.Client()
milestone, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, name)
milestone, _, err := client.Repositories.GetMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, name)
if err != nil {
return err
}
+4 -5
View File
@@ -8,7 +8,7 @@ import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/araddon/dateparse"
"github.com/urfave/cli/v3"
@@ -50,7 +50,7 @@ var CmdMilestonesCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
func runMilestonesCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -72,14 +72,13 @@ func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
}
if ctx.IsInteractiveMode() {
if err := interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo); err != nil && !interact.IsQuitting(err) {
if err := interact.CreateMilestone(requestCtx, ctx.Login, ctx.Owner, ctx.Repo); err != nil && !interact.IsQuitting(err) {
return err
}
return nil
}
return task.CreateMilestone(
ctx.Login,
return task.CreateMilestone(requestCtx, ctx.Login,
ctx.Owner,
ctx.Repo,
ctx.String("title"),
+2 -2
View File
@@ -23,7 +23,7 @@ var CmdMilestonesDelete = cli.Command{
Flags: flags.AllDefaultFlags,
}
func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error {
func deleteMilestone(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -33,6 +33,6 @@ func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
_, err = client.DeleteMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First())
_, err = client.Repositories.DeleteMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, ctx.Args().First())
return err
}
+10 -10
View File
@@ -8,7 +8,7 @@ import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
@@ -71,7 +71,7 @@ var CmdMilestoneRemoveIssue = cli.Command{
Flags: flags.AllDefaultFlags,
}
func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
func runMilestoneIssueList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -97,12 +97,12 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
milestone := ctx.Args().First()
// make sure milestone exist
_, _, err = client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestone)
_, _, err = client.Repositories.GetMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, milestone)
if err != nil {
return err
}
issues, _, err := client.ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
issues, _, err := client.Issues.ListRepoIssues(requestCtx, ctx.Owner, ctx.Repo, gitea.ListIssueOption{
ListOptions: flags.GetListOptions(cmd),
Milestones: []string{milestone},
Type: kind,
@@ -119,7 +119,7 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
return print.IssuesPullsList(issues, ctx.Output, fields)
}
func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
func runMilestoneIssueAdd(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -140,12 +140,12 @@ func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
}
// make sure milestone exist
mile, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, mileName)
mile, _, err := client.Repositories.GetMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, mileName)
if err != nil {
return fmt.Errorf("failed to get milestone '%s': %w", mileName, err)
}
_, _, err = client.EditIssue(ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
_, _, err = client.Issues.EditIssue(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
Milestone: &mile.ID,
})
if err != nil {
@@ -154,7 +154,7 @@ func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
return nil
}
func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
func runMilestoneIssueRemove(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -174,7 +174,7 @@ func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("invalid issue index '%s': %w", issueIndex, err)
}
issue, _, err := client.GetIssue(ctx.Owner, ctx.Repo, idx)
issue, _, err := client.Issues.GetIssue(requestCtx, ctx.Owner, ctx.Repo, idx)
if err != nil {
return fmt.Errorf("failed to get issue #%d: %w", idx, err)
}
@@ -188,7 +188,7 @@ func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
}
zero := int64(0)
_, _, err = client.EditIssue(ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
_, _, err = client.Issues.EditIssue(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
Milestone: &zero,
})
if err != nil {
+3 -3
View File
@@ -6,7 +6,7 @@ package milestones
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -39,7 +39,7 @@ var CmdMilestonesList = cli.Command{
}
// RunMilestonesList list milestones
func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
func RunMilestonesList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -62,7 +62,7 @@ func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
}
client := ctx.Login.Client()
milestones, _, err := client.ListRepoMilestones(ctx.Owner, ctx.Repo, gitea.ListMilestoneOption{
milestones, _, err := client.Repositories.ListMilestones(requestCtx, ctx.Owner, ctx.Repo, gitea.ListMilestoneOption{
ListOptions: flags.GetListOptions(cmd),
State: state,
})
+3 -3
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -28,7 +28,7 @@ var CmdMilestonesReopen = cli.Command{
Flags: flags.AllDefaultFlags,
}
func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
func editMilestoneStatus(requestCtx stdctx.Context, cmd *cli.Command, close bool) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -58,7 +58,7 @@ func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
State: &state,
Title: ms,
}
milestone, _, err := client.EditMilestoneByName(ctx.Owner, ctx.Repo, ms, opts)
milestone, _, err := client.Repositories.EditMilestoneByName(requestCtx, ctx.Owner, ctx.Repo, ms, opts)
if err != nil {
return err
}
+4 -4
View File
@@ -6,7 +6,7 @@ package notifications
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -59,7 +59,7 @@ func RunNotificationsList(ctx stdctx.Context, cmd *cli.Command) error {
}
// listNotifications will get the notifications based on status and subject type
func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
func listNotifications(requestCtx stdctx.Context, cmd *cli.Command, status []gitea.NotifyStatus, subjects []gitea.NotifySubjectType) error {
var news []*gitea.NotificationThread
var err error
@@ -87,7 +87,7 @@ func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.Notify
fields = append(fields, "repository")
}
news, _, err = client.ListNotifications(gitea.ListNotificationOptions{
news, _, err = client.Notifications.List(requestCtx, gitea.ListNotificationOptions{
ListOptions: listOpts,
Status: status,
SubjectTypes: subjects,
@@ -96,7 +96,7 @@ func listNotifications(_ stdctx.Context, cmd *cli.Command, status []gitea.Notify
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
news, _, err = client.ListRepoNotifications(ctx.Owner, ctx.Repo, gitea.ListNotificationOptions{
news, _, err = client.Notifications.ListByRepo(requestCtx, ctx.Owner, ctx.Repo, gitea.ListNotificationOptions{
ListOptions: listOpts,
Status: status,
SubjectTypes: subjects,
+14 -14
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
@@ -23,7 +23,7 @@ var CmdNotificationsMarkRead = cli.Command{
Description: "Mark all filtered or a specific notification as read",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
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
@@ -35,7 +35,7 @@ var CmdNotificationsMarkRead = cli.Command{
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusUnread)}
}
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
return markNotificationAs(requestCtx, ctx, filter, gitea.NotifyStatusRead)
},
}
@@ -47,7 +47,7 @@ var CmdNotificationsMarkUnread = cli.Command{
Description: "Mark all filtered or a specific notification as unread",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
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
@@ -59,7 +59,7 @@ var CmdNotificationsMarkUnread = cli.Command{
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusRead)}
}
return markNotificationAs(ctx, filter, gitea.NotifyStatusUnread)
return markNotificationAs(requestCtx, ctx, filter, gitea.NotifyStatusUnread)
},
}
@@ -71,7 +71,7 @@ var CmdNotificationsMarkPinned = cli.Command{
Description: "Mark all filtered or a specific notification as pinned",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
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
@@ -83,7 +83,7 @@ var CmdNotificationsMarkPinned = cli.Command{
if !ctx.IsSet(flags.NotificationStateFlag.Name) {
filter = []string{string(gitea.NotifyStatusUnread)}
}
return markNotificationAs(ctx, filter, gitea.NotifyStatusPinned)
return markNotificationAs(requestCtx, ctx, filter, gitea.NotifyStatusPinned)
},
}
@@ -94,18 +94,18 @@ var CmdNotificationsUnpin = cli.Command{
Description: "Marks all pinned or a specific notification as read",
ArgsUsage: "[all | <notification id>]",
Flags: flags.NotificationFlags,
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
}
filter := []string{string(gitea.NotifyStatusPinned)}
// NOTE: we implicitly mark it as read, to match web UI semantics. marking as unread might be more useful?
return markNotificationAs(ctx, filter, gitea.NotifyStatusRead)
return markNotificationAs(requestCtx, ctx, filter, gitea.NotifyStatusRead)
},
}
func markNotificationAs(cmd *context.TeaContext, filterStates []string, targetState gitea.NotifyStatus) (err error) {
func markNotificationAs(ctx stdctx.Context, cmd *context.TeaContext, filterStates []string, targetState gitea.NotifyStatus) (err error) {
client := cmd.Login.Client()
subject := cmd.Args().First()
allRepos := cmd.Bool("mine")
@@ -120,12 +120,12 @@ func markNotificationAs(cmd *context.TeaContext, filterStates []string, targetSt
opts := gitea.MarkNotificationOptions{Status: states, ToStatus: targetState}
if allRepos {
_, _, err = client.ReadNotifications(opts)
_, _, err = client.Notifications.MarkRead(ctx, opts)
} else {
if err := cmd.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
return err
}
_, _, err = client.ReadRepoNotifications(cmd.Owner, cmd.Repo, opts)
_, _, err = client.Notifications.MarkReadByRepo(ctx, cmd.Owner, cmd.Repo, opts)
}
// TODO: print all affected notification subject URLs
@@ -136,12 +136,12 @@ func markNotificationAs(cmd *context.TeaContext, filterStates []string, targetSt
if err != nil {
return err
}
_, _, err = client.ReadNotification(id, targetState)
_, _, err = client.Notifications.MarkReadByID(ctx, id, targetState)
if err != nil {
return err
}
n, _, err := client.GetNotification(id)
n, _, err := client.Notifications.GetByID(ctx, id)
if err != nil {
return err
}
+1 -1
View File
@@ -27,7 +27,7 @@ var CmdOpen = cli.Command{
Flags: append([]cli.Flag{}, flags.LoginRepoFlags...),
}
func runOpen(_ stdctx.Context, cmd *cli.Command) error {
func runOpen(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
+7 -11
View File
@@ -36,17 +36,13 @@ func runOrganizations(ctx stdctx.Context, cmd *cli.Command) error {
return err
}
if teaCtx.Args().Len() == 1 {
return runOrganizationDetail(teaCtx)
org, _, err := teaCtx.Login.Client().Organizations.GetOrg(ctx, teaCtx.Args().First())
if err != nil {
return err
}
print.OrganizationDetails(org)
return nil
}
return organizations.RunOrganizationList(ctx, cmd)
}
func runOrganizationDetail(ctx *context.TeaContext) error {
org, _, err := ctx.Login.Client().GetOrg(ctx.Args().First())
if err != nil {
return err
}
print.OrganizationDetails(org)
return nil
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -53,7 +53,7 @@ var CmdOrganizationCreate = cli.Command{
}
// RunOrganizationCreate sets up a new organization
func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error {
func RunOrganizationCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -75,7 +75,7 @@ func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("unknown visibility '%s'", ctx.String("visibility"))
}
org, _, err := ctx.Login.Client().CreateOrg(gitea.CreateOrgOption{
org, _, err := ctx.Login.Client().Organizations.CreateOrg(requestCtx, gitea.CreateOrgOption{
Name: ctx.Args().First(),
FullName: ctx.String("full-name"),
Description: ctx.String("description"),
+2 -2
View File
@@ -28,7 +28,7 @@ var CmdOrganizationDelete = cli.Command{
}
// RunOrganizationDelete delete user organization
func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error {
func RunOrganizationDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -40,7 +40,7 @@ func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error {
return fmt.Errorf("organization name is required")
}
response, err := client.DeleteOrg(ctx.Args().First())
response, err := client.Organizations.DeleteOrg(requestCtx, ctx.Args().First())
if response != nil && response.StatusCode == 404 {
return fmt.Errorf("organization not found: %s", ctx.Args().First())
}
+3 -3
View File
@@ -6,7 +6,7 @@ package organizations
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
@@ -29,14 +29,14 @@ var CmdOrganizationList = cli.Command{
}
// RunOrganizationList list user organizations
func RunOrganizationList(_ stdctx.Context, cmd *cli.Command) error {
func RunOrganizationList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
client := ctx.Login.Client()
userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{
userOrganizations, _, err := client.Organizations.ListUserOrgs(requestCtx, ctx.Login.User, gitea.ListOrgsOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+9 -9
View File
@@ -8,7 +8,7 @@ import (
"fmt"
"time"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/cmd/pulls"
@@ -91,7 +91,7 @@ func runPulls(ctx stdctx.Context, cmd *cli.Command) error {
return pulls.RunPullsList(ctx, cmd)
}
func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
func runPullDetail(requestCtx stdctx.Context, cmd *cli.Command, index string) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -105,14 +105,14 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
}
client := ctx.Login.Client()
pr, _, err := client.GetPullRequest(ctx.Owner, ctx.Repo, idx)
pr, _, err := client.PullRequests.GetPullRequest(requestCtx, ctx.Owner, ctx.Repo, idx)
if err != nil {
return err
}
var reviews []*gitea.PullReview
for page := 1; ; {
page_reviews, resp, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
page_reviews, resp, err := client.PullRequests.ListPullReviews(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
})
if err != nil {
@@ -129,11 +129,11 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
if ctx.IsSet("output") {
switch ctx.String("output") {
case "json":
return runPullDetailAsJSON(ctx, pr, reviews)
return runPullDetailAsJSON(requestCtx, ctx, pr, reviews)
}
}
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 while loading CI: %v\n", err)
}
@@ -141,7 +141,7 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
print.PullDetails(pr, reviews, ci)
if pr.Comments > 0 {
err = interact.ShowCommentsMaybeInteractive(ctx, idx, pr.Comments)
err = interact.ShowCommentsMaybeInteractive(requestCtx, ctx, idx, pr.Comments)
if err != nil {
fmt.Printf("error loading comments: %v\n", err)
}
@@ -150,7 +150,7 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
return nil
}
func runPullDetailAsJSON(ctx *context.TeaContext, pr *gitea.PullRequest, reviews []*gitea.PullReview) error {
func runPullDetailAsJSON(requestCtx stdctx.Context, ctx *context.TeaContext, pr *gitea.PullRequest, reviews []*gitea.PullReview) error {
c := ctx.Login.Client()
opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)}
@@ -185,7 +185,7 @@ func runPullDetailAsJSON(ctx *context.TeaContext, pr *gitea.PullRequest, reviews
}
if ctx.Bool("comments") {
comments, _, err := c.ListIssueComments(ctx.Owner, ctx.Repo, pr.Index, opts)
comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, pr.Index, opts)
if err != nil {
return err
}
+3 -3
View File
@@ -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,
}
+2 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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"
+2 -2
View File
@@ -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
View File
@@ -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
}
}
+2 -2
View File
@@ -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
}
+6 -5
View File
@@ -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)
}
+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 != "" {
+2 -2
View File
@@ -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,
}
+4 -4
View File
@@ -10,7 +10,7 @@ import (
"os"
"path/filepath"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -67,7 +67,7 @@ var CmdReleaseCreate = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error {
func runReleaseCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -94,7 +94,7 @@ func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error {
notestring = string(notebytes)
}
release, resp, err := ctx.Login.Client().CreateRelease(ctx.Owner, ctx.Repo, gitea.CreateReleaseOption{
release, resp, err := ctx.Login.Client().Releases.CreateRelease(requestCtx, ctx.Owner, ctx.Repo, gitea.CreateReleaseOption{
TagName: tag,
Target: ctx.String("target"),
Title: ctx.String("title"),
@@ -118,7 +118,7 @@ func runReleaseCreate(_ stdctx.Context, cmd *cli.Command) error {
filePath := filepath.Base(asset)
if _, _, err = ctx.Login.Client().CreateReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
if _, _, err = ctx.Login.Client().Releases.CreateReleaseAttachment(requestCtx, ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
file.Close()
return err
}
+4 -4
View File
@@ -34,7 +34,7 @@ var CmdReleaseDelete = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error {
func runReleaseDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -55,17 +55,17 @@ func runReleaseDelete(_ stdctx.Context, cmd *cli.Command) error {
}
for _, tag := range ctx.Args().Slice() {
release, err := GetReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
release, err := GetReleaseByTag(requestCtx, ctx.Owner, ctx.Repo, tag, client)
if err != nil {
return err
}
_, err = client.DeleteRelease(ctx.Owner, ctx.Repo, release.ID)
_, err = client.Releases.DeleteRelease(requestCtx, ctx.Owner, ctx.Repo, release.ID)
if err != nil {
return err
}
if ctx.Bool("delete-tag") {
_, err = client.DeleteTag(ctx.Owner, ctx.Repo, tag)
_, err = client.Repositories.DeleteTag(requestCtx, ctx.Owner, ctx.Repo, tag)
return err
}
}
+4 -4
View File
@@ -9,7 +9,7 @@ import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
@@ -58,7 +58,7 @@ var CmdReleaseEdit = cli.Command{
}, flags.AllDefaultFlags...),
}
func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error {
func runReleaseEdit(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -82,12 +82,12 @@ func runReleaseEdit(_ stdctx.Context, cmd *cli.Command) error {
}
for _, tag := range ctx.Args().Slice() {
release, err := GetReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
release, err := GetReleaseByTag(requestCtx, ctx.Owner, ctx.Repo, tag, client)
if err != nil {
return err
}
_, _, err = client.EditRelease(ctx.Owner, ctx.Repo, release.ID, gitea.EditReleaseOption{
_, _, err = client.Releases.EditRelease(requestCtx, ctx.Owner, ctx.Repo, release.ID, gitea.EditReleaseOption{
TagName: ctx.String("tag"),
Target: ctx.String("target"),
Title: ctx.String("title"),
+3 -3
View File
@@ -6,7 +6,7 @@ package releases
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -29,7 +29,7 @@ var CmdReleaseList = cli.Command{
}
// RunReleasesList list releases
func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error {
func RunReleasesList(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -38,7 +38,7 @@ func RunReleasesList(_ stdctx.Context, cmd *cli.Command) error {
return err
}
releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{
releases, _, err := ctx.Login.Client().Releases.ListReleases(requestCtx, ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{
ListOptions: flags.GetListOptions(cmd),
})
if err != nil {
+4 -3
View File
@@ -4,15 +4,16 @@
package releases
import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
)
// GetReleaseByTag finds a release by its tag name.
func GetReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) {
func GetReleaseByTag(ctx stdctx.Context, owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) {
for page := 1; ; {
rl, resp, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{
rl, resp, err := client.Releases.ListReleases(ctx, owner, repo, gitea.ListReleasesOptions{
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
})
if err != nil {
+4 -4
View File
@@ -6,7 +6,7 @@ package cmd
import (
stdctx "context"
"code.gitea.io/sdk/gitea"
gitea "gitea.dev/sdk"
"gitea.dev/tea/cmd/repos"
"gitea.dev/tea/modules/context"
@@ -44,18 +44,18 @@ func runRepos(ctx stdctx.Context, cmd *cli.Command) error {
return repos.RunReposList(ctx, cmd)
}
func runRepoDetail(_ stdctx.Context, cmd *cli.Command, path string) error {
func runRepoDetail(requestCtx stdctx.Context, cmd *cli.Command, path string) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
}
client := ctx.Login.Client()
repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner)
repo, _, err := client.GetRepo(repoOwner, repoName)
repo, _, err := client.Repositories.GetRepo(requestCtx, repoOwner, repoName)
if err != nil {
return err
}
topics, _, err := client.ListRepoTopics(repoOwner, repoName, gitea.ListRepoTopicsOptions{})
topics, _, err := client.Repositories.ListRepoTopics(requestCtx, repoOwner, repoName, gitea.ListRepoTopicsOptions{})
if err != nil {
return err
}
+5 -5
View File
@@ -7,7 +7,7 @@ import (
stdctx "context"
"fmt"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"gitea.dev/tea/cmd/flags"
"gitea.dev/tea/modules/context"
@@ -102,7 +102,7 @@ var CmdRepoCreate = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoCreate(_ stdctx.Context, cmd *cli.Command) error {
func runRepoCreate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -141,15 +141,15 @@ func runRepoCreate(_ stdctx.Context, cmd *cli.Command) error {
ObjectFormatName: ctx.String("object-format"),
}
if len(ctx.String("owner")) != 0 {
repo, _, err = client.CreateOrgRepo(ctx.String("owner"), opts)
repo, _, err = client.Repositories.CreateOrgRepo(requestCtx, ctx.String("owner"), opts)
} else {
repo, _, err = client.CreateRepo(opts)
repo, _, err = client.Repositories.CreateRepo(requestCtx, opts)
}
if err != nil {
return err
}
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
topics, _, err := client.Repositories.ListRepoTopics(requestCtx, repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
if err != nil {
return err
}
+4 -4
View File
@@ -8,7 +8,7 @@ import (
stdctx "context"
"code.gitea.io/sdk/gitea"
"gitea.dev/sdk"
"github.com/urfave/cli/v3"
"gitea.dev/tea/cmd/flags"
@@ -83,7 +83,7 @@ var CmdRepoCreateFromTemplate = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoCreateFromTemplate(_ stdctx.Context, cmd *cli.Command) error {
func runRepoCreateFromTemplate(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -109,12 +109,12 @@ func runRepoCreateFromTemplate(_ stdctx.Context, cmd *cli.Command) error {
Webhooks: ctx.Bool("webhooks"),
}
repo, _, err := client.CreateRepoFromTemplate(templateOwner, templateRepo, opts)
repo, _, err := client.Repositories.CreateRepoFromTemplate(requestCtx, templateOwner, templateRepo, opts)
if err != nil {
return err
}
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
topics, _, err := client.Repositories.ListRepoTopics(requestCtx, repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
if err != nil {
return err
}
+2 -2
View File
@@ -45,7 +45,7 @@ var CmdRepoRm = cli.Command{
}, flags.LoginOutputFlags...),
}
func runRepoDelete(_ stdctx.Context, cmd *cli.Command) error {
func runRepoDelete(requestCtx stdctx.Context, cmd *cli.Command) error {
ctx, err := context.InitCommand(cmd)
if err != nil {
return err
@@ -79,7 +79,7 @@ func runRepoDelete(_ stdctx.Context, cmd *cli.Command) error {
}
}
_, err = client.DeleteRepo(owner, repoName)
_, err = client.Repositories.DeleteRepo(requestCtx, owner, repoName)
if err != nil {
return err
}

Some files were not shown because too many files have changed in this diff Show More