diff --git a/.gitea/workflows/release-nightly.yml b/.gitea/workflows/release-nightly.yml index 49e3a281..be23e74d 100644 --- a/.gitea/workflows/release-nightly.yml +++ b/.gitea/workflows/release-nightly.yml @@ -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: diff --git a/.gitea/workflows/release-tag.yml b/.gitea/workflows/release-tag.yml index 49d9f2b4..6e0b731f 100644 --- a/.gitea/workflows/release-tag.yml +++ b/.gitea/workflows/release-tag.yml @@ -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: diff --git a/.gitea/workflows/test-pr.yml b/.gitea/workflows/test-pr.yml index a9573c91..5cc76505 100644 --- a/.gitea/workflows/test-pr.yml +++ b/.gitea/workflows/test-pr.yml @@ -51,7 +51,7 @@ jobs: make integration-test services: gitea: - image: docker.gitea.com/gitea:1.26.1 + image: docker.gitea.com/gitea:1.26.2 cmd: - bash - -c diff --git a/.goreleaser.yaml b/.goreleaser.yaml index cdab207b..35546017 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -56,7 +56,7 @@ builds: flags: - -trimpath ldflags: - - -s -w -X "code.gitea.io/tea/modules/version.Version={{ trimprefix .Summary "v" }}" -X "code.gitea.io/tea/modules/version.Tags=" -X "code.gitea.io/tea/modules/version.SDK={{ .Env.SDK_VERSION }}" + - -s -w -X "gitea.dev/tea/modules/version.Version={{ trimprefix .Summary "v" }}" -X "gitea.dev/tea/modules/version.Tags=" -X "gitea.dev/tea/modules/version.SDK={{ .Env.SDK_VERSION }}" binary: >- {{ .ProjectName }}- {{- .Version }}- diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3705272c..a762dd2a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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" diff --git a/Makefile b/Makefile index 31ff016a..6eaa2ae2 100644 --- a/Makefile +++ b/Makefile @@ -24,16 +24,17 @@ endif TEA_VERSION_TAG ?= $(shell sed 's/+/_/' <<< $(TEA_VERSION)) TAGS ?= -SDK ?= $(shell $(GO) list -f '{{.Version}}' -m code.gitea.io/sdk/gitea) -LDFLAGS := -X "code.gitea.io/tea/modules/version.Version=$(TEA_VERSION)" -X "code.gitea.io/tea/modules/version.Tags=$(TAGS)" -X "code.gitea.io/tea/modules/version.SDK=$(SDK)" -s -w +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 override GOFLAGS := $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -PACKAGES ?= $(shell $(GO) list ./... | grep -v '^code.gitea.io/tea/tests') +PACKAGES ?= $(shell $(GO) list ./... | grep -v '^gitea.dev/tea/tests') UNIT_PACKAGES ?= $(PACKAGES) INTEGRATION_PACKAGES ?= $(shell $(GO) list ./tests/... 2>/dev/null) INTEGRATION_TEST_TAGS ?= testtools +INTEGRATION_TEST_GOFLAGS ?= -v SOURCES ?= $(shell find . -name "*.go" -type f) # OS specific vars. @@ -103,7 +104,7 @@ unit-test: .PHONY: integration-test integration-test: @if [ -n "$(INTEGRATION_PACKAGES)" ]; then \ - $(GO) test -tags='$(INTEGRATION_TEST_TAGS)' $(INTEGRATION_PACKAGES); \ + $(GO) test $(INTEGRATION_TEST_GOFLAGS) -tags='$(INTEGRATION_TEST_TAGS)' $(INTEGRATION_PACKAGES); \ else \ echo "No integration test packages found"; \ fi diff --git a/README.md b/README.md index 6ca016db..2293b841 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) [![Release](https://raster.shields.io/badge/dynamic/json.svg?label=release&url=https://gitea.com/api/v1/repos/gitea/tea/releases&query=$[0].tag_name)](https://gitea.com/gitea/tea/releases) [![Join the chat at https://img.shields.io/discord/322538954119184384.svg](https://img.shields.io/discord/322538954119184384.svg)](https://discord.gg/Gitea) -[![Go Report Card](https://goreportcard.com/badge/code.gitea.io/tea)](https://goreportcard.com/report/code.gitea.io/tea) [![GoDoc](https://pkg.go.dev/badge/code.gitea.io/tea?status.svg)](https://godoc.org/code.gitea.io/tea) +[![Go Report Card](https://goreportcard.com/badge/gitea.dev/tea)](https://goreportcard.com/report/gitea.dev/tea) [![GoDoc](https://pkg.go.dev/badge/gitea.dev/tea?status.svg)](https://godoc.org/gitea.dev/tea) ![Tea Release Status](https://gitea.com/gitea/tea/actions/workflows/release-nightly.yml/badge.svg) ## The official CLI for Gitea @@ -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 @@ -186,7 +186,7 @@ Make sure you have a current Go version installed (1.26 or newer). - For a quick installation without `git` & `make`, set $version and exec: ```sh - go install code.gitea.io/tea@${version} + go install gitea.dev/tea@${version} ``` ## Contributing diff --git a/cmd/actions.go b/cmd/actions.go index df5b2830..447949c5 100644 --- a/cmd/actions.go +++ b/cmd/actions.go @@ -6,7 +6,7 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/actions" + "gitea.dev/tea/cmd/actions" "github.com/urfave/cli/v3" ) diff --git a/cmd/actions/runs.go b/cmd/actions/runs.go index 10130cfc..0b34d690 100644 --- a/cmd/actions/runs.go +++ b/cmd/actions/runs.go @@ -6,7 +6,7 @@ package actions import ( stdctx "context" - "code.gitea.io/tea/cmd/actions/runs" + "gitea.dev/tea/cmd/actions/runs" "github.com/urfave/cli/v3" ) diff --git a/cmd/actions/runs/delete.go b/cmd/actions/runs/delete.go index 6ca69545..310afedd 100644 --- a/cmd/actions/runs/delete.go +++ b/cmd/actions/runs/delete.go @@ -8,8 +8,8 @@ import ( "fmt" "strconv" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/actions/runs/list.go b/cmd/actions/runs/list.go index 73dba888..40f6fc1c 100644 --- a/cmd/actions/runs/list.go +++ b/cmd/actions/runs/list.go @@ -8,11 +8,11 @@ import ( "fmt" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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"), diff --git a/cmd/actions/runs/list_test.go b/cmd/actions/runs/list_test.go index 1486e54f..82258996 100644 --- a/cmd/actions/runs/list_test.go +++ b/cmd/actions/runs/list_test.go @@ -4,15 +4,15 @@ package runs import ( - stdctx "context" "os" "testing" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" + gitea "gitea.dev/sdk" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/config" ) func TestFilterRunsByTime(t *testing.T) { @@ -106,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") } diff --git a/cmd/actions/runs/logs.go b/cmd/actions/runs/logs.go index bebcf636..f6b4735b 100644 --- a/cmd/actions/runs/logs.go +++ b/cmd/actions/runs/logs.go @@ -9,10 +9,10 @@ import ( "strconv" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/actions/runs/view.go b/cmd/actions/runs/view.go index 9bba2046..efd4dfa6 100644 --- a/cmd/actions/runs/view.go +++ b/cmd/actions/runs/view.go @@ -8,11 +8,10 @@ import ( "fmt" "strconv" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - - "code.gitea.io/sdk/gitea" + gitea "gitea.dev/sdk" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/actions/secrets.go b/cmd/actions/secrets.go index f00ec1ad..0380de39 100644 --- a/cmd/actions/secrets.go +++ b/cmd/actions/secrets.go @@ -6,7 +6,7 @@ package actions import ( stdctx "context" - "code.gitea.io/tea/cmd/actions/secrets" + "gitea.dev/tea/cmd/actions/secrets" "github.com/urfave/cli/v3" ) diff --git a/cmd/actions/secrets/create.go b/cmd/actions/secrets/create.go index 26e40e1a..1f070844 100644 --- a/cmd/actions/secrets/create.go +++ b/cmd/actions/secrets/create.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/actions/secrets/delete.go b/cmd/actions/secrets/delete.go index 60d721e2..2bd555a1 100644 --- a/cmd/actions/secrets/delete.go +++ b/cmd/actions/secrets/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/actions/secrets/list.go b/cmd/actions/secrets/list.go index 0903e2e8..0a698ba7 100644 --- a/cmd/actions/secrets/list.go +++ b/cmd/actions/secrets/list.go @@ -6,11 +6,11 @@ package secrets import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/actions/secrets/list_test.go b/cmd/actions/secrets/list_test.go index 86608301..063229b2 100644 --- a/cmd/actions/secrets/list_test.go +++ b/cmd/actions/secrets/list_test.go @@ -4,13 +4,13 @@ package secrets import ( - stdctx "context" "os" "testing" - "code.gitea.io/tea/modules/config" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/config" ) func TestSecretsListFlags(t *testing.T) { @@ -93,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") } diff --git a/cmd/actions/variables.go b/cmd/actions/variables.go index 061da4de..6e6c723f 100644 --- a/cmd/actions/variables.go +++ b/cmd/actions/variables.go @@ -6,7 +6,7 @@ package actions import ( stdctx "context" - "code.gitea.io/tea/cmd/actions/variables" + "gitea.dev/tea/cmd/actions/variables" "github.com/urfave/cli/v3" ) diff --git a/cmd/actions/variables/delete.go b/cmd/actions/variables/delete.go index f3483749..0db6e0c8 100644 --- a/cmd/actions/variables/delete.go +++ b/cmd/actions/variables/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/actions/variables/list.go b/cmd/actions/variables/list.go index fe5ecb7d..d3b2c96c 100644 --- a/cmd/actions/variables/list.go +++ b/cmd/actions/variables/list.go @@ -7,9 +7,9 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/actions/variables/list_test.go b/cmd/actions/variables/list_test.go index 396487ae..6d018574 100644 --- a/cmd/actions/variables/list_test.go +++ b/cmd/actions/variables/list_test.go @@ -4,13 +4,13 @@ package variables import ( - stdctx "context" "os" "testing" - "code.gitea.io/tea/modules/config" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/config" ) func TestVariablesListFlags(t *testing.T) { @@ -93,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") } diff --git a/cmd/actions/variables/set.go b/cmd/actions/variables/set.go index 9f2c5685..d808771d 100644 --- a/cmd/actions/variables/set.go +++ b/cmd/actions/variables/set.go @@ -8,9 +8,9 @@ import ( "fmt" "regexp" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/actions/workflows.go b/cmd/actions/workflows.go index 1dc593a5..a7e692d7 100644 --- a/cmd/actions/workflows.go +++ b/cmd/actions/workflows.go @@ -6,7 +6,7 @@ package actions import ( stdctx "context" - "code.gitea.io/tea/cmd/actions/workflows" + "gitea.dev/tea/cmd/actions/workflows" "github.com/urfave/cli/v3" ) diff --git a/cmd/actions/workflows/disable.go b/cmd/actions/workflows/disable.go index b707ca9d..8ed5b0d3 100644 --- a/cmd/actions/workflows/disable.go +++ b/cmd/actions/workflows/disable.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/actions/workflows/dispatch.go b/cmd/actions/workflows/dispatch.go index 2d241710..7d28b235 100644 --- a/cmd/actions/workflows/dispatch.go +++ b/cmd/actions/workflows/dispatch.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 diff --git a/cmd/actions/workflows/enable.go b/cmd/actions/workflows/enable.go index 7ca3af16..dbe2e1e4 100644 --- a/cmd/actions/workflows/enable.go +++ b/cmd/actions/workflows/enable.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/actions/workflows/list.go b/cmd/actions/workflows/list.go index a661cbc2..31a88646 100644 --- a/cmd/actions/workflows/list.go +++ b/cmd/actions/workflows/list.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/actions/workflows/view.go b/cmd/actions/workflows/view.go index d05901f1..0d86de47 100644 --- a/cmd/actions/workflows/view.go +++ b/cmd/actions/workflows/view.go @@ -7,9 +7,9 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/admin.go b/cmd/admin.go index 728cad75..306226be 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -6,10 +6,11 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/admin/users" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/admin/users" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) // CmdAdmin represents the namespace of admin commands. @@ -19,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{ @@ -46,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 } diff --git a/cmd/admin/users/create.go b/cmd/admin/users/create.go index 5630587c..f685639e 100644 --- a/cmd/admin/users/create.go +++ b/cmd/admin/users/create.go @@ -11,11 +11,11 @@ import ( "strings" "syscall" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" "golang.org/x/term" ) @@ -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) } diff --git a/cmd/admin/users/delete.go b/cmd/admin/users/delete.go index d0df7ee8..f0dcc90a 100644 --- a/cmd/admin/users/delete.go +++ b/cmd/admin/users/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/admin/users/edit.go b/cmd/admin/users/edit.go index 169939df..fa1475ee 100644 --- a/cmd/admin/users/edit.go +++ b/cmd/admin/users/edit.go @@ -11,11 +11,10 @@ import ( "strings" "syscall" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - - "code.gitea.io/sdk/gitea" + gitea "gitea.dev/sdk" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" "golang.org/x/term" ) @@ -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) } diff --git a/cmd/admin/users/list.go b/cmd/admin/users/list.go index 65c545ee..715d25af 100644 --- a/cmd/admin/users/list.go +++ b/cmd/admin/users/list.go @@ -6,11 +6,11 @@ package users import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/admin/users/shared.go b/cmd/admin/users/shared.go index e03f89bf..5abbaec5 100644 --- a/cmd/admin/users/shared.go +++ b/cmd/admin/users/shared.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) func parseUserVisibility(visibility string) (*gitea.VisibleType, error) { diff --git a/cmd/api.go b/cmd/api.go index 12c7feb2..6c5c22a5 100644 --- a/cmd/api.go +++ b/cmd/api.go @@ -13,9 +13,9 @@ import ( "strconv" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/api" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/api" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" "golang.org/x/term" @@ -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 diff --git a/cmd/api_test.go b/cmd/api_test.go index 87b242ee..8e92b5e0 100644 --- a/cmd/api_test.go +++ b/cmd/api_test.go @@ -8,16 +8,14 @@ import ( "encoding/json" "io" "os" + "os/exec" "path/filepath" "testing" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - tea_git "code.gitea.io/tea/modules/git" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + tea_git "gitea.dev/tea/modules/git" - gogit "github.com/go-git/go-git/v5" - "github.com/go-git/go-git/v5/plumbing" - "github.com/go-git/go-git/v5/plumbing/object" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" @@ -298,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 } @@ -572,33 +570,32 @@ func TestExpandPlaceholders(t *testing.T) { t.Run("replaces branch from local repo HEAD", func(t *testing.T) { tmpDir := t.TempDir() - repo, err := gogit.PlainInit(tmpDir, false) - require.NoError(t, err) + runGit := func(args ...string) { + cmd := exec.Command("git", args...) + cmd.Dir = tmpDir + require.NoError(t, cmd.Run()) + } + + runGit("init") + runGit("config", "user.email", "test@test.com") + runGit("config", "user.name", "test") // Create an initial commit so HEAD points to a branch. - wt, err := repo.Worktree() - require.NoError(t, err) tmpFile := filepath.Join(tmpDir, "init.txt") require.NoError(t, os.WriteFile(tmpFile, []byte("init"), 0o644)) - _, err = wt.Add("init.txt") - require.NoError(t, err) - _, err = wt.Commit("initial commit", &gogit.CommitOptions{ - Author: &object.Signature{Name: "test", Email: "test@test.com"}, - }) - require.NoError(t, err) + runGit("add", "init.txt") + runGit("commit", "-m", "initial commit") // Create and checkout a feature branch. - headRef, err := repo.Head() + runGit("checkout", "-b", "feature/my-branch") + + repo, err := tea_git.RepoFromPath(tmpDir) require.NoError(t, err) - branchRef := plumbing.NewBranchReferenceName("feature/my-branch") - ref := plumbing.NewHashReference(branchRef, headRef.Hash()) - require.NoError(t, repo.Storer.SetReference(ref)) - require.NoError(t, wt.Checkout(&gogit.CheckoutOptions{Branch: branchRef})) ctx := &context.TeaContext{ Owner: "alice", Repo: "proj", - LocalRepo: &tea_git.TeaRepo{Repository: repo}, + LocalRepo: repo, } result := expandPlaceholders("/repos/{owner}/{repo}/branches/{branch}", ctx) assert.Equal(t, "/repos/alice/proj/branches/feature/my-branch", result) diff --git a/cmd/attachments.go b/cmd/attachments.go index 154e1e52..52f14020 100644 --- a/cmd/attachments.go +++ b/cmd/attachments.go @@ -4,8 +4,8 @@ package cmd import ( - "code.gitea.io/tea/cmd/attachments" - "code.gitea.io/tea/cmd/flags" + "gitea.dev/tea/cmd/attachments" + "gitea.dev/tea/cmd/flags" "github.com/urfave/cli/v3" ) diff --git a/cmd/attachments/create.go b/cmd/attachments/create.go index 7f8eafed..d35c5646 100644 --- a/cmd/attachments/create.go +++ b/cmd/attachments/create.go @@ -9,9 +9,9 @@ import ( "os" "path/filepath" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/releases" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/releases" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/attachments/delete.go b/cmd/attachments/delete.go index b0182f0a..7a806a15 100644 --- a/cmd/attachments/delete.go +++ b/cmd/attachments/delete.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/releases" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/releases" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/attachments/list.go b/cmd/attachments/list.go index 1c91af36..4b512915 100644 --- a/cmd/attachments/list.go +++ b/cmd/attachments/list.go @@ -7,12 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/releases" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - - "code.gitea.io/sdk/gitea" + gitea "gitea.dev/sdk" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/releases" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/branches.go b/cmd/branches.go index 625b412c..6b646d6b 100644 --- a/cmd/branches.go +++ b/cmd/branches.go @@ -6,7 +6,7 @@ package cmd import ( "context" - "code.gitea.io/tea/cmd/branches" + "gitea.dev/tea/cmd/branches" "github.com/urfave/cli/v3" ) diff --git a/cmd/branches/list.go b/cmd/branches/list.go index a77389ca..6c559616 100644 --- a/cmd/branches/list.go +++ b/cmd/branches/list.go @@ -6,11 +6,11 @@ package branches import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/branches/protect.go b/cmd/branches/protect.go index 7b88a39f..84417fe4 100644 --- a/cmd/branches/protect.go +++ b/cmd/branches/protect.go @@ -7,10 +7,10 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/branches/rename.go b/cmd/branches/rename.go index bf99cec7..85a0935c 100644 --- a/cmd/branches/rename.go +++ b/cmd/branches/rename.go @@ -7,10 +7,10 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/clone.go b/cmd/clone.go index d65a5c22..c636a39f 100644 --- a/cmd/clone.go +++ b/cmd/clone.go @@ -7,14 +7,14 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/debug" - "code.gitea.io/tea/modules/git" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/debug" + "gitea.dev/tea/modules/git" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -88,6 +88,7 @@ func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error { } _, err = task.RepoClone( + ctx, dir, login, owner, diff --git a/cmd/cmd.go b/cmd/cmd.go index 0171b8ea..9bea3f39 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -2,13 +2,14 @@ // SPDX-License-Identifier: MIT // Tea is command line tool for Gitea. -package cmd // import "code.gitea.io/tea" +package cmd // import "gitea.dev/tea" import ( "fmt" - "code.gitea.io/tea/modules/version" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/version" ) // App creates and returns a tea Command with all subcommands set diff --git a/cmd/comment.go b/cmd/comment.go index cdccbe62..cbd6f8d7 100644 --- a/cmd/comment.go +++ b/cmd/comment.go @@ -10,14 +10,15 @@ import ( "io" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/theme" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/theme" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" "github.com/urfave/cli/v3" @@ -35,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 @@ -82,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 { diff --git a/cmd/detail_json.go b/cmd/detail_json.go index 7db03e0e..cde3c3fd 100644 --- a/cmd/detail_json.go +++ b/cmd/detail_json.go @@ -8,7 +8,7 @@ import ( "io" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) type detailLabelData struct { diff --git a/cmd/flags/csvflag.go b/cmd/flags/csvflag.go index a881f010..b3eb0972 100644 --- a/cmd/flags/csvflag.go +++ b/cmd/flags/csvflag.go @@ -7,8 +7,9 @@ import ( "fmt" "strings" - "code.gitea.io/tea/modules/utils" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/utils" ) // CsvFlag is a wrapper around cli.StringFlag, with an added GetValues() method diff --git a/cmd/flags/generic.go b/cmd/flags/generic.go index ee1362ff..adffd395 100644 --- a/cmd/flags/generic.go +++ b/cmd/flags/generic.go @@ -7,7 +7,7 @@ import ( "errors" "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/urfave/cli/v3" ) diff --git a/cmd/flags/generic_test.go b/cmd/flags/generic_test.go index 37d4a7f4..f98cc8c8 100644 --- a/cmd/flags/generic_test.go +++ b/cmd/flags/generic_test.go @@ -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"}) diff --git a/cmd/flags/issue_pr.go b/cmd/flags/issue_pr.go index 67a21e87..31a65c65 100644 --- a/cmd/flags/issue_pr.go +++ b/cmd/flags/issue_pr.go @@ -4,13 +4,15 @@ package flags import ( + stdctx "context" "fmt" "strings" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" "github.com/araddon/dateparse" "github.com/urfave/cli/v3" @@ -130,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"), @@ -154,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 } } @@ -163,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) } diff --git a/cmd/issues.go b/cmd/issues.go index 16da65af..7f3f4bea 100644 --- a/cmd/issues.go +++ b/cmd/issues.go @@ -8,13 +8,14 @@ import ( "fmt" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/issues" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/issues" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -37,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 @@ -78,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) { @@ -107,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 } @@ -120,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) } @@ -136,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 } diff --git a/cmd/issues/close.go b/cmd/issues/close.go index ea6f1b8c..3b24d668 100644 --- a/cmd/issues/close.go +++ b/cmd/issues/close.go @@ -7,12 +7,12 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/issues/create.go b/cmd/issues/create.go index d88ff2c2..8b0d7d53 100644 --- a/cmd/issues/create.go +++ b/cmd/issues/create.go @@ -6,10 +6,10 @@ package issues import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" "github.com/urfave/cli/v3" ) @@ -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, diff --git a/cmd/issues/edit.go b/cmd/issues/edit.go index e21cf143..3635afa3 100644 --- a/cmd/issues/edit.go +++ b/cmd/issues/edit.go @@ -8,13 +8,14 @@ import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" ) // CmdIssuesEdit is the subcommand of issues to edit issues @@ -29,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 @@ -56,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 @@ -65,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 } diff --git a/cmd/issues/list.go b/cmd/issues/list.go index 4b2652e9..184c2fc6 100644 --- a/cmd/issues/list.go +++ b/cmd/issues/list.go @@ -8,11 +8,11 @@ import ( "errors" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/araddon/dateparse" "github.com/urfave/cli/v3" ) @@ -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, diff --git a/cmd/issues/reopen.go b/cmd/issues/reopen.go index 05e9c612..30ba85fd 100644 --- a/cmd/issues/reopen.go +++ b/cmd/issues/reopen.go @@ -6,9 +6,9 @@ package issues import ( "context" - "code.gitea.io/tea/cmd/flags" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" "github.com/urfave/cli/v3" ) diff --git a/cmd/issues_test.go b/cmd/issues_test.go index 6c8bf754..5a11acb8 100644 --- a/cmd/issues_test.go +++ b/cmd/issues_test.go @@ -5,18 +5,20 @@ package cmd import ( "bytes" + stdctx "context" "encoding/json" "fmt" "testing" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" ) const ( @@ -31,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 @@ -46,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 @@ -220,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 { @@ -350,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) diff --git a/cmd/labels.go b/cmd/labels.go index cd0aef16..b676de71 100644 --- a/cmd/labels.go +++ b/cmd/labels.go @@ -7,8 +7,9 @@ import ( "context" "fmt" - "code.gitea.io/tea/cmd/labels" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/labels" ) // CmdLabels represents to operate repositories' labels. diff --git a/cmd/labels/create.go b/cmd/labels/create.go index 5320521a..aaea9a5c 100644 --- a/cmd/labels/create.go +++ b/cmd/labels/create.go @@ -10,10 +10,10 @@ import ( "os" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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, diff --git a/cmd/labels/delete.go b/cmd/labels/delete.go index 1199dcc7..b7b2a7ad 100644 --- a/cmd/labels/delete.go +++ b/cmd/labels/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/labels/list.go b/cmd/labels/list.go index ca66d3ac..22a1bffe 100644 --- a/cmd/labels/list.go +++ b/cmd/labels/list.go @@ -6,12 +6,12 @@ package labels import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/task" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/task" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/labels/update.go b/cmd/labels/update.go index 9e2cb1d4..640d1acd 100644 --- a/cmd/labels/update.go +++ b/cmd/labels/update.go @@ -6,10 +6,10 @@ package labels import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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, diff --git a/cmd/login.go b/cmd/login.go index 4e427ce1..fddf6f4b 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -7,9 +7,9 @@ import ( "context" "fmt" - "code.gitea.io/tea/cmd/login" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/print" + "gitea.dev/tea/cmd/login" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) diff --git a/cmd/login/add.go b/cmd/login/add.go index 674d76f0..9a821f28 100644 --- a/cmd/login/add.go +++ b/cmd/login/add.go @@ -7,9 +7,9 @@ import ( "context" "fmt" - "code.gitea.io/tea/modules/auth" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" + "gitea.dev/tea/modules/auth" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" "github.com/urfave/cli/v3" ) @@ -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"), diff --git a/cmd/login/default.go b/cmd/login/default.go index a49fc011..76c0c1e8 100644 --- a/cmd/login/default.go +++ b/cmd/login/default.go @@ -7,8 +7,8 @@ import ( "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/login/delete.go b/cmd/login/delete.go index f9039be8..835c7247 100644 --- a/cmd/login/delete.go +++ b/cmd/login/delete.go @@ -7,7 +7,7 @@ import ( "context" "fmt" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" "github.com/urfave/cli/v3" ) @@ -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 diff --git a/cmd/login/edit.go b/cmd/login/edit.go index a052ba37..03683255 100644 --- a/cmd/login/edit.go +++ b/cmd/login/edit.go @@ -5,11 +5,13 @@ package login import ( "context" + "fmt" "os" "os/exec" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/utils" "github.com/skratchdot/open-golang/open" "github.com/urfave/cli/v3" @@ -26,13 +28,18 @@ 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, config.GetConfigPath()) + cmd := exec.Command(e, ymlPath) cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr return cmd.Run() } - return open.Start(config.GetConfigPath()) + if exist, _ := utils.FileExist(ymlPath); !exist { + fmt.Printf("Config file does not exist, please run login add first\n") + return nil + } + return open.Start(ymlPath) } diff --git a/cmd/login/helper.go b/cmd/login/helper.go index 174c85fd..67402bf6 100644 --- a/cmd/login/helper.go +++ b/cmd/login/helper.go @@ -11,9 +11,10 @@ import ( "os" "strings" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/task" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/task" ) // CmdLoginHelper represents to login a gitea helper. @@ -28,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 @@ -63,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() { diff --git a/cmd/login/list.go b/cmd/login/list.go index 79c442be..d17ccc3b 100644 --- a/cmd/login/list.go +++ b/cmd/login/list.go @@ -6,9 +6,9 @@ package login import ( "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/print" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 diff --git a/cmd/login/oauth_refresh.go b/cmd/login/oauth_refresh.go index af6012a2..969e47f2 100644 --- a/cmd/login/oauth_refresh.go +++ b/cmd/login/oauth_refresh.go @@ -7,8 +7,8 @@ import ( "context" "fmt" - "code.gitea.io/tea/modules/auth" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/auth" + "gitea.dev/tea/modules/config" "github.com/urfave/cli/v3" ) @@ -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) } diff --git a/cmd/logout.go b/cmd/logout.go index a03bf03a..c20f3b79 100644 --- a/cmd/logout.go +++ b/cmd/logout.go @@ -4,7 +4,7 @@ package cmd import ( - "code.gitea.io/tea/cmd/login" + "gitea.dev/tea/cmd/login" "github.com/urfave/cli/v3" ) diff --git a/cmd/milestones.go b/cmd/milestones.go index 915fae02..4250c52e 100644 --- a/cmd/milestones.go +++ b/cmd/milestones.go @@ -6,10 +6,11 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/milestones" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/milestones" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) // CmdMilestones represents to operate repositories milestones. @@ -39,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 @@ -49,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 } diff --git a/cmd/milestones/close.go b/cmd/milestones/close.go index 6ec795f9..bea8af13 100644 --- a/cmd/milestones/close.go +++ b/cmd/milestones/close.go @@ -6,8 +6,9 @@ package milestones import ( "context" - "code.gitea.io/tea/cmd/flags" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" ) // CmdMilestonesClose represents a sub command of milestones to close an milestone diff --git a/cmd/milestones/create.go b/cmd/milestones/create.go index 74477589..1c8c1dfc 100644 --- a/cmd/milestones/create.go +++ b/cmd/milestones/create.go @@ -8,13 +8,14 @@ import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" + gitea "gitea.dev/sdk" "github.com/araddon/dateparse" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" ) // CmdMilestonesCreate represents a sub command of milestones to create milestone @@ -49,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 @@ -71,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"), diff --git a/cmd/milestones/delete.go b/cmd/milestones/delete.go index e0e3eaa9..d4ef1646 100644 --- a/cmd/milestones/delete.go +++ b/cmd/milestones/delete.go @@ -6,8 +6,8 @@ package milestones import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/milestones/issues.go b/cmd/milestones/issues.go index 2f89bac7..2f7c18b7 100644 --- a/cmd/milestones/issues.go +++ b/cmd/milestones/issues.go @@ -8,12 +8,13 @@ import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" ) var msIssuesFieldsFlag = flags.FieldsFlag(print.IssueFields, []string{ @@ -70,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 @@ -96,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, @@ -118,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 @@ -139,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 { @@ -153,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 @@ -173,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) } @@ -187,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 { diff --git a/cmd/milestones/list.go b/cmd/milestones/list.go index 2149a670..7db0998f 100644 --- a/cmd/milestones/list.go +++ b/cmd/milestones/list.go @@ -6,11 +6,11 @@ package milestones import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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, }) diff --git a/cmd/milestones/reopen.go b/cmd/milestones/reopen.go index 595eb079..f79ac966 100644 --- a/cmd/milestones/reopen.go +++ b/cmd/milestones/reopen.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/notifications.go b/cmd/notifications.go index bce5d499..1dd182c4 100644 --- a/cmd/notifications.go +++ b/cmd/notifications.go @@ -4,7 +4,7 @@ package cmd import ( - "code.gitea.io/tea/cmd/notifications" + "gitea.dev/tea/cmd/notifications" "github.com/urfave/cli/v3" ) diff --git a/cmd/notifications/list.go b/cmd/notifications/list.go index 334b6568..9daf021f 100644 --- a/cmd/notifications/list.go +++ b/cmd/notifications/list.go @@ -6,11 +6,11 @@ package notifications import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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, diff --git a/cmd/notifications/mark_as.go b/cmd/notifications/mark_as.go index a1917665..7d436bbb 100644 --- a/cmd/notifications/mark_as.go +++ b/cmd/notifications/mark_as.go @@ -7,11 +7,12 @@ import ( stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" ) // CmdNotificationsMarkRead represents a sub command of notifications to list read notifications @@ -22,7 +23,7 @@ var CmdNotificationsMarkRead = cli.Command{ Description: "Mark all filtered or a specific notification as read", ArgsUsage: "[all | ]", 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 @@ -34,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) }, } @@ -46,7 +47,7 @@ var CmdNotificationsMarkUnread = cli.Command{ Description: "Mark all filtered or a specific notification as unread", ArgsUsage: "[all | ]", 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 @@ -58,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) }, } @@ -70,7 +71,7 @@ var CmdNotificationsMarkPinned = cli.Command{ Description: "Mark all filtered or a specific notification as pinned", ArgsUsage: "[all | ]", 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 @@ -82,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) }, } @@ -93,18 +94,18 @@ var CmdNotificationsUnpin = cli.Command{ Description: "Marks all pinned or a specific notification as read", ArgsUsage: "[all | ]", 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") @@ -119,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 @@ -135,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 } diff --git a/cmd/open.go b/cmd/open.go index 7e6c448c..c69f94bf 100644 --- a/cmd/open.go +++ b/cmd/open.go @@ -8,9 +8,9 @@ import ( "path" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - local_git "code.gitea.io/tea/modules/git" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + local_git "gitea.dev/tea/modules/git" "github.com/skratchdot/open-golang/open" "github.com/urfave/cli/v3" @@ -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 diff --git a/cmd/organizations.go b/cmd/organizations.go index cccc54cf..86315528 100644 --- a/cmd/organizations.go +++ b/cmd/organizations.go @@ -6,9 +6,9 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/organizations" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/tea/cmd/organizations" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 -} diff --git a/cmd/organizations/create.go b/cmd/organizations/create.go index 8eea3ad4..ff1cfce9 100644 --- a/cmd/organizations/create.go +++ b/cmd/organizations/create.go @@ -7,10 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -52,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 @@ -74,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"), diff --git a/cmd/organizations/delete.go b/cmd/organizations/delete.go index b88f75d8..c70740a6 100644 --- a/cmd/organizations/delete.go +++ b/cmd/organizations/delete.go @@ -7,9 +7,10 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" ) // CmdOrganizationDelete represents a sub command of organizations to delete a given user organization @@ -27,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 @@ -39,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()) } diff --git a/cmd/organizations/list.go b/cmd/organizations/list.go index f279edcf..e1951aef 100644 --- a/cmd/organizations/list.go +++ b/cmd/organizations/list.go @@ -6,11 +6,12 @@ package organizations import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) // CmdOrganizationList represents a sub command of organizations to list users organizations @@ -28,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 { diff --git a/cmd/pulls.go b/cmd/pulls.go index bd28d168..4f732c05 100644 --- a/cmd/pulls.go +++ b/cmd/pulls.go @@ -8,13 +8,14 @@ import ( "fmt" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/pulls" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/pulls" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -91,7 +92,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 +106,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 +130,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 +142,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 +151,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 +186,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 } diff --git a/cmd/pulls/approve.go b/cmd/pulls/approve.go index ba3b0ede..84d5b259 100644 --- a/cmd/pulls/approve.go +++ b/cmd/pulls/approve.go @@ -6,10 +6,11 @@ package pulls import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" ) // CmdPullsApprove approves a PR @@ -19,12 +20,12 @@ var CmdPullsApprove = cli.Command{ Usage: "Approve a pull request", Description: "Approve a pull request", ArgsUsage: " []", - 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, } diff --git a/cmd/pulls/checkout.go b/cmd/pulls/checkout.go index 1219a5de..90c74c3d 100644 --- a/cmd/pulls/checkout.go +++ b/cmd/pulls/checkout.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -33,7 +33,7 @@ var CmdPullsCheckout = cli.Command{ }, flags.AllDefaultFlags...), } -func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error { +func runPullsCheckout(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -52,7 +52,7 @@ func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error { return err } - if err := task.PullCheckout(ctx.Login, ctx.Owner, ctx.Repo, ctx.Bool("branch"), idx, interact.PromptPassword); err != nil && !interact.IsQuitting(err) { + if err := task.PullCheckout(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, ctx.Bool("branch"), idx, interact.PromptPassword); err != nil && !interact.IsQuitting(err) { return err } return nil diff --git a/cmd/pulls/clean.go b/cmd/pulls/clean.go index 05c1e850..5bee1b66 100644 --- a/cmd/pulls/clean.go +++ b/cmd/pulls/clean.go @@ -8,12 +8,13 @@ import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" ) // CmdPullsClean removes the remote and local feature branches, if a PR is merged. @@ -31,7 +32,7 @@ var CmdPullsClean = cli.Command{ }, flags.AllDefaultFlags...), } -func runPullsClean(_ stdctx.Context, cmd *cli.Command) error { +func runPullsClean(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -48,7 +49,7 @@ func runPullsClean(_ stdctx.Context, cmd *cli.Command) error { return err } - if err := task.PullClean(ctx.Login, ctx.Owner, ctx.Repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword); err != nil && !interact.IsQuitting(err) { + if err := task.PullClean(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword); err != nil && !interact.IsQuitting(err) { return err } return nil diff --git a/cmd/pulls/close.go b/cmd/pulls/close.go index 74f7a584..766f564c 100644 --- a/cmd/pulls/close.go +++ b/cmd/pulls/close.go @@ -6,9 +6,9 @@ package pulls import ( "context" - "code.gitea.io/tea/cmd/flags" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" "github.com/urfave/cli/v3" ) diff --git a/cmd/pulls/create.go b/cmd/pulls/create.go index c0f74d7d..fb1abb34 100644 --- a/cmd/pulls/create.go +++ b/cmd/pulls/create.go @@ -6,12 +6,13 @@ package pulls import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" ) // CmdPullsCreate creates a pull request @@ -48,7 +49,7 @@ var CmdPullsCreate = cli.Command{ }, flags.IssuePRCreateFlags...), } -func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error { +func runPullsCreate(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -62,20 +63,21 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error { // no args -> interactive mode if ctx.IsInteractiveMode() { - if err := interact.CreatePull(ctx); err != nil && !interact.IsQuitting(err) { + if err := interact.CreatePull(requestCtx, ctx); err != nil && !interact.IsQuitting(err) { return err } return nil } // else use args to create PR - opts, err := flags.GetIssuePRCreateFlags(ctx) + opts, err := flags.GetIssuePRCreateFlags(requestCtx, ctx) if err != nil { return err } if ctx.Bool("agit") { return task.CreateAgitFlowPull( + requestCtx, ctx, ctx.String("remote"), ctx.String("head"), @@ -92,6 +94,7 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error { } return task.CreatePull( + requestCtx, ctx, ctx.String("base"), ctx.String("head"), diff --git a/cmd/pulls/edit.go b/cmd/pulls/edit.go index b9090b03..272646e2 100644 --- a/cmd/pulls/edit.go +++ b/cmd/pulls/edit.go @@ -8,13 +8,13 @@ import ( "fmt" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -40,7 +40,7 @@ use an empty string (eg. --milestone "").`, ), } -func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error { +func runPullsEdit(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -72,7 +72,7 @@ func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error { client := ctx.Login.Client() for _, opts.Index = range indices { - pr, err := task.EditPull(ctx, client, *opts) + pr, err := task.EditPull(requestCtx, ctx, client, *opts) if err != nil { return err } @@ -87,7 +87,7 @@ func runPullsEdit(_ stdctx.Context, cmd *cli.Command) error { } // editPullState abstracts the arg parsing to edit the given pull request -func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error { +func editPullState(requestCtx stdctx.Context, cmd *cli.Command, opts gitea.EditPullRequestOption) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -106,7 +106,7 @@ func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullReques client := ctx.Login.Client() for _, index := range indices { - pr, _, err := client.EditPullRequest(ctx.Owner, ctx.Repo, index, opts) + pr, _, err := client.PullRequests.EditPullRequest(requestCtx, ctx.Owner, ctx.Repo, index, opts) if err != nil { return err } diff --git a/cmd/pulls/list.go b/cmd/pulls/list.go index 3eaf9d6a..f772e0f8 100644 --- a/cmd/pulls/list.go +++ b/cmd/pulls/list.go @@ -8,11 +8,12 @@ import ( "fmt" "slices" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) var pullFieldsFlag = flags.FieldsFlag(print.PullFields, []string{ @@ -31,7 +32,7 @@ var CmdPullsList = cli.Command{ } // RunPullsList return list of pulls -func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { +func RunPullsList(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -46,7 +47,7 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { } client := ctx.Login.Client() - prs, _, err := client.ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ + prs, _, err := client.PullRequests.ListRepoPullRequests(requestCtx, ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{ ListOptions: flags.GetListOptions(cmd), State: state, }) @@ -66,7 +67,7 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error { if pr.Head == nil || pr.Head.Sha == "" { continue } - ci, _, err := client.GetCombinedStatus(ctx.Owner, ctx.Repo, pr.Head.Sha) + ci, _, err := client.Repositories.GetCombinedStatus(requestCtx, ctx.Owner, ctx.Repo, pr.Head.Sha) if err != nil { fmt.Printf("error fetching CI status for PR #%d: %v\n", pr.Index, err) continue diff --git a/cmd/pulls/merge.go b/cmd/pulls/merge.go index a8de9306..a08d0606 100644 --- a/cmd/pulls/merge.go +++ b/cmd/pulls/merge.go @@ -6,13 +6,14 @@ package pulls import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" ) // CmdPullsMerge merges a PR @@ -40,7 +41,7 @@ var CmdPullsMerge = cli.Command{ Usage: "Merge commit message", }, }, flags.AllDefaultFlags...), - Action: func(_ stdctx.Context, cmd *cli.Command) error { + Action: func(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -51,7 +52,7 @@ var CmdPullsMerge = cli.Command{ if ctx.Args().Len() != 1 { // If no PR index is provided, try interactive mode - if err := interact.MergePull(ctx); err != nil && !interact.IsQuitting(err) { + if err := interact.MergePull(requestCtx, ctx); err != nil && !interact.IsQuitting(err) { return err } return nil @@ -62,7 +63,7 @@ var CmdPullsMerge = cli.Command{ return err } - return task.PullMerge(ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{ + return task.PullMerge(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, idx, gitea.MergePullRequestOption{ Style: gitea.MergeStyle(ctx.String("style")), Title: ctx.String("title"), Message: ctx.String("message"), diff --git a/cmd/pulls/reject.go b/cmd/pulls/reject.go index 67f2a706..1b44ca81 100644 --- a/cmd/pulls/reject.go +++ b/cmd/pulls/reject.go @@ -6,10 +6,11 @@ package pulls import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" ) // CmdPullsReject requests changes to a PR @@ -18,12 +19,12 @@ var CmdPullsReject = cli.Command{ Usage: "Request changes to a pull request", Description: "Request changes to a pull request", ArgsUsage: " ", - 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, } diff --git a/cmd/pulls/reopen.go b/cmd/pulls/reopen.go index f05ea08f..68790e29 100644 --- a/cmd/pulls/reopen.go +++ b/cmd/pulls/reopen.go @@ -6,9 +6,9 @@ package pulls import ( "context" - "code.gitea.io/tea/cmd/flags" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" "github.com/urfave/cli/v3" ) diff --git a/cmd/pulls/reply.go b/cmd/pulls/reply.go index d3608a43..f66dcf86 100644 --- a/cmd/pulls/reply.go +++ b/cmd/pulls/reply.go @@ -6,8 +6,8 @@ package pulls import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -18,12 +18,12 @@ var CmdPullsReply = cli.Command{ Usage: "Reply to a pull request review comment", Description: "Reply to a pull request review comment", ArgsUsage: " []", - Action: func(_ stdctx.Context, cmd *cli.Command) error { + Action: func(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err } - return runPullReviewReply(ctx) + return runPullReviewReply(requestCtx, ctx) }, Flags: flags.AllDefaultFlags, } diff --git a/cmd/pulls/resolve.go b/cmd/pulls/resolve.go index 6be00283..a6e3bb73 100644 --- a/cmd/pulls/resolve.go +++ b/cmd/pulls/resolve.go @@ -6,9 +6,9 @@ package pulls import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" "github.com/urfave/cli/v3" ) @@ -19,12 +19,12 @@ var CmdPullsResolve = cli.Command{ Usage: "Resolve a review comment on a pull request", Description: "Resolve a review comment on a pull request", ArgsUsage: "", - 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, } diff --git a/cmd/pulls/review.go b/cmd/pulls/review.go index ea37b429..c9b5b063 100644 --- a/cmd/pulls/review.go +++ b/cmd/pulls/review.go @@ -8,11 +8,11 @@ import ( "fmt" "os" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -23,7 +23,7 @@ var CmdPullsReview = cli.Command{ Usage: "Interactively review a pull request", Description: "Interactively review a pull request", ArgsUsage: "", - 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 } } diff --git a/cmd/pulls/review_comments.go b/cmd/pulls/review_comments.go index 63b19f2f..7bc0c39f 100644 --- a/cmd/pulls/review_comments.go +++ b/cmd/pulls/review_comments.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -31,7 +31,7 @@ var CmdPullsReviewComments = cli.Command{ Flags: append([]cli.Flag{reviewCommentFieldsFlag}, flags.AllDefaultFlags...), } -func runPullsReviewComments(_ stdctx.Context, cmd *cli.Command) error { +func runPullsReviewComments(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -49,7 +49,7 @@ func runPullsReviewComments(_ stdctx.Context, cmd *cli.Command) error { return err } - comments, err := task.ListPullReviewComments(ctx, idx) + comments, err := task.ListPullReviewComments(requestCtx, ctx, idx) if err != nil { return err } diff --git a/cmd/pulls/review_helpers.go b/cmd/pulls/review_helpers.go index 94b2c977..82db65e8 100644 --- a/cmd/pulls/review_helpers.go +++ b/cmd/pulls/review_helpers.go @@ -4,24 +4,26 @@ package pulls import ( + stdctx "context" "errors" "fmt" "io" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/interact" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/interact" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" ) // runPullReview handles the common logic for approving/rejecting pull requests -func runPullReview(ctx *context.TeaContext, state gitea.ReviewStateType, requireComment bool) error { +func runPullReview(requestCtx stdctx.Context, ctx *context.TeaContext, state gitea.ReviewStateType, requireComment bool) error { if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil { return err } @@ -45,11 +47,11 @@ func runPullReview(ctx *context.TeaContext, state gitea.ReviewStateType, require comment := strings.Join(ctx.Args().Tail(), " ") - return task.CreatePullReview(ctx, idx, state, comment, nil) + return task.CreatePullReview(requestCtx, ctx, idx, state, comment, nil) } // runResolveComment handles the common logic for resolving/unresolving review comments -func runResolveComment(ctx *context.TeaContext, action func(*context.TeaContext, int64) error) error { +func runResolveComment(requestCtx stdctx.Context, ctx *context.TeaContext, action func(stdctx.Context, *context.TeaContext, int64) error) error { if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil { return err } @@ -63,11 +65,11 @@ func runResolveComment(ctx *context.TeaContext, action func(*context.TeaContext, return err } - return action(ctx, commentID) + return action(requestCtx, ctx, commentID) } // runPullReviewReply handles replying to a specific review comment on a pull request. -func runPullReviewReply(ctx *context.TeaContext) error { +func runPullReviewReply(requestCtx stdctx.Context, ctx *context.TeaContext) error { if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil { return err } @@ -91,7 +93,7 @@ func runPullReviewReply(ctx *context.TeaContext) error { return err } - return task.ReplyToPullReviewComment(ctx, idx, commentID, body) + return task.ReplyToPullReviewComment(requestCtx, ctx, idx, commentID, body) } func getCommentBody(ctx *context.TeaContext, extraArgs []string, promptTitle, noun string) (string, error) { diff --git a/cmd/pulls/review_test.go b/cmd/pulls/review_test.go index 566d692f..83d65eeb 100644 --- a/cmd/pulls/review_test.go +++ b/cmd/pulls/review_test.go @@ -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 != "" { diff --git a/cmd/pulls/unresolve.go b/cmd/pulls/unresolve.go index 1dea3897..55f72e1b 100644 --- a/cmd/pulls/unresolve.go +++ b/cmd/pulls/unresolve.go @@ -6,9 +6,9 @@ package pulls import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" "github.com/urfave/cli/v3" ) @@ -19,12 +19,12 @@ var CmdPullsUnresolve = cli.Command{ Usage: "Unresolve a review comment on a pull request", Description: "Unresolve a review comment on a pull request", ArgsUsage: "", - 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, } diff --git a/cmd/releases.go b/cmd/releases.go index d69d10bf..6c2989f6 100644 --- a/cmd/releases.go +++ b/cmd/releases.go @@ -4,8 +4,8 @@ package cmd import ( - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/cmd/releases" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/cmd/releases" "github.com/urfave/cli/v3" ) diff --git a/cmd/releases/create.go b/cmd/releases/create.go index bb525b5c..74f7ebc3 100644 --- a/cmd/releases/create.go +++ b/cmd/releases/create.go @@ -10,10 +10,10 @@ import ( "os" "path/filepath" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/releases/delete.go b/cmd/releases/delete.go index 9d6974de..5deb41c5 100644 --- a/cmd/releases/delete.go +++ b/cmd/releases/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -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 } } diff --git a/cmd/releases/edit.go b/cmd/releases/edit.go index cc53078b..76fb3b49 100644 --- a/cmd/releases/edit.go +++ b/cmd/releases/edit.go @@ -9,10 +9,11 @@ import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" ) // CmdReleaseEdit represents a sub command of Release to edit releases @@ -57,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 @@ -81,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"), diff --git a/cmd/releases/list.go b/cmd/releases/list.go index 8d9af535..4fa950d0 100644 --- a/cmd/releases/list.go +++ b/cmd/releases/list.go @@ -6,11 +6,11 @@ package releases import ( stdctx "context" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 { diff --git a/cmd/releases/utils.go b/cmd/releases/utils.go index c27618c4..6230ee46 100644 --- a/cmd/releases/utils.go +++ b/cmd/releases/utils.go @@ -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 { diff --git a/cmd/repos.go b/cmd/repos.go index 7c306906..47b54e94 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -6,12 +6,12 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/repos" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/repos" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/repos/create.go b/cmd/repos/create.go index 21b19cd3..ef7b324d 100644 --- a/cmd/repos/create.go +++ b/cmd/repos/create.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -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 } diff --git a/cmd/repos/create_from_template.go b/cmd/repos/create_from_template.go index 27a6df37..8bbc8912 100644 --- a/cmd/repos/create_from_template.go +++ b/cmd/repos/create_from_template.go @@ -8,12 +8,13 @@ import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" ) // CmdRepoCreateFromTemplate represents a sub command of repos to generate one from a template repo @@ -82,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 @@ -108,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 } diff --git a/cmd/repos/delete.go b/cmd/repos/delete.go index abb9f89e..46e2871d 100644 --- a/cmd/repos/delete.go +++ b/cmd/repos/delete.go @@ -7,8 +7,8 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "charm.land/huh/v2" "github.com/urfave/cli/v3" @@ -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 } diff --git a/cmd/repos/edit.go b/cmd/repos/edit.go index 22a3a558..635ad2f2 100644 --- a/cmd/repos/edit.go +++ b/cmd/repos/edit.go @@ -7,11 +7,11 @@ import ( stdctx "context" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -59,7 +59,7 @@ var CmdRepoEdit = cli.Command{ }, flags.AllDefaultFlags...), } -func runRepoEdit(_ stdctx.Context, cmd *cli.Command) error { +func runRepoEdit(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -97,12 +97,12 @@ func runRepoEdit(_ stdctx.Context, cmd *cli.Command) error { opts.Archived = gitea.OptionalBool(strings.ToLower(ctx.String("archived"))[:1] == "t") } - repo, _, err := client.EditRepo(ctx.Owner, ctx.Repo, opts) + repo, _, err := client.Repositories.EditRepo(requestCtx, ctx.Owner, ctx.Repo, 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 } diff --git a/cmd/repos/flags.go b/cmd/repos/flags.go index b91e489f..180a4c0b 100644 --- a/cmd/repos/flags.go +++ b/cmd/repos/flags.go @@ -6,7 +6,7 @@ package repos import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/urfave/cli/v3" ) diff --git a/cmd/repos/fork.go b/cmd/repos/fork.go index 81dd16ef..9cbc4a72 100644 --- a/cmd/repos/fork.go +++ b/cmd/repos/fork.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -32,7 +32,7 @@ var CmdRepoFork = cli.Command{ }, flags.LoginRepoFlags...), } -func runRepoFork(_ stdctx.Context, cmd *cli.Command) error { +func runRepoFork(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -48,12 +48,12 @@ func runRepoFork(_ stdctx.Context, cmd *cli.Command) error { opts.Organization = &owner } - repo, _, err := client.CreateFork(ctx.Owner, ctx.Repo, opts) + repo, _, err := client.Repositories.CreateFork(requestCtx, ctx.Owner, ctx.Repo, 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 } diff --git a/cmd/repos/list.go b/cmd/repos/list.go index 56be1d90..0f4a33c7 100644 --- a/cmd/repos/list.go +++ b/cmd/repos/list.go @@ -8,11 +8,11 @@ import ( "fmt" "net/http" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -57,7 +57,7 @@ var CmdReposList = cli.Command{ } // RunReposList list repositories -func RunReposList(_ stdctx.Context, cmd *cli.Command) error { +func RunReposList(requestCtx stdctx.Context, cmd *cli.Command) error { teaCmd, err := context.InitCommand(cmd) if err != nil { return err @@ -72,17 +72,17 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error { var rps []*gitea.Repository if owner := teaCmd.String("owner"); owner != "" { var err error - _, resp, orgErr := client.GetOrg(owner) + _, resp, orgErr := client.Organizations.GetOrg(requestCtx, owner) if orgErr != nil { if resp == nil || resp.StatusCode != http.StatusNotFound { return fmt.Errorf("could not find owner: %w", orgErr) } // not an org, treat as user - rps, _, err = client.ListUserRepos(owner, gitea.ListReposOptions{ + rps, _, err = client.Repositories.ListUserRepos(requestCtx, owner, gitea.ListReposOptions{ ListOptions: flags.GetListOptions(cmd), }) } else { - rps, _, err = client.ListOrgRepos(owner, gitea.ListOrgReposOptions{ + rps, _, err = client.Repositories.ListOrgRepos(requestCtx, owner, gitea.ListOrgReposOptions{ ListOptions: flags.GetListOptions(cmd), }) } @@ -90,11 +90,11 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error { return err } } else if teaCmd.Bool("starred") { - user, _, err := client.GetMyUserInfo() + user, _, err := client.Users.GetMyUserInfo(requestCtx) if err != nil { return err } - rps, _, err = client.SearchRepos(gitea.SearchRepoOptions{ + rps, _, err = client.Repositories.SearchRepos(requestCtx, gitea.SearchRepoOptions{ ListOptions: flags.GetListOptions(cmd), StarredByUserID: user.ID, }) @@ -104,14 +104,14 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error { } else if teaCmd.Bool("watched") { // GetMyWatchedRepos doesn't expose server-side pagination, // so we implement client-side pagination as a workaround - allRepos, _, err := client.GetMyWatchedRepos() + allRepos, _, err := client.Repositories.GetMyWatchedRepos(requestCtx) if err != nil { return err } rps = paginateRepos(allRepos, flags.GetListOptions(cmd)) } else { var err error - rps, _, err = client.ListMyRepos(gitea.ListReposOptions{ + rps, _, err = client.Repositories.ListMyRepos(requestCtx, gitea.ListReposOptions{ ListOptions: flags.GetListOptions(cmd), }) if err != nil { diff --git a/cmd/repos/migrate.go b/cmd/repos/migrate.go index 3f158b74..a241d0b8 100644 --- a/cmd/repos/migrate.go +++ b/cmd/repos/migrate.go @@ -8,11 +8,12 @@ import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) // CmdRepoMigrate represents a sub command of repos to migrate one @@ -108,7 +109,7 @@ var CmdRepoMigrate = cli.Command{ }, flags.LoginOutputFlags...), } -func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error { +func runRepoMigrate(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -158,12 +159,12 @@ func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error { LFSEndpoint: ctx.String("lfs-endpoint"), } - repo, _, err = client.MigrateRepo(opts) + repo, _, err = client.Repositories.MigrateRepo(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 } diff --git a/cmd/repos/search.go b/cmd/repos/search.go index d4bb0fd8..4efde401 100644 --- a/cmd/repos/search.go +++ b/cmd/repos/search.go @@ -9,11 +9,11 @@ import ( "net/http" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -57,7 +57,7 @@ var CmdReposSearch = cli.Command{ }, flags.LoginOutputFlags...), } -func runReposSearch(_ stdctx.Context, cmd *cli.Command) error { +func runReposSearch(requestCtx stdctx.Context, cmd *cli.Command) error { teaCmd, err := context.InitCommand(cmd) if err != nil { return err @@ -67,14 +67,14 @@ func runReposSearch(_ stdctx.Context, cmd *cli.Command) error { var ownerID int64 if teaCmd.IsSet("owner") { // test if owner is an organization - org, resp, err := client.GetOrg(teaCmd.String("owner")) + org, resp, err := client.Organizations.GetOrg(requestCtx, teaCmd.String("owner")) if err != nil { if resp == nil || resp.StatusCode != http.StatusNotFound { return fmt.Errorf("could not find owner: %w", err) } // if owner is no org, its a user - user, _, err := client.GetUserInfo(teaCmd.String("owner")) + user, _, err := client.Users.GetUserInfo(requestCtx, teaCmd.String("owner")) if err != nil { return err } @@ -106,12 +106,12 @@ func runReposSearch(_ stdctx.Context, cmd *cli.Command) error { keyword = strings.Join(teaCmd.Args().Slice(), " ") } - user, _, err := client.GetMyUserInfo() + user, _, err := client.Users.GetMyUserInfo(requestCtx) if err != nil { return err } - rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{ + rps, _, err := client.Repositories.SearchRepos(requestCtx, gitea.SearchRepoOptions{ ListOptions: flags.GetListOptions(cmd), OwnerID: ownerID, IsPrivate: isPrivate, diff --git a/cmd/sshkeys.go b/cmd/sshkeys.go index d18e2de3..f232c170 100644 --- a/cmd/sshkeys.go +++ b/cmd/sshkeys.go @@ -6,8 +6,9 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/cmd/sshkeys" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/sshkeys" ) // CmdSSHKeys represents the ssh-keys command group diff --git a/cmd/sshkeys/add.go b/cmd/sshkeys/add.go index 5294404a..1a930b5c 100644 --- a/cmd/sshkeys/add.go +++ b/cmd/sshkeys/add.go @@ -10,9 +10,10 @@ import ( "path/filepath" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -34,7 +35,7 @@ var CmdSSHKeyAdd = cli.Command{ } // RunSSHKeyAdd reads a public key file and registers it with the Gitea instance -func RunSSHKeyAdd(_ stdctx.Context, cmd *cli.Command) error { +func RunSSHKeyAdd(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -61,7 +62,7 @@ func RunSSHKeyAdd(_ stdctx.Context, cmd *cli.Command) error { title = strings.TrimSuffix(base, filepath.Ext(base)) } - key, _, err := ctx.Login.Client().CreatePublicKey(gitea.CreateKeyOption{ + key, _, err := ctx.Login.Client().Users.CreatePublicKey(requestCtx, gitea.CreateKeyOption{ Title: title, Key: keyContent, }) diff --git a/cmd/sshkeys/delete.go b/cmd/sshkeys/delete.go index 9c027844..d9df0d93 100644 --- a/cmd/sshkeys/delete.go +++ b/cmd/sshkeys/delete.go @@ -8,8 +8,8 @@ import ( "fmt" "strconv" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -32,7 +32,7 @@ var CmdSSHKeyDelete = cli.Command{ } // RunSSHKeyDelete removes an SSH key by its numeric ID -func RunSSHKeyDelete(_ stdctx.Context, cmd *cli.Command) error { +func RunSSHKeyDelete(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -49,7 +49,7 @@ func RunSSHKeyDelete(_ stdctx.Context, cmd *cli.Command) error { client := ctx.Login.Client() - key, resp, err := client.GetPublicKey(keyID) + key, resp, err := client.Users.GetPublicKey(requestCtx, keyID) if err != nil { if resp != nil && resp.StatusCode == 404 { return fmt.Errorf("SSH key with ID %d not found", keyID) @@ -67,7 +67,7 @@ func RunSSHKeyDelete(_ stdctx.Context, cmd *cli.Command) error { } } - if _, err = client.DeletePublicKey(keyID); err != nil { + if _, err = client.Users.DeletePublicKey(requestCtx, keyID); err != nil { return err } diff --git a/cmd/sshkeys/list.go b/cmd/sshkeys/list.go index f28aaa1c..269b876a 100644 --- a/cmd/sshkeys/list.go +++ b/cmd/sshkeys/list.go @@ -6,10 +6,11 @@ package sshkeys import ( stdctx "context" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -29,14 +30,14 @@ var CmdSSHKeyList = cli.Command{ } // RunSSHKeyList lists SSH keys for the current user -func RunSSHKeyList(_ stdctx.Context, cmd *cli.Command) error { +func RunSSHKeyList(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err } client := ctx.Login.Client() - keys, _, err := client.ListMyPublicKeys(gitea.ListPublicKeysOptions{ + keys, _, err := client.Users.ListMyPublicKeys(requestCtx, gitea.ListPublicKeysOptions{ ListOptions: flags.GetListOptions(cmd), }) if err != nil { diff --git a/cmd/times.go b/cmd/times.go index eb7a69ef..fd1a761e 100644 --- a/cmd/times.go +++ b/cmd/times.go @@ -4,8 +4,9 @@ package cmd import ( - "code.gitea.io/tea/cmd/times" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/times" ) // CmdTrackedTimes represents the command to operate repositories' times. diff --git a/cmd/times/add.go b/cmd/times/add.go index 28772185..26f7781e 100644 --- a/cmd/times/add.go +++ b/cmd/times/add.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -31,7 +31,7 @@ var CmdTrackedTimesAdd = cli.Command{ Flags: flags.LoginRepoFlags, } -func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error { +func runTrackedTimesAdd(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -54,7 +54,7 @@ func runTrackedTimesAdd(_ stdctx.Context, cmd *cli.Command) error { return err } - _, _, err = ctx.Login.Client().AddTime(ctx.Owner, ctx.Repo, issue, gitea.AddTimeOption{ + _, _, err = ctx.Login.Client().Issues.AddTime(requestCtx, ctx.Owner, ctx.Repo, issue, gitea.AddTimeOption{ Time: int64(duration.Seconds()), }) return err diff --git a/cmd/times/delete.go b/cmd/times/delete.go index cbb92845..58a2e2c0 100644 --- a/cmd/times/delete.go +++ b/cmd/times/delete.go @@ -8,9 +8,9 @@ import ( "fmt" "strconv" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -25,7 +25,7 @@ var CmdTrackedTimesDelete = cli.Command{ Flags: flags.LoginRepoFlags, } -func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error { +func runTrackedTimesDelete(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -49,6 +49,6 @@ func runTrackedTimesDelete(_ stdctx.Context, cmd *cli.Command) error { return err } - _, err = client.DeleteTime(ctx.Owner, ctx.Repo, issue, timeID) + _, err = client.Issues.DeleteTime(requestCtx, ctx.Owner, ctx.Repo, issue, timeID) return err } diff --git a/cmd/times/list.go b/cmd/times/list.go index 9eec82c7..c6974edd 100644 --- a/cmd/times/list.go +++ b/cmd/times/list.go @@ -9,12 +9,12 @@ import ( "strings" "time" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/araddon/dateparse" "github.com/urfave/cli/v3" ) @@ -71,7 +71,7 @@ Depending on your permissions on the repository, only your own tracked times mig } // RunTimesList list repositories -func RunTimesList(_ stdctx.Context, cmd *cli.Command) error { +func RunTimesList(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -106,11 +106,11 @@ func RunTimesList(_ stdctx.Context, cmd *cli.Command) error { user := ctx.Args().First() if ctx.Bool("mine") { - times, _, err = client.ListMyTrackedTimes(opts) + times, _, err = client.Issues.ListMyTrackedTimes(requestCtx, opts) fields = []string{"created", "repo", "issue", "duration"} } else if user == "" { // get all tracked times on the repo - times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, opts) + times, _, err = client.Issues.ListRepoTrackedTimes(requestCtx, ctx.Owner, ctx.Repo, opts) fields = []string{"created", "issue", "user", "duration"} } else if strings.HasPrefix(user, "#") { // get all tracked times on the specified issue @@ -118,12 +118,12 @@ func RunTimesList(_ stdctx.Context, cmd *cli.Command) error { if parseErr != nil { return parseErr } - times, _, err = client.ListIssueTrackedTimes(ctx.Owner, ctx.Repo, issue, opts) + times, _, err = client.Issues.ListIssueTrackedTimes(requestCtx, ctx.Owner, ctx.Repo, issue, opts) fields = []string{"created", "user", "duration"} } else { // get all tracked times by the specified user opts.User = user - times, _, err = client.ListRepoTrackedTimes(ctx.Owner, ctx.Repo, opts) + times, _, err = client.Issues.ListRepoTrackedTimes(requestCtx, ctx.Owner, ctx.Repo, opts) fields = []string{"created", "issue", "duration"} } diff --git a/cmd/times/reset.go b/cmd/times/reset.go index 08f8f933..9ce78ce0 100644 --- a/cmd/times/reset.go +++ b/cmd/times/reset.go @@ -7,9 +7,9 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -24,7 +24,7 @@ var CmdTrackedTimesReset = cli.Command{ Flags: flags.LoginRepoFlags, } -func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error { +func runTrackedTimesReset(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -43,6 +43,6 @@ func runTrackedTimesReset(_ stdctx.Context, cmd *cli.Command) error { return err } - _, err = client.ResetIssueTime(ctx.Owner, ctx.Repo, issue) + _, err = client.Issues.ResetIssueTime(requestCtx, ctx.Owner, ctx.Repo, issue) return err } diff --git a/cmd/webhooks.go b/cmd/webhooks.go index 63f90522..1ddab25c 100644 --- a/cmd/webhooks.go +++ b/cmd/webhooks.go @@ -7,12 +7,12 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/webhooks" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/webhooks" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -63,7 +63,7 @@ func runWebhooksDefault(ctx stdctx.Context, cmd *cli.Command) error { return webhooks.RunWebhooksList(ctx, cmd) } -func runWebhookDetail(_ stdctx.Context, cmd *cli.Command) error { +func runWebhookDetail(requestCtx stdctx.Context, cmd *cli.Command) error { ctx, err := context.InitCommand(cmd) if err != nil { return err @@ -79,9 +79,9 @@ func runWebhookDetail(_ stdctx.Context, cmd *cli.Command) error { if ctx.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(ctx.Org) > 0 { - hook, _, err = client.GetOrgHook(ctx.Org, int64(webhookID)) + hook, _, err = client.Hooks.GetOrgHook(requestCtx, ctx.Org, int64(webhookID)) } else { - hook, _, err = client.GetRepoHook(ctx.Owner, ctx.Repo, int64(webhookID)) + hook, _, err = client.Hooks.GetRepoHook(requestCtx, ctx.Owner, ctx.Repo, int64(webhookID)) } if err != nil { return err diff --git a/cmd/webhooks/create.go b/cmd/webhooks/create.go index d6694366..90109482 100644 --- a/cmd/webhooks/create.go +++ b/cmd/webhooks/create.go @@ -8,10 +8,10 @@ import ( "fmt" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" "github.com/urfave/cli/v3" ) @@ -93,7 +93,7 @@ func runWebhooksCreate(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - hook, _, err = client.CreateOrgHook(c.Org, gitea.CreateHookOption{ + hook, _, err = client.Hooks.CreateOrgHook(ctx, c.Org, gitea.CreateHookOption{ Type: webhookType, Config: config, Events: events, @@ -102,7 +102,7 @@ func runWebhooksCreate(ctx stdctx.Context, cmd *cli.Command) error { AuthorizationHeader: authHeader, }) } else { - hook, _, err = client.CreateRepoHook(c.Owner, c.Repo, gitea.CreateHookOption{ + hook, _, err = client.Hooks.CreateRepoHook(ctx, c.Owner, c.Repo, gitea.CreateHookOption{ Type: webhookType, Config: config, Events: events, diff --git a/cmd/webhooks/create_test.go b/cmd/webhooks/create_test.go index c5c9d91a..05751580 100644 --- a/cmd/webhooks/create_test.go +++ b/cmd/webhooks/create_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/urfave/cli/v3" ) diff --git a/cmd/webhooks/delete.go b/cmd/webhooks/delete.go index fe4a5e36..62e04eeb 100644 --- a/cmd/webhooks/delete.go +++ b/cmd/webhooks/delete.go @@ -7,11 +7,10 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" - - "code.gitea.io/sdk/gitea" + gitea "gitea.dev/sdk" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -53,9 +52,9 @@ func runWebhooksDelete(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - hook, _, err = client.GetOrgHook(c.Org, int64(webhookID)) + hook, _, err = client.Hooks.GetOrgHook(ctx, c.Org, int64(webhookID)) } else { - hook, _, err = client.GetRepoHook(c.Owner, c.Repo, int64(webhookID)) + hook, _, err = client.Hooks.GetRepoHook(ctx, c.Owner, c.Repo, int64(webhookID)) } if err != nil { return err @@ -74,9 +73,9 @@ func runWebhooksDelete(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - _, err = client.DeleteOrgHook(c.Org, int64(webhookID)) + _, err = client.Hooks.DeleteOrgHook(ctx, c.Org, int64(webhookID)) } else { - _, err = client.DeleteRepoHook(c.Owner, c.Repo, int64(webhookID)) + _, err = client.Hooks.DeleteRepoHook(ctx, c.Owner, c.Repo, int64(webhookID)) } if err != nil { return err diff --git a/cmd/webhooks/delete_test.go b/cmd/webhooks/delete_test.go index 6d1a1a81..c938be33 100644 --- a/cmd/webhooks/delete_test.go +++ b/cmd/webhooks/delete_test.go @@ -6,7 +6,7 @@ package webhooks import ( "testing" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/urfave/cli/v3" ) diff --git a/cmd/webhooks/list.go b/cmd/webhooks/list.go index ccabdb20..c7aa8a80 100644 --- a/cmd/webhooks/list.go +++ b/cmd/webhooks/list.go @@ -7,11 +7,11 @@ import ( stdctx "context" "fmt" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" "github.com/urfave/cli/v3" ) @@ -40,11 +40,11 @@ func RunWebhooksList(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - hooks, _, err = client.ListOrgHooks(c.Org, gitea.ListHooksOptions{ + hooks, _, err = client.Hooks.ListOrgHooks(ctx, c.Org, gitea.ListHooksOptions{ ListOptions: flags.GetListOptions(cmd), }) } else { - hooks, _, err = client.ListRepoHooks(c.Owner, c.Repo, gitea.ListHooksOptions{ + hooks, _, err = client.Hooks.ListRepoHooks(ctx, c.Owner, c.Repo, gitea.ListHooksOptions{ ListOptions: flags.GetListOptions(cmd), }) } diff --git a/cmd/webhooks/update.go b/cmd/webhooks/update.go index e37fcb42..7c1b39e6 100644 --- a/cmd/webhooks/update.go +++ b/cmd/webhooks/update.go @@ -8,11 +8,11 @@ import ( "fmt" "strings" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/utils" "github.com/urfave/cli/v3" ) @@ -77,9 +77,9 @@ func runWebhooksUpdate(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - hook, _, err = client.GetOrgHook(c.Org, int64(webhookID)) + hook, _, err = client.Hooks.GetOrgHook(ctx, c.Org, int64(webhookID)) } else { - hook, _, err = client.GetRepoHook(c.Owner, c.Repo, int64(webhookID)) + hook, _, err = client.Hooks.GetRepoHook(ctx, c.Owner, c.Repo, int64(webhookID)) } if err != nil { return err @@ -128,7 +128,7 @@ func runWebhooksUpdate(ctx stdctx.Context, cmd *cli.Command) error { if c.IsGlobal { return fmt.Errorf("global webhooks not yet supported in this version") } else if len(c.Org) > 0 { - _, err = client.EditOrgHook(c.Org, int64(webhookID), gitea.EditHookOption{ + _, err = client.Hooks.EditOrgHook(ctx, c.Org, int64(webhookID), gitea.EditHookOption{ Config: config, Events: events, Active: &active, @@ -136,7 +136,7 @@ func runWebhooksUpdate(ctx stdctx.Context, cmd *cli.Command) error { AuthorizationHeader: authHeader, }) } else { - _, err = client.EditRepoHook(c.Owner, c.Repo, int64(webhookID), gitea.EditHookOption{ + _, err = client.Hooks.EditRepoHook(ctx, c.Owner, c.Repo, int64(webhookID), gitea.EditHookOption{ Config: config, Events: events, Active: &active, diff --git a/cmd/webhooks/update_test.go b/cmd/webhooks/update_test.go index 70df1e0d..882d905b 100644 --- a/cmd/webhooks/update_test.go +++ b/cmd/webhooks/update_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/urfave/cli/v3" ) diff --git a/cmd/whoami.go b/cmd/whoami.go index be461a5e..a6ccea39 100644 --- a/cmd/whoami.go +++ b/cmd/whoami.go @@ -6,9 +6,10 @@ package cmd import ( stdctx "context" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" ) // CmdWhoami represents the command to show current logged in user @@ -18,13 +19,13 @@ var CmdWhoami = cli.Command{ Description: `For debugging purposes, show the user that is currently logged in.`, Usage: "Show current logged in user", ArgsUsage: " ", // command does not accept arguments - 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 } client := ctx.Login.Client() - user, _, _ := client.GetMyUserInfo() + user, _, _ := client.Users.GetMyUserInfo(requestCtx) print.UserDetails(user) return nil }, diff --git a/docs/docs.go b/docs/docs.go index 756ea80a..8aab49b1 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -8,9 +8,10 @@ import ( "context" "os" - "code.gitea.io/tea/cmd" docs "github.com/urfave/cli-docs/v3" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd" ) // CmdDocs generates markdown for tea diff --git a/go.mod b/go.mod index c5ef4c31..b3c9d250 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module code.gitea.io/tea +module gitea.dev/tea go 1.26 @@ -7,97 +7,84 @@ require ( charm.land/huh/v2 v2.0.3 charm.land/lipgloss/v2 v2.0.3 code.gitea.io/gitea-vet v0.2.3 - code.gitea.io/sdk/gitea v0.25.0 gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c + gitea.dev/sdk v1.0.1 github.com/adrg/xdg v0.5.3 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/enescakir/emoji v1.0.0 - github.com/go-authgate/sdk-go v0.10.0 - github.com/go-git/go-git/v5 v5.18.0 + github.com/go-authgate/sdk-go v0.11.0 github.com/muesli/termenv v0.16.0 github.com/olekukonko/tablewriter v1.1.4 github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/stretchr/testify v1.11.1 github.com/urfave/cli-docs/v3 v3.1.0 - github.com/urfave/cli/v3 v3.8.0 - golang.org/x/crypto v0.50.0 + github.com/urfave/cli/v3 v3.9.0 + golang.org/x/crypto v0.52.0 golang.org/x/oauth2 v0.36.0 - golang.org/x/sys v0.43.0 - golang.org/x/term v0.42.0 + golang.org/x/sys v0.45.0 + golang.org/x/term v0.43.0 gopkg.in/yaml.v3 v3.0.1 ) require ( charm.land/bubbles/v2 v2.1.0 // indirect - charm.land/bubbletea/v2 v2.0.2 // indirect - dario.cat/mergo v1.0.2 // indirect + charm.land/bubbletea/v2 v2.0.6 // indirect github.com/42wim/httpsig v1.2.4 // indirect - github.com/Microsoft/go-winio v0.6.2 // indirect - github.com/ProtonMail/go-crypto v1.4.1 // indirect - github.com/alecthomas/chroma/v2 v2.23.1 // indirect + github.com/alecthomas/chroma/v2 v2.24.1 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/aymerick/douceur v0.2.0 // indirect github.com/catppuccin/go v0.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/charmbracelet/colorprofile v0.4.3 // indirect - github.com/charmbracelet/ultraviolet v0.0.0-20260330092749-0f94982c930b // indirect + github.com/charmbracelet/ultraviolet v0.0.0-20260511121909-c840852527f3 // indirect github.com/charmbracelet/x/ansi v0.11.7 // indirect github.com/charmbracelet/x/exp/ordered v0.1.0 // indirect - github.com/charmbracelet/x/exp/slice v0.0.0-20260406091427-a791e22d5143 // indirect + github.com/charmbracelet/x/exp/slice v0.0.0-20260511125431-fe5d686e0c99 // indirect github.com/charmbracelet/x/exp/strings v0.1.0 // indirect github.com/charmbracelet/x/term v0.2.2 // indirect github.com/charmbracelet/x/termios v0.1.1 // indirect github.com/charmbracelet/x/windows v0.2.2 // indirect github.com/clipperhouse/displaywidth v0.11.0 // indirect github.com/clipperhouse/uax29/v2 v2.7.0 // indirect - github.com/cloudflare/circl v1.6.3 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect - github.com/cyphar/filepath-securejoin v0.6.1 // indirect github.com/danieljoos/wincred v1.2.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/davidmz/go-pageant v1.0.2 // indirect - github.com/dlclark/regexp2 v1.11.5 // indirect + github.com/dlclark/regexp2 v1.12.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/color v1.19.0 // indirect github.com/go-fed/httpsig v1.1.0 // indirect - github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.8.0 // indirect github.com/goccy/go-json v0.10.6 // indirect github.com/godbus/dbus/v5 v5.2.2 // indirect - github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect + github.com/google/go-cmp v0.7.0 // indirect github.com/gorilla/css v1.0.1 // indirect github.com/hashicorp/go-version v1.9.0 // indirect - github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect - github.com/kevinburke/ssh_config v1.6.0 // indirect - github.com/klauspost/cpuid/v2 v2.3.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/lucasb-eyer/go-colorful v1.4.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect - github.com/mattn/go-isatty v0.0.21 // indirect + github.com/mattn/go-isatty v0.0.22 // indirect github.com/mattn/go-runewidth v0.0.23 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 // indirect - github.com/olekukonko/errors v1.2.0 // indirect + github.com/olekukonko/errors v1.3.0 // indirect github.com/olekukonko/ll v0.1.8 // indirect - github.com/pjbgf/sha1cd v0.5.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/sergi/go-diff v1.4.0 // indirect - github.com/skeema/knownhosts v1.3.2 // indirect - github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/yuin/goldmark v1.8.2 // indirect github.com/yuin/goldmark-emoji v1.0.6 // indirect github.com/zalando/go-keyring v0.2.8 // indirect - golang.org/x/net v0.53.0 // indirect + golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f // indirect + golang.org/x/net v0.55.0 // indirect golang.org/x/sync v0.20.0 // indirect - golang.org/x/text v0.36.0 // indirect - golang.org/x/tools v0.44.0 // indirect - gopkg.in/warnings.v0 v0.1.2 // indirect + golang.org/x/text v0.37.0 // indirect + golang.org/x/tools v0.45.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect ) retract v1.3.3 // accidental release, tag deleted diff --git a/go.sum b/go.sum index 6cdf58f6..bf859c6e 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ charm.land/bubbles/v2 v2.1.0 h1:YSnNh5cPYlYjPxRrzs5VEn3vwhtEn3jVGRBT3M7/I0g= charm.land/bubbles/v2 v2.1.0/go.mod h1:l97h4hym2hvWBVfmJDtrEHHCtkIKeTEb3TTJ4ZOB3wY= -charm.land/bubbletea/v2 v2.0.2 h1:4CRtRnuZOdFDTWSff9r8QFt/9+z6Emubz3aDMnf/dx0= -charm.land/bubbletea/v2 v2.0.2/go.mod h1:3LRff2U4WIYXy7MTxfbAQ+AdfM3D8Xuvz2wbsOD9OHQ= +charm.land/bubbletea/v2 v2.0.6 h1:UHN/91OyuhaOFGSrBXQ/hMZD8IO1Uc4BvHlgHXL2WJo= +charm.land/bubbletea/v2 v2.0.6/go.mod h1:MH/D8ZLlN3op37vQvijKuU29g3rqTp+aQapURFonF9g= charm.land/glamour/v2 v2.0.0 h1:IDBoqLEy7Hdpb9VOXN+khLP/XSxtJy1VsHuW/yF87+U= charm.land/glamour/v2 v2.0.0/go.mod h1:kjq9WB0s8vuUYZNYey2jp4Lgd9f4cKdzAw88FZtpj/w= charm.land/huh/v2 v2.0.3 h1:2cJsMqEPwSywGHvdlKsJyQKPtSJLVnFKyFbsYZTlLkU= @@ -10,35 +10,32 @@ charm.land/lipgloss/v2 v2.0.3 h1:yM2zJ4Cf5Y51b7RHIwioil4ApI/aypFXXVHSwlM6RzU= charm.land/lipgloss/v2 v2.0.3/go.mod h1:7myLU9iG/3xluAWzpY/fSxYYHCgoKTie7laxk6ATwXA= code.gitea.io/gitea-vet v0.2.3 h1:gdFmm6WOTM65rE8FUBTRzeQZYzXePKSSB1+r574hWwI= code.gitea.io/gitea-vet v0.2.3/go.mod h1:zcNbT/aJEmivCAhfmkHOlT645KNOf9W2KnkLgFjGGfE= -code.gitea.io/sdk/gitea v0.25.0 h1:wSJlL0Qv+ODY2OdF0L7fwt86wgf1C/0g3xIXZ6eC5zI= -code.gitea.io/sdk/gitea v0.25.0/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg= dario.cat/mergo v1.0.2 h1:85+piFYR1tMbRrLcDwR18y4UKJ3aH1Tbzi24VRW1TK8= dario.cat/mergo v1.0.2/go.mod h1:E/hbnu0NxMFBjpMIE34DRGLWqDy0g5FuKDhCb31ngxA= gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c h1:8fTkq2UaVkLHZCF+iB4wTxINmVAToe2geZGayk9LMbA= gitea.com/noerw/unidiff-comments v0.0.0-20220822113322-50f4daa0e35c/go.mod h1:Fc8iyPm4NINRWujeIk2bTfcbGc4ZYY29/oMAAGcr4qI= +gitea.dev/sdk v0.0.0-20260525162228-ffb5234862e0 h1:ZqpFhspucP2OpkgxWdrXEulp5RLKpIXKqb1aHdewtIg= +gitea.dev/sdk v0.0.0-20260525162228-ffb5234862e0/go.mod h1:jCf5Uzz0Jkb61jxNgMxLOCWwle1J1B2nKdcRtxuK9rY= +gitea.dev/sdk v1.0.0 h1:S7FDAeRnvOwOgWKoEGKsTsjf9jg/b6tcDIzxFY9AiEo= +gitea.dev/sdk v1.0.0/go.mod h1:jCf5Uzz0Jkb61jxNgMxLOCWwle1J1B2nKdcRtxuK9rY= +gitea.dev/sdk v1.0.1-0.20260526041347-23be5b0596e7 h1:06cYUmiIO2X4fsxKmCmkRXKxitaF7s1ZultK5YZvqKU= +gitea.dev/sdk v1.0.1-0.20260526041347-23be5b0596e7/go.mod h1:jCf5Uzz0Jkb61jxNgMxLOCWwle1J1B2nKdcRtxuK9rY= +gitea.dev/sdk v1.0.1 h1:CWXQUQvp2I6YKOWkhYo1Flx2sRNfMK1X9Op4oR2awXs= +gitea.dev/sdk v1.0.1/go.mod h1:jCf5Uzz0Jkb61jxNgMxLOCWwle1J1B2nKdcRtxuK9rY= github.com/42wim/httpsig v1.2.4 h1:mI5bH0nm4xn7K18fo1K3okNDRq8CCJ0KbBYWyA6r8lU= github.com/42wim/httpsig v1.2.4/go.mod h1:yKsYfSyTBEohkPik224QPFylmzEBtda/kjyIAJjh3ps= github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= -github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= -github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= -github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM= -github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo= github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0= github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= -github.com/alecthomas/chroma/v2 v2.23.1 h1:nv2AVZdTyClGbVQkIzlDm/rnhk1E9bU9nXwmZ/Vk/iY= -github.com/alecthomas/chroma/v2 v2.23.1/go.mod h1:NqVhfBR0lte5Ouh3DcthuUCTUpDC9cxBOfyMbMQPs3o= +github.com/alecthomas/chroma/v2 v2.24.1 h1:m5ffpfZbIb++k8AqFEKy9uVgY12xIQtBsQlc6DfZJQM= +github.com/alecthomas/chroma/v2 v2.24.1/go.mod h1:l+ohZ9xRXIbGe7cIW+YZgOGbvuVLjMps/FYN/CwuabI= github.com/alecthomas/repr v0.5.2 h1:SU73FTI9D1P5UNtvseffFSGmdNci/O6RsqzeXJtP0Qs= github.com/alecthomas/repr v0.5.2/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= -github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= -github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= -github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= @@ -53,8 +50,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q= -github.com/charmbracelet/ultraviolet v0.0.0-20260330092749-0f94982c930b h1:ASDO9RT6SNKTQN87jO2bRfxHFJq8cgeYdFzivY2gCeM= -github.com/charmbracelet/ultraviolet v0.0.0-20260330092749-0f94982c930b/go.mod h1:Vo8TffMf0q7Uho/n8e6XpBZvOWtd3g39yX+9P5rRutA= +github.com/charmbracelet/ultraviolet v0.0.0-20260511121909-c840852527f3 h1:pxGjlWZFcRQMWAdtjRelpL3Gbu8iYIyuO3Eqbd037Ow= +github.com/charmbracelet/ultraviolet v0.0.0-20260511121909-c840852527f3/go.mod h1:SnKWaPaTnkTNXJgdgdquu66de12V8pW/b/qlTGaF9xg= github.com/charmbracelet/x/ansi v0.11.7 h1:kzv1kJvjg2S3r9KHo8hDdHFQLEqn4RBCb39dAYC84jI= github.com/charmbracelet/x/ansi v0.11.7/go.mod h1:9qGpnAVYz+8ACONkZBUWPtL7lulP9No6p1epAihUZwQ= github.com/charmbracelet/x/conpty v0.1.1 h1:s1bUxjoi7EpqiXysVtC+a8RrvPPNcNvAjfi4jxsAuEs= @@ -65,8 +62,8 @@ github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6g github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I= github.com/charmbracelet/x/exp/ordered v0.1.0 h1:55/qLwjIh0gL0Vni+QAWk7T/qRVP6sBf+2agPBgnOFE= github.com/charmbracelet/x/exp/ordered v0.1.0/go.mod h1:5UHwmG+is5THxMyCJHNPCn2/ecI07aKNrW+LcResjJ8= -github.com/charmbracelet/x/exp/slice v0.0.0-20260406091427-a791e22d5143 h1:aEppolah2k9c0LzKX2fk5ryuyQ0Lq8kCOjkvMw1b8o4= -github.com/charmbracelet/x/exp/slice v0.0.0-20260406091427-a791e22d5143/go.mod h1:vqEfX6xzqW1pKKZUUiFOKg0OQ7bCh54Q2vR/tserrRA= +github.com/charmbracelet/x/exp/slice v0.0.0-20260511125431-fe5d686e0c99 h1:e4VttUIAVgO4neqnJG80U4BE//1kcvyOrJ5utftPXQE= +github.com/charmbracelet/x/exp/slice v0.0.0-20260511125431-fe5d686e0c99/go.mod h1:vqEfX6xzqW1pKKZUUiFOKg0OQ7bCh54Q2vR/tserrRA= github.com/charmbracelet/x/exp/strings v0.1.0 h1:i69S2XI7uG1u4NLGeJPSYU++Nmjvpo9nwd6aoEm7gkA= github.com/charmbracelet/x/exp/strings v0.1.0/go.mod h1:/ehtMPNh9K4odGFkqYJKpIYyePhdp1hLBRvyY4bWkH8= github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= @@ -81,14 +78,11 @@ github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSE github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= -github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8= -github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4= github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= -github.com/cyphar/filepath-securejoin v0.6.1 h1:5CeZ1jPXEiYt3+Z6zqprSAgSWiggmpVyciv8syjIpVE= -github.com/cyphar/filepath-securejoin v0.6.1/go.mod h1:A8hd4EnAeyujCJRrICiOWqjS1AX0a9kM5XL+NwKoYSc= github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -96,22 +90,16 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= -github.com/dlclark/regexp2 v1.11.5 h1:Q/sSnsKerHeCkc/jSTNq1oCm7KiVgUMZRDUoRu0JQZQ= -github.com/dlclark/regexp2 v1.11.5/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= +github.com/dlclark/regexp2 v1.12.0 h1:0j4c5qQmnC6XOWNjP3PIXURXN2gWx76rd3KvgdPkCz8= +github.com/dlclark/regexp2 v1.12.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o= -github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog= github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0= github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= -github.com/go-authgate/sdk-go v0.10.0 h1:MNcfV6XSPs63SWPDdLqoJ9CFiKlXIue1RmiAbTXDAEI= -github.com/go-authgate/sdk-go v0.10.0/go.mod h1:Afx/Dbyvf8pw4YeOqVEVdDW2WHhn534Sb2/TaFQktuU= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= @@ -122,12 +110,12 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.18.0 h1:O831KI+0PR51hM2kep6T8k+w0/LIAD490gvqMCvL5hM= github.com/go-git/go-git/v5 v5.18.0/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo= +github.com/go-authgate/sdk-go v0.11.0 h1:ZTfJ0rzeDn4QBqAmF9VKS3CqlKhE8+0tJxg8OGNtIzo= +github.com/go-authgate/sdk-go v0.11.0/go.mod h1:sa0ige5wtayj2WcnXlxa8wGuyi5z/c/chc0mXPJTl/Q= github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU= github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= @@ -136,13 +124,7 @@ github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaX github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= -github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY= -github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M= -github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= -github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -153,8 +135,8 @@ github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= -github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs= -github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= +github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4= +github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4= github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw= github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= @@ -168,23 +150,19 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6 h1:zrbMGy9YXpIeTnGj4EljqMiZsIcE09mmF8XsD5AYOJc= github.com/olekukonko/cat v0.0.0-20250911104152-50322a0618f6/go.mod h1:rEKTHC9roVVicUIfZK7DYrdIoM0EOr8mK1Hj5s3JjH0= -github.com/olekukonko/errors v1.2.0 h1:10Zcn4GeV59t/EGqJc8fUjtFT/FuUh5bTMzZ1XwmCRo= -github.com/olekukonko/errors v1.2.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y= +github.com/olekukonko/errors v1.3.0 h1:teJvgLGUEqMzBUms+Dj3/3szNqCG/Jdw9iDbum8fR6U= +github.com/olekukonko/errors v1.3.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y= github.com/olekukonko/ll v0.1.8 h1:ysHCJRGHYKzmBSdz9w5AySztx7lG8SQY+naTGYUbsz8= github.com/olekukonko/ll v0.1.8/go.mod h1:RPRC6UcscfFZgjo1nulkfMH5IM0QAYim0LfnMvUuozw= github.com/olekukonko/tablewriter v1.1.4 h1:ORUMI3dXbMnRlRggJX3+q7OzQFDdvgbN9nVWj1drm6I= github.com/olekukonko/tablewriter v1.1.4/go.mod h1:+kedxuyTtgoZLwif3P1Em4hARJs+mVnzKxmsCL/C5RY= -github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= -github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= -github.com/pjbgf/sha1cd v0.5.0 h1:a+UkboSi1znleCDUNT3M5YxjOnN1fz2FhN48FlwCxs0= -github.com/pjbgf/sha1cd v0.5.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -192,27 +170,18 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD github.com/scylladb/termtables v0.0.0-20191203121021-c4c0b6d42ff4/go.mod h1:C1a7PQSMz9NShzorzCiG2fk9+xuCgLkPeCvMHYR2OWg= github.com/seletskiy/tplutil v0.0.0-20200921103632-f880f6245597 h1:nZY1S2jo+VtDrUfjO9XYI137O41hhRkxZNV5Fb5ixCA= github.com/seletskiy/tplutil v0.0.0-20200921103632-f880f6245597/go.mod h1:F8CBHSOjnzjx9EeXyWJTAzJyVxN+Y8JH2WjLMn4utiw= -github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= -github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skeema/knownhosts v1.3.2 h1:EDL9mgf4NzwMXCTfaxSD/o/a5fxDw/xL9nkU28JjdBg= -github.com/skeema/knownhosts v1.3.2/go.mod h1:bEg3iQAuw+jyiw+484wwFJoKSLwcfd7fqRy+N0QTiow= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 h1:JIAuq3EEf9cgbU6AtGPK4CTG3Zf6CKMNqf0MHTggAUA= github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966/go.mod h1:sUM3LWHvSMaG192sy56D9F7CNvL7jUJVXoqM1QKLnog= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/urfave/cli-docs/v3 v3.1.0 h1:Sa5xm19IpE5gpm6tZzXdfjdFxn67PnEsE4dpXF7vsKw= github.com/urfave/cli-docs/v3 v3.1.0/go.mod h1:59d+5Hz1h6GSGJ10cvcEkbIe3j233t4XDqI72UIx7to= -github.com/urfave/cli/v3 v3.8.0 h1:XqKPrm0q4P0q5JpoclYoCAv0/MIvH/jZ2umzuf8pNTI= -github.com/urfave/cli/v3 v3.8.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= -github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= -github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= +github.com/urfave/cli/v3 v3.9.0 h1:AV9lIiPv3ukYnxunaCUsHnEozptYmDN2F0+yWqLMn/c= +github.com/urfave/cli/v3 v3.9.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -226,21 +195,19 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.50.0 h1:zO47/JPrL6vsNkINmLoo/PH1gcxpls50DNogFvB5ZGI= -golang.org/x/crypto v0.50.0/go.mod h1:3muZ7vA7PBCE6xgPX7nkzzjiUq87kRItoJQM1Yo8S+Q= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988= +golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc= +golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM= +golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM= -golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU= +golang.org/x/mod v0.36.0 h1:JJjpVx6myfUsUdAzZuOSTTmRE0PfZeNWzzvKrP7amb4= +golang.org/x/mod v0.36.0/go.mod h1:moc6ELqsWcOw5Ef3xVprK5ul/MvtVvkIXLziUOICjUQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA= -golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs= +golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8= +golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww= golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -249,38 +216,27 @@ golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= -golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY= +golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY= -golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY= +golang.org/x/term v0.43.0 h1:S4RLU2sB31O/NCl+zFN9Aru9A/Cq2aqKpTZJ6B+DwT4= +golang.org/x/term v0.43.0/go.mod h1:lrhlHNdQJHO+1qVYiHfFKVuVioJIheAc3fBSMFYEIsk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg= -golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164= +golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc= +golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200325010219-a49f79bcc224/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c= -golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI= +golang.org/x/tools v0.45.0 h1:18qN3FAooORvApf5XjCXgsuayZOEtXf6JK18I3+ONa8= +golang.org/x/tools v0.45.0/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 1ad0405d..11c69cfb 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Tea is command line tool for Gitea. -package main // import "code.gitea.io/tea" +package main // import "gitea.dev/tea" import ( "context" @@ -10,9 +10,9 @@ import ( "fmt" "os" - "code.gitea.io/tea/cmd" - teacontext "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/debug" + "gitea.dev/tea/cmd" + teacontext "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/debug" ) func main() { diff --git a/modules/api/client.go b/modules/api/client.go index 853a2a06..7cd02044 100644 --- a/modules/api/client.go +++ b/modules/api/client.go @@ -12,8 +12,8 @@ import ( "net/url" "strings" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/httputil" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/httputil" ) // Client provides direct HTTP access to Gitea API diff --git a/modules/auth/oauth.go b/modules/auth/oauth.go index e1fd47ca..48bff99d 100644 --- a/modules/auth/oauth.go +++ b/modules/auth/oauth.go @@ -17,10 +17,10 @@ import ( "strings" "time" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/httputil" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/httputil" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "github.com/skratchdot/open-golang/open" "golang.org/x/oauth2" @@ -53,12 +53,12 @@ type OAuthOptions struct { } // OAuthLogin performs an OAuth2 PKCE login flow to authorize the CLI -func OAuthLogin(name, giteaURL string) error { - return OAuthLoginWithOptions(name, giteaURL, false) +func OAuthLogin(ctx context.Context, name, giteaURL string) error { + return OAuthLoginWithOptions(ctx, name, giteaURL, false) } // OAuthLoginWithOptions performs an OAuth2 PKCE login flow with additional options -func OAuthLoginWithOptions(name, giteaURL string, insecure bool) error { +func OAuthLoginWithOptions(ctx context.Context, name, giteaURL string, insecure bool) error { opts := OAuthOptions{ Name: name, URL: giteaURL, @@ -67,22 +67,22 @@ func OAuthLoginWithOptions(name, giteaURL string, insecure bool) error { RedirectURL: fmt.Sprintf("http://%s:%d", redirectHost, redirectPort), Port: redirectPort, } - return OAuthLoginWithFullOptions(opts) + return OAuthLoginWithFullOptions(ctx, opts) } // OAuthLoginWithFullOptions performs an OAuth2 PKCE login flow with full options control -func OAuthLoginWithFullOptions(opts OAuthOptions) error { - serverURL, token, err := performBrowserOAuthFlow(opts) +func OAuthLoginWithFullOptions(ctx context.Context, opts OAuthOptions) error { + serverURL, token, err := performBrowserOAuthFlow(ctx, opts) if err != nil { return err } - return createLoginFromToken(opts.Name, serverURL, token, opts.Insecure) + return createLoginFromToken(ctx, opts.Name, serverURL, token, opts.Insecure) } // performBrowserOAuthFlow performs the browser-based OAuth2 PKCE flow and returns the token. // This is the shared implementation used by both new logins and re-authentication. -func performBrowserOAuthFlow(opts OAuthOptions) (serverURL string, token *oauth2.Token, err error) { +func performBrowserOAuthFlow(ctx context.Context, opts OAuthOptions) (serverURL string, token *oauth2.Token, err error) { // Normalize URL normalizedURL, err := utils.NormalizeURL(opts.URL) if err != nil { @@ -127,7 +127,6 @@ func performBrowserOAuthFlow(opts OAuthOptions) (serverURL string, token *oauth2 codeChallenge := generateCodeChallenge(codeVerifier) // Set up the OAuth2 config - ctx := context.Background() ctx = context.WithValue(ctx, oauth2.HTTPClient, createHTTPClient(opts.Insecure)) // Configure the OAuth2 endpoints @@ -366,7 +365,7 @@ func openBrowser(url string) error { } // createLoginFromToken creates a login entry using the obtained access token -func createLoginFromToken(name, serverURL string, token *oauth2.Token, insecure bool) error { +func createLoginFromToken(ctx context.Context, name, serverURL string, token *oauth2.Token, insecure bool) error { if name == "" { var err error name, err = task.GenerateLoginName(serverURL, "") @@ -388,7 +387,7 @@ func createLoginFromToken(name, serverURL string, token *oauth2.Token, insecure // Validate token by getting user info client := login.Client() - u, _, err := client.GetMyUserInfo() + u, _, err := client.Users.GetMyUserInfo(ctx) if err != nil { return fmt.Errorf("failed to validate token: %s", err) } @@ -429,7 +428,7 @@ func RefreshAccessToken(login *config.Login) error { // ReauthenticateLogin performs a full browser-based OAuth flow to get new tokens // for an existing login. This is used when the refresh token is expired or invalid. -func ReauthenticateLogin(login *config.Login) error { +func ReauthenticateLogin(ctx context.Context, login *config.Login) error { opts := OAuthOptions{ Name: login.Name, URL: login.URL, @@ -439,7 +438,7 @@ func ReauthenticateLogin(login *config.Login) error { Port: redirectPort, } - _, token, err := performBrowserOAuthFlow(opts) + _, token, err := performBrowserOAuthFlow(ctx, opts) if err != nil { return err } diff --git a/modules/config/config.go b/modules/config/config.go index 18a22415..73a58d27 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -9,7 +9,7 @@ import ( "path/filepath" "sync" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/modules/utils" "github.com/adrg/xdg" "gopkg.in/yaml.v3" diff --git a/modules/config/lock.go b/modules/config/lock.go index 7a5a0326..a8310c7e 100644 --- a/modules/config/lock.go +++ b/modules/config/lock.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "code.gitea.io/tea/modules/filelock" + "gitea.dev/tea/modules/filelock" ) const ( diff --git a/modules/config/login.go b/modules/config/login.go index 9a7849df..8ca55188 100644 --- a/modules/config/login.go +++ b/modules/config/login.go @@ -15,11 +15,12 @@ import ( "strings" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/debug" - "code.gitea.io/tea/modules/httputil" - "code.gitea.io/tea/modules/theme" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/debug" + "gitea.dev/tea/modules/httputil" + "gitea.dev/tea/modules/theme" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" "golang.org/x/oauth2" @@ -341,7 +342,7 @@ func (l *Login) RefreshOAuthToken() error { } // Still need to refresh - proceed with OAuth call - newToken, err := doOAuthRefresh(l) + newToken, err := doOAuthRefresh(context.Background(), l) if err != nil { return err } @@ -369,7 +370,7 @@ func (l *Login) RefreshOAuthToken() error { } // doOAuthRefresh performs the actual OAuth token refresh API call. -func doOAuthRefresh(l *Login) (*oauth2.Token, error) { +func doOAuthRefresh(ctx context.Context, l *Login) (*oauth2.Token, error) { // Build current token from credstore (single load) or YAML fields var accessToken, refreshToken string var expiry time.Time @@ -388,8 +389,6 @@ func doOAuthRefresh(l *Login) (*oauth2.Token, error) { Expiry: expiry, } - ctx := context.Background() - httpClient := &http.Client{ Transport: httputil.WrapTransport(&http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: l.Insecure}, diff --git a/modules/config/testtools.go b/modules/config/testtools.go index 384cfe24..2bec228d 100644 --- a/modules/config/testtools.go +++ b/modules/config/testtools.go @@ -1,8 +1,6 @@ // Copyright 2026 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT -//go:build testtools - package config import "time" diff --git a/modules/context/context.go b/modules/context/context.go index 7255c68b..eedbcf3e 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -9,13 +9,12 @@ import ( "os" "strings" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/git" - "code.gitea.io/tea/modules/theme" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/git" + "gitea.dev/tea/modules/theme" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" - gogit "github.com/go-git/go-git/v5" "github.com/urfave/cli/v3" "golang.org/x/term" ) @@ -104,21 +103,23 @@ func InitCommand(cmd *cli.Command) (*TeaContext, error) { // try to read local git repo & extract context: if repoFlag specifies a valid path, read repo in that dir, // otherwise attempt PWD. if no repo is found, continue with default login - if c.RepoSlug == "" { - if repoPath == "" { - if repoPath, err = os.Getwd(); err != nil { - return nil, err - } + if repoPath == "" { + if repoPath, err = os.Getwd(); err != nil { + return nil, err } + } - if c.LocalRepo, c.Login, c.RepoSlug, err = contextFromLocalRepo(repoPath, remoteFlag, extraLogins); err != nil { - if err == errNotAGiteaRepo || err == gogit.ErrRepositoryNotExists { - // we can deal with that, commands needing the optional values use ctx.Ensure() - } else { - return nil, err - } + var localSlug string + if c.LocalRepo, c.Login, localSlug, err = contextFromLocalRepo(repoPath, remoteFlag, extraLogins); err != nil { + if err == errNotAGiteaRepo || err == git.ErrRepositoryNotExists { + // we can deal with that, commands needing the optional values use ctx.Ensure() + } else { + return nil, err } } + if c.RepoSlug == "" && localSlug != "" { + c.RepoSlug = localSlug + } // If env vars are set, always use the env login (but repo slug was already // resolved by contextFromLocalRepo with the env login in the match list) diff --git a/modules/context/context_login.go b/modules/context/context_login.go index 76223d1d..65535a75 100644 --- a/modules/context/context_login.go +++ b/modules/context/context_login.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" ) // GetLoginByEnvVar returns a login based on environment variables, or nil if no login can be created diff --git a/modules/context/context_prompt_test.go b/modules/context/context_prompt_test.go index ae0fded0..ba6df20d 100644 --- a/modules/context/context_prompt_test.go +++ b/modules/context/context_prompt_test.go @@ -6,7 +6,7 @@ package context import ( "testing" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" ) func TestShouldPromptFallbackLogin(t *testing.T) { diff --git a/modules/context/context_remote.go b/modules/context/context_remote.go index 61dc4bdd..99690170 100644 --- a/modules/context/context_remote.go +++ b/modules/context/context_remote.go @@ -7,9 +7,9 @@ import ( "fmt" "strings" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/debug" - "code.gitea.io/tea/modules/git" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/debug" + "gitea.dev/tea/modules/git" ) // MatchLogins matches the given remoteURL against the provided logins and returns diff --git a/modules/context/context_repo.go b/modules/context/context_repo.go index ca44bfb2..ab9c238f 100644 --- a/modules/context/context_repo.go +++ b/modules/context/context_repo.go @@ -6,9 +6,9 @@ package context import ( "fmt" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/debug" - "code.gitea.io/tea/modules/git" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/debug" + "gitea.dev/tea/modules/git" ) // contextFromLocalRepo discovers login & repo slug from the default branch remote of the given local repo diff --git a/modules/context/context_require_test.go b/modules/context/context_require_test.go index a3a338cb..db808fd8 100644 --- a/modules/context/context_require_test.go +++ b/modules/context/context_require_test.go @@ -6,10 +6,11 @@ package context import ( "testing" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/git" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/git" ) func TestEnsureReturnsRequirementErrors(t *testing.T) { diff --git a/modules/context/context_test.go b/modules/context/context_test.go index 9b73f887..01db9327 100644 --- a/modules/context/context_test.go +++ b/modules/context/context_test.go @@ -6,7 +6,7 @@ package context import ( "testing" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" ) func Test_MatchLogins(t *testing.T) { diff --git a/modules/git/auth.go b/modules/git/auth.go index 1a9e474e..9d7c0bfd 100644 --- a/modules/git/auth.go +++ b/modules/git/auth.go @@ -7,69 +7,64 @@ import ( "fmt" "net/url" "os" + "strings" - "code.gitea.io/tea/modules/utils" - - git_transport "github.com/go-git/go-git/v5/plumbing/transport" - gogit_http "github.com/go-git/go-git/v5/plumbing/transport/http" - gogit_ssh "github.com/go-git/go-git/v5/plumbing/transport/ssh" + "gitea.dev/tea/modules/utils" "golang.org/x/crypto/ssh" ) type pwCallback = func(string) (string, error) -// GetAuthForURL returns the appropriate AuthMethod to be used in Push() / Pull() -// operations depending on the protocol, and prompts the user for credentials if -// necessary. -func GetAuthForURL(remoteURL *url.URL, authToken, keyFile string, passwordCallback pwCallback) (git_transport.AuthMethod, error) { +// GetAuthForURL returns backend-agnostic auth settings for git network operations. +func GetAuthForURL(remoteURL *url.URL, authToken, keyFile string, passwordCallback pwCallback) (*AuthMethod, error) { switch remoteURL.Scheme { case "http", "https": - // gitea supports push/pull via app token as username. - return &gogit_http.BasicAuth{Password: "", Username: authToken}, nil - + return &AuthMethod{Scheme: remoteURL.Scheme, Username: authToken}, nil case "ssh": - // try to select right key via ssh-agent. if it fails, try to read a key manually - user := remoteURL.User.Username() - auth, err := gogit_ssh.DefaultAuthBuilder(user) - if err != nil { - signer, err2 := readSSHPrivKey(keyFile, passwordCallback) - if err2 != nil { - return nil, err2 - } - auth = &gogit_ssh.PublicKeys{User: user, Signer: signer} + if keyFile == "" { + return &AuthMethod{Scheme: remoteURL.Scheme, Username: remoteURL.User.Username()}, nil + } + expandedKeyFile, err := utils.AbsPathWithExpansion(keyFile) + if err != nil { + return nil, err + } + sshKey, err := os.ReadFile(expandedKeyFile) + if err != nil { + return nil, fmt.Errorf("can not read ssh key '%s'", expandedKeyFile) } - return auth, nil - } - return nil, fmt.Errorf("don't know how to handle url scheme %v", remoteURL.Scheme) -} -func readSSHPrivKey(keyFile string, passwordCallback pwCallback) (sig ssh.Signer, err error) { - if keyFile != "" { - keyFile, err = utils.AbsPathWithExpansion(keyFile) - } else { - keyFile, err = utils.AbsPathWithExpansion("~/.ssh/id_rsa") - } - if err != nil { - return nil, err - } - sshKey, err := os.ReadFile(keyFile) - if err != nil { - return nil, fmt.Errorf("can not read ssh key '%s'", keyFile) - } - sig, err = ssh.ParsePrivateKey(sshKey) - if _, ok := err.(*ssh.PassphraseMissingError); ok && passwordCallback != nil { - // allow for up to 3 password attempts - for i := 0; i < 3; i++ { - var pass string - pass, err = passwordCallback(keyFile) - if err != nil { + auth := &AuthMethod{ + Scheme: remoteURL.Scheme, + Username: remoteURL.User.Username(), + KeyFile: expandedKeyFile, + } + if _, err := ssh.ParsePrivateKey(sshKey); err == nil { + return auth, nil + } + + if _, ok := err.(*ssh.PassphraseMissingError); ok { + if passwordCallback == nil { return nil, err } - sig, err = ssh.ParsePrivateKeyWithPassphrase(sshKey, []byte(pass)) - if err == nil { - break + for i := 0; i < 3; i++ { + pass, err := passwordCallback(expandedKeyFile) + if err != nil { + return nil, err + } + if _, err := ssh.ParsePrivateKeyWithPassphrase(sshKey, []byte(pass)); err == nil { + auth.KeyPassphrase = pass + return auth, nil + } } + return nil, err } + + return nil, err + default: + return nil, fmt.Errorf("don't know how to handle url scheme %v", remoteURL.Scheme) } - return sig, err +} + +func shellQuote(s string) string { + return "'" + strings.ReplaceAll(s, "'", "'\\''") + "'" } diff --git a/modules/git/backend.go b/modules/git/backend.go new file mode 100644 index 00000000..49e62897 --- /dev/null +++ b/modules/git/backend.go @@ -0,0 +1,103 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "fmt" + "sort" + "sync" +) + +var backendRegistry = struct { + sync.RWMutex + current string + backends map[string]Backend +}{ + backends: make(map[string]Backend), +} + +func init() { + mustRegisterBackend(cliBackend{}) + mustUseBackend("cli") +} + +// RegisterBackend makes a git backend available for later switching. +func RegisterBackend(backend Backend) error { + if backend == nil { + return fmt.Errorf("git backend is nil") + } + name := backend.Name() + if name == "" { + return fmt.Errorf("git backend name is empty") + } + + backendRegistry.Lock() + defer backendRegistry.Unlock() + backendRegistry.backends[name] = backend + if backendRegistry.current == "" { + backendRegistry.current = name + } + return nil +} + +func mustRegisterBackend(backend Backend) { + if err := RegisterBackend(backend); err != nil { + panic(err) + } +} + +// UseBackend switches the active git backend implementation. +func UseBackend(name string) error { + backendRegistry.Lock() + defer backendRegistry.Unlock() + if _, ok := backendRegistry.backends[name]; !ok { + return fmt.Errorf("git backend %q is not registered", name) + } + backendRegistry.current = name + return nil +} + +func mustUseBackend(name string) { + if err := UseBackend(name); err != nil { + panic(err) + } +} + +// CurrentBackendName returns the active backend name. +func CurrentBackendName() string { + backendRegistry.RLock() + defer backendRegistry.RUnlock() + return backendRegistry.current +} + +// RegisteredBackends returns all registered backend names. +func RegisteredBackends() []string { + backendRegistry.RLock() + defer backendRegistry.RUnlock() + out := make([]string, 0, len(backendRegistry.backends)) + for name := range backendRegistry.backends { + out = append(out, name) + } + sort.Strings(out) + return out +} + +func currentBackend() Backend { + backendRegistry.RLock() + defer backendRegistry.RUnlock() + return backendRegistry.backends[backendRegistry.current] +} + +func setBackendForTesting(t testingT, backend Backend) { + t.Helper() + prev := CurrentBackendName() + mustRegisterBackend(backend) + mustUseBackend(backend.Name()) + t.Cleanup(func() { mustUseBackend(prev) }) +} + +type testingT interface { + Cleanup(func()) + Helper() +} diff --git a/modules/git/backend_test.go b/modules/git/backend_test.go new file mode 100644 index 00000000..b514c5f0 --- /dev/null +++ b/modules/git/backend_test.go @@ -0,0 +1,74 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +type fakeBackend struct{} + +type fakeRepoBackend struct { + workTree string +} + +func (fakeBackend) Name() string { return "fake" } + +func (fakeBackend) Open(path string) (RepositoryBackend, error) { + return &fakeRepoBackend{workTree: "open:" + path}, nil +} + +func (fakeBackend) Clone(path, remoteURL string, auth *AuthMethod, opts CloneOptions) (RepositoryBackend, error) { + return &fakeRepoBackend{workTree: fmt.Sprintf("clone:%s:%s", path, remoteURL)}, nil +} + +func (r *fakeRepoBackend) WorkTree() string { return r.workTree } +func (r *fakeRepoBackend) Config() (*Config, error) { + return &Config{Remotes: map[string]*RemoteConfig{}, Branches: map[string]*Branch{}}, nil +} + +func (r *fakeRepoBackend) Head() (*Reference, error) { + return &Reference{name: NewBranchReferenceName("main"), hash: Hash("deadbeef")}, nil +} +func (r *fakeRepoBackend) AddRemote(name, remoteURL string) error { return nil } +func (r *fakeRepoBackend) SetBranchUpstream(branchName, remoteName, remoteBranch string) error { + return nil +} + +func (r *fakeRepoBackend) Fetch(remoteName string, refspecs []string, auth *AuthMethod) error { + return nil +} + +func (r *fakeRepoBackend) CreateTrackingBranch(localBranchName, remoteBranchName, remoteName string) error { + return nil +} +func (r *fakeRepoBackend) Checkout(ref ReferenceName) error { return nil } +func (r *fakeRepoBackend) DeleteLocalBranch(branchName string) error { return nil } +func (r *fakeRepoBackend) DeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error { + return nil +} +func (r *fakeRepoBackend) ListReferences(prefixes ...string) ([]*Reference, error) { return nil, nil } +func (r *fakeRepoBackend) PushToAgitFlowPR(remoteName, head, base, topic string, pushOptions map[string]string, auth *AuthMethod) error { + return nil +} + +func TestCanSwitchBackends(t *testing.T) { + setBackendForTesting(t, fakeBackend{}) + + repo, err := RepoFromPath("demo") + require.NoError(t, err) + require.Equal(t, "open:demo", repo.WorkTree()) + require.Equal(t, "fake", CurrentBackendName()) + + cloned, err := Clone("target", "https://example.com/repo.git", nil, 1, false) + require.NoError(t, err) + require.Equal(t, "clone:target:https://example.com/repo.git", cloned.WorkTree()) +} + +func TestRegisteredBackendsContainsCLI(t *testing.T) { + require.Contains(t, RegisteredBackends(), "cli") +} diff --git a/modules/git/branch.go b/modules/git/branch.go index eb6b6603..db531539 100644 --- a/modules/git/branch.go +++ b/modules/git/branch.go @@ -6,71 +6,33 @@ package git import ( "encoding/base64" "fmt" - "os" - "os/exec" "strings" "unicode" - - "github.com/go-git/go-git/v5" - git_config "github.com/go-git/go-git/v5/config" - git_plumbing "github.com/go-git/go-git/v5/plumbing" - git_transport "github.com/go-git/go-git/v5/plumbing/transport" ) // TeaCreateBranch creates a new branch in the repo, tracking from another branch. func (r TeaRepo) TeaCreateBranch(localBranchName, remoteBranchName, remoteName string) error { - localBranchRefName := git_plumbing.NewBranchReferenceName(localBranchName) - if _, err := r.Reference(localBranchRefName, true); err == nil { - return git.ErrBranchExists - } else if err != nil && err != git_plumbing.ErrReferenceNotFound { - return err - } - - return runGitCommand("branch", "--track", localBranchName, fmt.Sprintf("%s/%s", remoteName, remoteBranchName)) + return r.backend.CreateTrackingBranch(localBranchName, remoteBranchName, remoteName) } // TeaCheckout checks out the given branch in the worktree. -func (r TeaRepo) TeaCheckout(ref git_plumbing.ReferenceName) error { - args := []string{"checkout"} - if ref.IsRemote() { - args = append(args, "--detach", ref.String()) - } else if ref.IsBranch() { - args = append(args, ref.Short()) - } else { - args = append(args, ref.String()) - } - - return runGitCommand(args...) +func (r TeaRepo) TeaCheckout(ref ReferenceName) error { + return r.backend.Checkout(ref) } -// TeaDeleteLocalBranch removes the given branch locally -func (r TeaRepo) TeaDeleteLocalBranch(branch *git_config.Branch) error { - err := r.DeleteBranch(branch.Name) - // if the branch is not found that's ok, as .git/config may have no entry if - // no remote tracking branch is configured for it (eg push without -u flag) - if err != nil && err.Error() != "branch not found" { - return err - } - return r.Storer.RemoveReference(git_plumbing.NewBranchReferenceName(branch.Name)) +// TeaDeleteLocalBranch removes the given branch locally. +func (r TeaRepo) TeaDeleteLocalBranch(branch *Branch) error { + return r.backend.DeleteLocalBranch(branch.Name) } -// TeaDeleteRemoteBranch removes the given branch on the given remote via git protocol -func (r TeaRepo) TeaDeleteRemoteBranch(remoteName, remoteBranch string, auth git_transport.AuthMethod) error { - // delete remote branch via git protocol: - // an empty source in the refspec means remote deletion to git 🙃 - refspec := fmt.Sprintf(":%s", git_plumbing.NewBranchReferenceName(remoteBranch)) - return r.Push(&git.PushOptions{ - RemoteName: remoteName, - RefSpecs: []git_config.RefSpec{git_config.RefSpec(refspec)}, - Prune: true, - Auth: auth, - }) +// TeaDeleteRemoteBranch removes the given branch on the given remote via git protocol. +func (r TeaRepo) TeaDeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error { + return r.backend.DeleteRemoteBranch(remoteName, remoteBranch, auth) } // TeaFindBranchBySha returns a branch that is at the the given SHA and syncs to the // given remote repo. -func (r TeaRepo) TeaFindBranchBySha(sha, repoURL string) (b *git_config.Branch, err error) { - // find remote matching our repoURL +func (r TeaRepo) TeaFindBranchBySha(sha, repoURL string) (b *Branch, err error) { remote, err := r.GetRemote(repoURL) if err != nil { return nil, err @@ -80,41 +42,26 @@ func (r TeaRepo) TeaFindBranchBySha(sha, repoURL string) (b *git_config.Branch, } remoteName := remote.Config().Name - // check if the given remote has our branch (.git/refs/remotes//*) - iter, err := r.References() + refs, err := r.backend.ListReferences("refs/heads", "refs/remotes/"+remoteName) if err != nil { return nil, err } - defer iter.Close() - var remoteRefName git_plumbing.ReferenceName - var localRefName git_plumbing.ReferenceName - err = iter.ForEach(func(ref *git_plumbing.Reference) error { - if ref.Name().IsRemote() { - name := ref.Name().Short() - if ref.Hash().String() == sha && strings.HasPrefix(name, remoteName) { - remoteRefName = ref.Name() - } - } + var remoteRefName ReferenceName + var localRefName ReferenceName + for _, ref := range refs { + if ref.Name().IsRemote() && ref.Hash().String() == sha { + remoteRefName = ref.Name() + } if ref.Name().IsBranch() && ref.Hash().String() == sha { localRefName = ref.Name() } - return nil - }) - if err != nil { - return nil, err } if remoteRefName == "" || localRefName == "" { - // no remote tracking branch found, so a potential local branch - // can't be a match either return nil, nil } - b = &git_config.Branch{ - Remote: remoteName, - Name: localRefName.Short(), - Merge: localRefName, - } + b = &Branch{Remote: remoteName, Name: localRefName.Short(), Merge: localRefName} return b, b.Validate() } @@ -122,8 +69,7 @@ func (r TeaRepo) TeaFindBranchBySha(sha, repoURL string) (b *git_config.Branch, // remote names and syncs to the given remote repo. This method is less precise // than TeaFindBranchBySha(), but may be desirable if local and remote branch // have diverged. -func (r TeaRepo) TeaFindBranchByName(branchName, repoURL string) (b *git_config.Branch, err error) { - // find remote matching our repoURL +func (r TeaRepo) TeaFindBranchByName(branchName, repoURL string) (b *Branch, err error) { remote, err := r.GetRemote(repoURL) if err != nil { return nil, err @@ -133,45 +79,35 @@ func (r TeaRepo) TeaFindBranchByName(branchName, repoURL string) (b *git_config. } remoteName := remote.Config().Name - // check if the given remote has our branch (.git/refs/remotes//*) - iter, err := r.References() + refs, err := r.backend.ListReferences("refs/heads", "refs/remotes/"+remoteName) if err != nil { return nil, err } - defer iter.Close() - var remoteRefName git_plumbing.ReferenceName - var localRefName git_plumbing.ReferenceName + + var remoteRefName ReferenceName + var localRefName ReferenceName remoteSearchingName := fmt.Sprintf("%s/%s", remoteName, branchName) - err = iter.ForEach(func(ref *git_plumbing.Reference) error { + for _, ref := range refs { if ref.Name().IsRemote() && ref.Name().Short() == remoteSearchingName { remoteRefName = ref.Name() } - n := ref.Name() - if n.IsBranch() && n.Short() == branchName { - localRefName = n + if ref.Name().IsBranch() && ref.Name().Short() == branchName { + localRefName = ref.Name() } - return nil - }) - if err != nil { - return nil, err } if remoteRefName == "" || localRefName == "" { return nil, nil } - b = &git_config.Branch{ - Remote: remoteName, - Name: localRefName.Short(), - Merge: localRefName, - } + b = &Branch{Remote: remoteName, Name: localRefName.Short(), Merge: localRefName} return b, b.Validate() } // TeaFindBranchRemote gives the first remote that has a branch with the same name or sha, // depending on what is passed in. // This function is needed, as git does not always define branches in .git/config with remote entries. -// Priority order is: first match of sha and branch -> first match of branch -> first match of sha -func (r TeaRepo) TeaFindBranchRemote(branchName, hash string) (*git.Remote, error) { +// Priority order is: first match of sha and branch -> first match of branch -> first match of sha. +func (r TeaRepo) TeaFindBranchRemote(branchName, hash string) (*Remote, error) { remotes, err := r.Remotes() if err != nil { return nil, err @@ -184,55 +120,53 @@ func (r TeaRepo) TeaFindBranchRemote(branchName, hash string) (*git.Remote, erro return remotes[0], nil } - // check if the given remote has our branch (.git/refs/remotes//*) - iter, err := r.References() + refs, err := r.backend.ListReferences("refs/remotes") if err != nil { return nil, err } - defer iter.Close() - var shaMatch *git.Remote - var branchMatch *git.Remote - var fullMatch *git.Remote - if err := iter.ForEach(func(ref *git_plumbing.Reference) error { - if ref.Name().IsRemote() { - names := strings.SplitN(ref.Name().Short(), "/", 2) - remote := names[0] - branch := names[1] - if branchMatch == nil && branchName != "" && branchName == branch { - if branchMatch, err = r.Remote(remote); err != nil { - return err - } - } - if shaMatch == nil && hash != "" && hash == ref.Hash().String() { - if shaMatch, err = r.Remote(remote); err != nil { - return err - } - } - if fullMatch == nil && branchName != "" && branchName == branch && hash != "" && hash == ref.Hash().String() { - if fullMatch, err = r.Remote(remote); err != nil { - return err - } - // stop asap you have a full match - return nil - } + remoteByName := make(map[string]*Remote, len(remotes)) + for _, remote := range remotes { + remoteByName[remote.Config().Name] = remote + } + + var shaMatch *Remote + var branchMatch *Remote + var fullMatch *Remote + for _, ref := range refs { + remoteName, remoteBranch, ok := splitRemoteRef(ref.Name()) + if !ok { + continue + } + remote := remoteByName[remoteName] + if remote == nil { + continue + } + if branchMatch == nil && branchName != "" && branchName == remoteBranch { + branchMatch = remote + } + if shaMatch == nil && hash != "" && hash == ref.Hash().String() { + shaMatch = remote + } + if fullMatch == nil && branchName != "" && branchName == remoteBranch && hash != "" && hash == ref.Hash().String() { + fullMatch = remote + break } - return nil - }); err != nil { - return nil, err } - if fullMatch != nil { + switch { + case fullMatch != nil: return fullMatch, nil - } else if branchMatch != nil { + case branchMatch != nil: return branchMatch, nil - } else if shaMatch != nil { + case shaMatch != nil: return shaMatch, nil + default: + return nil, nil } - return nil, nil } -// TeaGetCurrentBranchNameAndSHA return the name and sha of the branch witch is currently active +// TeaGetCurrentBranchNameAndSHA return the name and sha of the branch witch is currently active. func (r TeaRepo) TeaGetCurrentBranchNameAndSHA() (string, string, error) { localHead, err := r.Head() if err != nil { @@ -247,13 +181,11 @@ func (r TeaRepo) TeaGetCurrentBranchNameAndSHA() (string, string, error) { } // PushToCreatAgitFlowPR pushes the given head to the refs/for// ref on the remote to create an agit flow PR. -func (r TeaRepo) PushToCreatAgitFlowPR(remoteName, head, base, topic, title, description string, auth git_transport.AuthMethod) error { +func (r TeaRepo) PushToCreatAgitFlowPR(remoteName, head, base, topic, title, description string, auth *AuthMethod) error { if !strings.HasPrefix(head, "refs/") { head = "refs/heads/" + head } - ref := fmt.Sprintf("%s:refs/for/%s/%s", head, base, topic) - pushOptions := make(map[string]string) if len(title) > 0 { pushOptions["title"] = b64Encode(title) @@ -261,15 +193,18 @@ func (r TeaRepo) PushToCreatAgitFlowPR(remoteName, head, base, topic, title, des if len(description) > 0 { pushOptions["description"] = b64Encode(description) } + return r.backend.PushToAgitFlowPR(remoteName, head, base, topic, pushOptions, auth) +} - opts := &git.PushOptions{ - RemoteName: remoteName, - RefSpecs: []git_config.RefSpec{git_config.RefSpec(ref)}, - Options: pushOptions, - Auth: auth, +func splitRemoteRef(ref ReferenceName) (remoteName, branchName string, ok bool) { + if !ref.IsRemote() { + return "", "", false } - - return r.Push(opts) + parts := strings.SplitN(ref.Short(), "/", 2) + if len(parts) != 2 { + return "", "", false + } + return parts[0], parts[1], true } // b64Encode implements base64 encode for string if necessary. @@ -289,19 +224,3 @@ func isASCII(s string) bool { } return true } - -func runGitCommand(args ...string) error { - cmd := exec.Command("git", args...) - cmd.Env = os.Environ() - output, err := cmd.CombinedOutput() - if err == nil { - return nil - } - - msg := strings.TrimSpace(string(output)) - if msg == "" { - return fmt.Errorf("git %s: %w", strings.Join(args, " "), err) - } - - return fmt.Errorf("git %s: %w: %s", strings.Join(args, " "), err, msg) -} diff --git a/modules/git/cli_backend.go b/modules/git/cli_backend.go new file mode 100644 index 00000000..99989e5a --- /dev/null +++ b/modules/git/cli_backend.go @@ -0,0 +1,374 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "bytes" + "encoding/base64" + "errors" + "fmt" + "os" + "os/exec" + "sort" + "strconv" + "strings" +) + +type cliBackend struct{} + +type cliRepository struct { + workTree string +} + +func (cliBackend) Name() string { + return "cli" +} + +func (b cliBackend) Open(path string) (RepositoryBackend, error) { + if path == "" { + path = "." + } + + out, err := runGitCommand(path, nil, nil, "rev-parse", "--show-toplevel") + if err != nil { + return nil, classifyRepoError(err) + } + + return &cliRepository{workTree: strings.TrimSpace(out)}, nil +} + +func (b cliBackend) Clone(path, remoteURL string, auth *AuthMethod, opts CloneOptions) (RepositoryBackend, error) { + extraConfigs := make([]string, 0, 1) + if opts.Insecure { + extraConfigs = append(extraConfigs, "http.sslVerify=false") + } + + args := []string{"clone"} + if opts.Depth > 0 { + args = append(args, "--depth", strconv.Itoa(opts.Depth)) + } + args = append(args, remoteURL, path) + + if _, err := runGitCommand("", auth, extraConfigs, args...); err != nil { + return nil, err + } + return b.Open(path) +} + +func (r *cliRepository) WorkTree() string { + return r.workTree +} + +func (r *cliRepository) Config() (*Config, error) { + cfg := &Config{ + Remotes: map[string]*RemoteConfig{}, + Branches: map[string]*Branch{}, + } + + remoteOut, err := r.git(nil, nil, "remote") + if err != nil { + return nil, err + } + for _, remoteName := range strings.Fields(remoteOut) { + urlOut, err := r.git(nil, nil, "config", "--get-all", "remote."+remoteName+".url") + if err != nil { + return nil, err + } + cfg.Remotes[remoteName] = &RemoteConfig{Name: remoteName, URLs: splitNonEmptyLines(urlOut)} + } + + branchOut, err := r.git(nil, nil, "config", "--get-regexp", `^branch\..*\.(remote|merge)$`) + if err != nil { + var gitErr *gitCommandError + if !errors.As(err, &gitErr) { + return nil, err + } + if strings.TrimSpace(gitErr.stderr) != "" && !strings.Contains(gitErr.stderr, "No such section or key") { + return nil, err + } + return cfg, nil + } + + for _, line := range splitNonEmptyLines(branchOut) { + parts := strings.SplitN(line, " ", 2) + if len(parts) != 2 { + continue + } + branchName, field, ok := parseBranchConfigKey(parts[0]) + if !ok { + continue + } + branch := cfg.Branches[branchName] + if branch == nil { + branch = &Branch{Name: branchName} + cfg.Branches[branchName] = branch + } + switch field { + case "remote": + branch.Remote = parts[1] + case "merge": + branch.Merge = ReferenceName(parts[1]) + } + } + + return cfg, nil +} + +func (r *cliRepository) Head() (*Reference, error) { + hashOut, err := r.git(nil, nil, "rev-parse", "HEAD") + if err != nil { + return nil, err + } + hash := Hash(strings.TrimSpace(hashOut)) + + if refOut, err := r.git(nil, nil, "symbolic-ref", "-q", "HEAD"); err == nil { + return &Reference{name: ReferenceName(strings.TrimSpace(refOut)), hash: hash}, nil + } + if tagOut, err := r.git(nil, nil, "describe", "--exact-match", "--tags", "HEAD"); err == nil { + return &Reference{name: ReferenceName("refs/tags/" + strings.TrimSpace(tagOut)), hash: hash}, nil + } + return &Reference{name: ReferenceName("HEAD"), hash: hash}, nil +} + +func (r *cliRepository) AddRemote(name, remoteURL string) error { + _, err := r.git(nil, nil, "remote", "add", name, remoteURL) + return err +} + +func (r *cliRepository) SetBranchUpstream(branchName, remoteName, remoteBranch string) error { + mergeRef := NewBranchReferenceName(remoteBranch).String() + if _, err := r.git(nil, nil, "config", "branch."+branchName+".remote", remoteName); err != nil { + return err + } + _, err := r.git(nil, nil, "config", "branch."+branchName+".merge", mergeRef) + return err +} + +func (r *cliRepository) Fetch(remoteName string, refspecs []string, auth *AuthMethod) error { + args := []string{"fetch", remoteName} + args = append(args, refspecs...) + _, err := r.git(auth, nil, args...) + return err +} + +func (r *cliRepository) CreateTrackingBranch(localBranchName, remoteBranchName, remoteName string) error { + _, err := r.git(nil, nil, "branch", "--track", localBranchName, fmt.Sprintf("%s/%s", remoteName, remoteBranchName)) + if err == nil { + return nil + } + if gitErr, ok := err.(*gitCommandError); ok && strings.Contains(gitErr.stderr, "already exists") { + return ErrBranchExists + } + return err +} + +func (r *cliRepository) Checkout(ref ReferenceName) error { + _, err := r.git(nil, nil, "checkout", ref.String()) + return err +} + +func (r *cliRepository) DeleteLocalBranch(branchName string) error { + _, err := r.git(nil, nil, "branch", "-D", branchName) + if err == nil { + return nil + } + if gitErr, ok := err.(*gitCommandError); ok { + stderr := strings.ToLower(gitErr.stderr) + if strings.Contains(stderr, "not found") || strings.Contains(stderr, "not exist") { + return nil + } + } + return err +} + +func (r *cliRepository) DeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error { + _, err := r.git(auth, nil, "push", "--delete", remoteName, remoteBranch) + return err +} + +func (r *cliRepository) ListReferences(prefixes ...string) ([]*Reference, error) { + args := []string{"for-each-ref", "--format=%(objectname)%09%(refname)"} + args = append(args, prefixes...) + out, err := r.git(nil, nil, args...) + if err != nil { + return nil, err + } + + refs := make([]*Reference, 0) + for _, line := range splitNonEmptyLines(out) { + parts := strings.SplitN(line, " ", 2) + if len(parts) != 2 { + continue + } + refs = append(refs, &Reference{name: ReferenceName(parts[1]), hash: Hash(parts[0])}) + } + return refs, nil +} + +func (r *cliRepository) PushToAgitFlowPR(remoteName, head, base, topic string, pushOptions map[string]string, auth *AuthMethod) error { + ref := fmt.Sprintf("%s:refs/for/%s/%s", head, base, topic) + args := []string{"push", remoteName, ref} + if len(pushOptions) > 0 { + keys := make([]string, 0, len(pushOptions)) + for key := range pushOptions { + keys = append(keys, key) + } + sort.Strings(keys) + for _, key := range keys { + args = append(args, "-o", key+"="+pushOptions[key]) + } + } + _, err := r.git(auth, nil, args...) + return err +} + +func (r *cliRepository) git(auth *AuthMethod, extraConfigs []string, args ...string) (string, error) { + return runGitCommand(r.workTree, auth, extraConfigs, args...) +} + +type gitCommandError struct { + args []string + stderr string + err error +} + +func (e *gitCommandError) Error() string { + stderr := strings.TrimSpace(e.stderr) + if stderr == "" { + return fmt.Sprintf("git %s: %v", strings.Join(e.args, " "), e.err) + } + return fmt.Sprintf("git %s: %s", strings.Join(e.args, " "), stderr) +} + +func (e *gitCommandError) Unwrap() error { + return e.err +} + +func runGitCommand(dir string, auth *AuthMethod, extraConfigs []string, args ...string) (string, error) { + authConfigs, authEnv, cleanup, err := prepareCLIAuth(auth) + if err != nil { + return "", err + } + defer cleanup() + + fullArgs := make([]string, 0, (len(extraConfigs)+len(authConfigs))*2+len(args)) + for _, cfg := range extraConfigs { + fullArgs = append(fullArgs, "-c", cfg) + } + for _, cfg := range authConfigs { + fullArgs = append(fullArgs, "-c", cfg) + } + fullArgs = append(fullArgs, args...) + + cmd := exec.Command("git", fullArgs...) + if dir != "" { + cmd.Dir = dir + } + cmd.Env = append(os.Environ(), authEnv...) + + var stdout bytes.Buffer + var stderr bytes.Buffer + cmd.Stdout = &stdout + cmd.Stderr = &stderr + if err := cmd.Run(); err != nil { + return "", &gitCommandError{args: fullArgs, stderr: stderr.String(), err: err} + } + return stdout.String(), nil +} + +func prepareCLIAuth(auth *AuthMethod) ([]string, []string, func(), error) { + if auth == nil { + return nil, nil, func() {}, nil + } + + configs := make([]string, 0, 1) + env := make([]string, 0, 4) + cleanup := func() {} + + switch auth.Scheme { + case "http", "https": + if auth.Username != "" || auth.Password != "" { + header := "Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(auth.Username+":"+auth.Password)) + configs = append(configs, "http.extraHeader="+header) + } + case "ssh": + sshCommand := "ssh" + if auth.KeyFile != "" { + sshCommand += " -i " + shellQuote(auth.KeyFile) + " -o IdentitiesOnly=yes" + } + env = append(env, "GIT_SSH_COMMAND="+sshCommand) + if auth.KeyPassphrase != "" { + askPassPath, err := writeAskPassScript(auth.KeyPassphrase) + if err != nil { + return nil, nil, cleanup, err + } + cleanup = func() { _ = os.Remove(askPassPath) } + env = append(env, + "SSH_ASKPASS="+askPassPath, + "SSH_ASKPASS_REQUIRE=force", + "DISPLAY=tea", + ) + } + } + + return configs, env, cleanup, nil +} + +func writeAskPassScript(passphrase string) (string, error) { + f, err := os.CreateTemp("", "tea-ssh-askpass-*") + if err != nil { + return "", err + } + defer f.Close() + + content := "#!/bin/sh\nprintf '%s\\n' " + shellQuote(passphrase) + "\n" + if _, err := f.WriteString(content); err != nil { + _ = os.Remove(f.Name()) + return "", err + } + if err := f.Chmod(0o700); err != nil { + _ = os.Remove(f.Name()) + return "", err + } + return f.Name(), nil +} + +func classifyRepoError(err error) error { + var gitErr *gitCommandError + if errors.As(err, &gitErr) { + msg := strings.ToLower(gitErr.stderr) + if strings.Contains(msg, "not a git repository") || strings.Contains(msg, "cannot change to") { + return ErrRepositoryNotExists + } + } + return err +} + +func parseBranchConfigKey(key string) (branchName, field string, ok bool) { + const prefix = "branch." + if !strings.HasPrefix(key, prefix) { + return "", "", false + } + trimmed := strings.TrimPrefix(key, prefix) + switch { + case strings.HasSuffix(trimmed, ".remote"): + return strings.TrimSuffix(trimmed, ".remote"), "remote", true + case strings.HasSuffix(trimmed, ".merge"): + return strings.TrimSuffix(trimmed, ".merge"), "merge", true + default: + return "", "", false + } +} + +func splitNonEmptyLines(s string) []string { + lines := strings.Split(strings.TrimSpace(s), "\n") + out := make([]string, 0, len(lines)) + for _, line := range lines { + line = strings.TrimSpace(line) + if line != "" { + out = append(out, line) + } + } + return out +} diff --git a/modules/git/network.go b/modules/git/network.go new file mode 100644 index 00000000..aac21ced --- /dev/null +++ b/modules/git/network.go @@ -0,0 +1,28 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +// Clone clones a repository using the active backend. +func Clone(path, remoteURL string, auth *AuthMethod, depth int, insecure bool) (*TeaRepo, error) { + backend, err := currentBackend().Clone(path, remoteURL, auth, CloneOptions{Depth: depth, Insecure: insecure}) + if err != nil { + return nil, err + } + return newTeaRepo(backend), nil +} + +// AddRemote adds a new remote to the repository. +func (r TeaRepo) AddRemote(name, remoteURL string) error { + return r.backend.AddRemote(name, remoteURL) +} + +// SetBranchUpstream configures the branch's upstream remote. +func (r TeaRepo) SetBranchUpstream(branchName, remoteName, remoteBranch string) error { + return r.backend.SetBranchUpstream(branchName, remoteName, remoteBranch) +} + +// Fetch fetches updates from the named remote. +func (r TeaRepo) Fetch(remoteName string, refspecs []string, auth *AuthMethod) error { + return r.backend.Fetch(remoteName, refspecs, auth) +} diff --git a/modules/git/remote.go b/modules/git/remote.go index c15606d9..8de93e45 100644 --- a/modules/git/remote.go +++ b/modules/git/remote.go @@ -6,14 +6,11 @@ package git import ( "fmt" "net/url" - - "github.com/go-git/go-git/v5" - git_config "github.com/go-git/go-git/v5/config" ) // GetRemote tries to match a Remote of the repo via the given URL. // Matching is based on the normalized URL, accepting different protocols. -func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) { +func (r TeaRepo) GetRemote(remoteURL string) (*Remote, error) { repoURL, err := ParseURL(remoteURL) if err != nil { return nil, err @@ -23,14 +20,14 @@ func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) { if err != nil { return nil, err } - for _, r := range remotes { - for _, u := range r.Config().URLs { - remoteURL, err := ParseURL(u) + for _, remote := range remotes { + for _, u := range remote.Config().URLs { + parsedRemoteURL, err := ParseURL(u) if err != nil { return nil, err } - if remoteURL.Host == repoURL.Host && remoteURL.Path == repoURL.Path { - return r, nil + if parsedRemoteURL.Host == repoURL.Host && parsedRemoteURL.Path == repoURL.Path { + return remote, nil } } } @@ -41,27 +38,23 @@ func (r TeaRepo) GetRemote(remoteURL string) (*git.Remote, error) { // GetOrCreateRemote tries to match a Remote of the repo via the given URL. // If no match is found, a new Remote with `newRemoteName` is created. // Matching is based on the normalized URL, accepting different protocols. -func (r TeaRepo) GetOrCreateRemote(remoteURL, newRemoteName string) (*git.Remote, error) { +func (r TeaRepo) GetOrCreateRemote(remoteURL, newRemoteName string) (*Remote, error) { localRemote, err := r.GetRemote(remoteURL) if err != nil { return nil, err } - // if no match found, create a new remote if localRemote == nil { - localRemote, err = r.CreateRemote(&git_config.RemoteConfig{ - Name: newRemoteName, - URLs: []string{remoteURL}, - }) - if err != nil { + if err := r.AddRemote(newRemoteName, remoteURL); err != nil { return nil, err } + return r.Remote(newRemoteName) } return localRemote, nil } -// TeaRemoteURL returns the first url entry for the given remote name +// TeaRemoteURL returns the first url entry for the given remote name. func (r TeaRepo) TeaRemoteURL(name string) (auth *url.URL, err error) { remote, err := r.Remote(name) if err != nil { @@ -71,5 +64,5 @@ func (r TeaRepo) TeaRemoteURL(name string) (auth *url.URL, err error) { if len(urls) == 0 { return nil, fmt.Errorf("remote %s has no URL configured", name) } - return ParseURL(remote.Config().URLs[0]) + return ParseURL(urls[0]) } diff --git a/modules/git/repo.go b/modules/git/repo.go index 938e4e60..32e5e156 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -4,14 +4,18 @@ package git import ( + "fmt" "net/url" - - "github.com/go-git/go-git/v5" + "sort" ) -// TeaRepo is a go-git Repository, with an extended high level interface. +// TeaRepo wraps a local git repository behind a swappable backend. type TeaRepo struct { - *git.Repository + backend RepositoryBackend +} + +func newTeaRepo(backend RepositoryBackend) *TeaRepo { + return &TeaRepo{backend: backend} } // RepoForWorkdir tries to open the git repository in the local directory @@ -20,28 +24,71 @@ func RepoForWorkdir() (*TeaRepo, error) { return RepoFromPath("") } -// RepoFromPath tries to open the git repository by path +// RepoFromPath tries to open the git repository by path. func RepoFromPath(path string) (*TeaRepo, error) { - if len(path) == 0 { - path = "./" + backend, err := currentBackend().Open(path) + if err != nil { + return nil, err } - repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{ - DetectDotGit: true, - EnableDotGitCommonDir: true, // Enable commondir support for worktrees - }) + return newTeaRepo(backend), nil +} + +// WorkTree returns the repository work tree path. +func (r TeaRepo) WorkTree() string { + return r.backend.WorkTree() +} + +// Config returns the repository config values tea needs. +func (r TeaRepo) Config() (*Config, error) { + return r.backend.Config() +} + +// Remote returns the configured remote by name. +func (r TeaRepo) Remote(remoteName string) (*Remote, error) { + cfg, err := r.Config() + if err != nil { + return nil, err + } + remoteCfg, ok := cfg.Remotes[remoteName] + if !ok { + return nil, fmt.Errorf("remote %s not found", remoteName) + } + return &Remote{repo: &r, config: remoteCfg}, nil +} + +// Remotes returns all configured remotes sorted by name. +func (r TeaRepo) Remotes() ([]*Remote, error) { + cfg, err := r.Config() if err != nil { return nil, err } - return &TeaRepo{repo}, nil + remoteNames := make([]string, 0, len(cfg.Remotes)) + for name := range cfg.Remotes { + remoteNames = append(remoteNames, name) + } + sort.Strings(remoteNames) + + remotes := make([]*Remote, 0, len(remoteNames)) + for _, name := range remoteNames { + remotes = append(remotes, &Remote{repo: &r, config: cfg.Remotes[name]}) + } + return remotes, nil } -// RemoteURL returns the URL of the given remote +// Head returns the currently checked out ref. +func (r TeaRepo) Head() (*Reference, error) { + return r.backend.Head() +} + +// RemoteURL returns the URL of the given remote. func (r TeaRepo) RemoteURL(remoteName string) (*url.URL, error) { remote, err := r.Remote(remoteName) if err != nil { return nil, err } - - return url.Parse(remote.Config().URLs[0]) + if len(remote.Config().URLs) == 0 { + return nil, fmt.Errorf("remote %s has no URL configured", remoteName) + } + return ParseURL(remote.Config().URLs[0]) } diff --git a/modules/git/repo_cli_test.go b/modules/git/repo_cli_test.go new file mode 100644 index 00000000..053b8512 --- /dev/null +++ b/modules/git/repo_cli_test.go @@ -0,0 +1,136 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/require" +) + +func runGit(t *testing.T, dir string, args ...string) string { + t.Helper() + cmd := exec.Command("git", args...) + if dir != "" { + cmd.Dir = dir + } + out, err := cmd.CombinedOutput() + require.NoErrorf(t, err, "git %v failed: %s", args, out) + return string(out) +} + +func tryGit(dir string, args ...string) error { + cmd := exec.Command("git", args...) + if dir != "" { + cmd.Dir = dir + } + _, err := cmd.CombinedOutput() + return err +} + +func TestRepoFromPathSupportsWorktrees(t *testing.T) { + tmpDir := t.TempDir() + mainRepoPath := filepath.Join(tmpDir, "main-repo") + worktreePath := filepath.Join(tmpDir, "worktree") + + runGit(t, "", "init", mainRepoPath) + runGit(t, mainRepoPath, "config", "user.email", "test@example.com") + runGit(t, mainRepoPath, "config", "user.name", "Test User") + runGit(t, mainRepoPath, "remote", "add", "origin", "https://gitea.com/owner/repo.git") + + readmePath := filepath.Join(mainRepoPath, "README.md") + require.NoError(t, os.WriteFile(readmePath, []byte("# Test Repo\n"), 0o644)) + runGit(t, mainRepoPath, "add", "README.md") + runGit(t, mainRepoPath, "commit", "-m", "Initial commit") + runGit(t, mainRepoPath, "worktree", "add", worktreePath, "-b", "test-branch") + + repo, err := RepoFromPath(worktreePath) + require.NoError(t, err) + + config, err := repo.Config() + require.NoError(t, err) + require.Contains(t, config.Remotes, "origin") + require.Equal(t, "https://gitea.com/owner/repo.git", config.Remotes["origin"].URLs[0]) + + head, err := repo.Head() + require.NoError(t, err) + require.Equal(t, "test-branch", head.Name().Short()) +} + +func TestRepoFromPathSupportsSHA256Repos(t *testing.T) { + tmpDir := t.TempDir() + repoPath := filepath.Join(tmpDir, "sha256-repo") + + if err := tryGit("", "init", "--object-format=sha256", repoPath); err != nil { + t.Skip("git does not support sha256 object format in this environment") + } + + runGit(t, repoPath, "config", "user.email", "test@example.com") + runGit(t, repoPath, "config", "user.name", "Test User") + runGit(t, repoPath, "remote", "add", "origin", "https://gitea.com/owner/repo.git") + + readmePath := filepath.Join(repoPath, "README.md") + require.NoError(t, os.WriteFile(readmePath, []byte("sha256\n"), 0o644)) + runGit(t, repoPath, "add", "README.md") + runGit(t, repoPath, "commit", "-m", "Initial commit") + + repo, err := RepoFromPath(repoPath) + require.NoError(t, err) + + branch, sha, err := repo.TeaGetCurrentBranchNameAndSHA() + require.NoError(t, err) + require.NotEmpty(t, branch) + require.Len(t, sha, 64) + + config, err := repo.Config() + require.NoError(t, err) + require.Contains(t, config.Remotes, "origin") +} + +func TestTeaFindBranchByShaAndName(t *testing.T) { + tmpDir := t.TempDir() + remotePath := filepath.Join(tmpDir, "remote.git") + localPath := filepath.Join(tmpDir, "local") + + runGit(t, "", "init", "--bare", remotePath) + runGit(t, "", "clone", remotePath, localPath) + runGit(t, localPath, "config", "user.email", "test@example.com") + runGit(t, localPath, "config", "user.name", "Test User") + + filePath := filepath.Join(localPath, "README.md") + require.NoError(t, os.WriteFile(filePath, []byte("main\n"), 0o644)) + runGit(t, localPath, "add", "README.md") + runGit(t, localPath, "commit", "-m", "Initial commit") + runGit(t, localPath, "branch", "-M", "main") + runGit(t, localPath, "push", "-u", "origin", "main") + runGit(t, localPath, "checkout", "-b", "feature/demo") + + require.NoError(t, os.WriteFile(filePath, []byte("feature\n"), 0o644)) + runGit(t, localPath, "commit", "-am", "Feature commit") + runGit(t, localPath, "push", "-u", "origin", "feature/demo") + + repo, err := RepoFromPath(localPath) + require.NoError(t, err) + + sha := strings.TrimSpace(runGit(t, localPath, "rev-parse", "HEAD")) + branchBySha, err := repo.TeaFindBranchBySha(sha, remotePath) + require.NoError(t, err) + require.NotNil(t, branchBySha) + require.Equal(t, "feature/demo", branchBySha.Name) + require.Equal(t, "origin", branchBySha.Remote) + + branchByName, err := repo.TeaFindBranchByName("feature/demo", remotePath) + require.NoError(t, err) + require.NotNil(t, branchByName) + require.Equal(t, "feature/demo", branchByName.Name) + + remote, err := repo.TeaFindBranchRemote("feature/demo", sha) + require.NoError(t, err) + require.NotNil(t, remote) + require.Equal(t, "origin", remote.Config().Name) +} diff --git a/modules/git/types.go b/modules/git/types.go new file mode 100644 index 00000000..41fe7f36 --- /dev/null +++ b/modules/git/types.go @@ -0,0 +1,163 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "errors" + "strings" +) + +var ( + // ErrRepositoryNotExists indicates the requested path is not inside a git repository. + ErrRepositoryNotExists = errors.New("repository does not exist") + // ErrBranchExists indicates the requested branch already exists locally. + ErrBranchExists = errors.New("branch already exists") +) + +// AuthMethod carries backend-agnostic authentication information for git operations. +type AuthMethod struct { + Scheme string + Username string + Password string + KeyFile string + KeyPassphrase string +} + +// CloneOptions describes repository clone behavior. +type CloneOptions struct { + Depth int + Insecure bool +} + +// RepositoryBackend is the backend abstraction used by TeaRepo. +type RepositoryBackend interface { + WorkTree() string + Config() (*Config, error) + Head() (*Reference, error) + AddRemote(name, remoteURL string) error + SetBranchUpstream(branchName, remoteName, remoteBranch string) error + Fetch(remoteName string, refspecs []string, auth *AuthMethod) error + CreateTrackingBranch(localBranchName, remoteBranchName, remoteName string) error + Checkout(ref ReferenceName) error + DeleteLocalBranch(branchName string) error + DeleteRemoteBranch(remoteName, remoteBranch string, auth *AuthMethod) error + ListReferences(prefixes ...string) ([]*Reference, error) + PushToAgitFlowPR(remoteName, head, base, topic string, pushOptions map[string]string, auth *AuthMethod) error +} + +// Backend opens and clones repositories using a concrete git implementation. +type Backend interface { + Name() string + Open(path string) (RepositoryBackend, error) + Clone(path, remoteURL string, auth *AuthMethod, opts CloneOptions) (RepositoryBackend, error) +} + +// Config mirrors the repository config fields tea needs. +type Config struct { + Remotes map[string]*RemoteConfig + Branches map[string]*Branch +} + +// RemoteConfig stores remote configuration. +type RemoteConfig struct { + Name string + URLs []string +} + +// Branch stores branch configuration. +type Branch struct { + Name string + Remote string + Merge ReferenceName +} + +// Validate checks whether the branch contains the fields tea needs. +func (b *Branch) Validate() error { + if b == nil || b.Name == "" { + return errors.New("branch name is required") + } + return nil +} + +// Remote wraps a configured git remote. +type Remote struct { + repo *TeaRepo + config *RemoteConfig +} + +// Config returns the remote configuration. +func (r *Remote) Config() *RemoteConfig { + if r == nil { + return nil + } + return r.config +} + +// ReferenceName identifies a git reference. +type ReferenceName string + +func (r ReferenceName) String() string { return string(r) } + +// Short returns the short display name for the reference. +func (r ReferenceName) Short() string { + s := string(r) + switch { + case strings.HasPrefix(s, "refs/heads/"): + return strings.TrimPrefix(s, "refs/heads/") + case strings.HasPrefix(s, "refs/remotes/"): + return strings.TrimPrefix(s, "refs/remotes/") + case strings.HasPrefix(s, "refs/tags/"): + return strings.TrimPrefix(s, "refs/tags/") + default: + return s + } +} + +// IsBranch reports whether the reference points to a local branch. +func (r ReferenceName) IsBranch() bool { + return strings.HasPrefix(string(r), "refs/heads/") +} + +// IsRemote reports whether the reference points to a remote-tracking branch. +func (r ReferenceName) IsRemote() bool { + return strings.HasPrefix(string(r), "refs/remotes/") +} + +// IsTag reports whether the reference points to a tag. +func (r ReferenceName) IsTag() bool { + return strings.HasPrefix(string(r), "refs/tags/") +} + +// Hash wraps a git object id. +type Hash string + +func (h Hash) String() string { return string(h) } + +// Reference stores a resolved git ref and its hash. +type Reference struct { + name ReferenceName + hash Hash +} + +// Name returns the reference name. +func (r *Reference) Name() ReferenceName { return r.name } + +// Hash returns the reference hash. +func (r *Reference) Hash() Hash { return r.hash } + +// NewBranchReferenceName constructs a local branch ref name. +func NewBranchReferenceName(name string) ReferenceName { + if strings.HasPrefix(name, "refs/") { + return ReferenceName(name) + } + return ReferenceName("refs/heads/" + name) +} + +// NewRemoteReferenceName constructs a remote-tracking ref name. +func NewRemoteReferenceName(remote, name string) ReferenceName { + if strings.HasPrefix(name, "refs/") { + return ReferenceName(name) + } + return ReferenceName("refs/remotes/" + remote + "/" + name) +} diff --git a/modules/httputil/httputil.go b/modules/httputil/httputil.go index e0dbe3ad..92338e33 100644 --- a/modules/httputil/httputil.go +++ b/modules/httputil/httputil.go @@ -8,7 +8,7 @@ import ( "net/http" "runtime" - "code.gitea.io/tea/modules/version" + "gitea.dev/tea/modules/version" ) // UserAgent returns the standard User-Agent string for tea. diff --git a/modules/interact/comments.go b/modules/interact/comments.go index 844153dd..def856f6 100644 --- a/modules/interact/comments.go +++ b/modules/interact/comments.go @@ -4,14 +4,16 @@ package interact import ( + stdctx "context" "fmt" "os" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/theme" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" "golang.org/x/term" @@ -19,18 +21,18 @@ import ( // ShowCommentsMaybeInteractive fetches & prints comments, depending on the --comments flag. // If that flag is unset, and output is not piped, prompts the user first. -func ShowCommentsMaybeInteractive(ctx *context.TeaContext, idx int64, totalComments int) error { +func ShowCommentsMaybeInteractive(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, totalComments int) error { if ctx.Bool("comments") { opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)} c := ctx.Login.Client() - comments, _, err := c.ListIssueComments(ctx.Owner, ctx.Repo, idx, opts) + comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, idx, opts) if err != nil { return err } print.Comments(comments) } else if print.IsInteractive() && !ctx.IsSet("comments") { // if we're interactive, but --comments hasn't been explicitly set to false - if err := ShowCommentsPaginated(ctx, idx, totalComments); err != nil { + if err := ShowCommentsPaginated(requestCtx, ctx, idx, totalComments); err != nil { fmt.Printf("error while loading comments: %v\n", err) } } @@ -38,7 +40,7 @@ func ShowCommentsMaybeInteractive(ctx *context.TeaContext, idx int64, totalComme } // ShowCommentsPaginated prompts if issue/pr comments should be shown and continues to do so. -func ShowCommentsPaginated(ctx *context.TeaContext, idx int64, totalComments int) error { +func ShowCommentsPaginated(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, totalComments int) error { c := ctx.Login.Client() opts := gitea.ListIssueCommentOptions{ListOptions: flags.GetListOptions(ctx.Command)} prompt := "show comments?" @@ -58,7 +60,7 @@ func ShowCommentsPaginated(ctx *context.TeaContext, idx int64, totalComments int } else if !loadComments { break } else { - if comments, _, err := c.ListIssueComments(ctx.Owner, ctx.Repo, idx, opts); err != nil { + if comments, _, err := c.Issues.ListIssueComments(requestCtx, ctx.Owner, ctx.Repo, idx, opts); err != nil { return err } else if len(comments) != 0 { print.Comments(comments) diff --git a/modules/interact/issue_create.go b/modules/interact/issue_create.go index 3e478ee3..3dee358e 100644 --- a/modules/interact/issue_create.go +++ b/modules/interact/issue_create.go @@ -4,12 +4,14 @@ package interact import ( + "context" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) @@ -20,7 +22,7 @@ func IsQuitting(err error) bool { } // CreateIssue interactively creates an issue -func CreateIssue(login *config.Login, owner, repo string) error { +func CreateIssue(ctx context.Context, login *config.Login, owner, repo string) error { owner, repo, err := promptRepoSlug(owner, repo) if err != nil { return err @@ -28,19 +30,19 @@ func CreateIssue(login *config.Login, owner, repo string) error { printTitleAndContent("Target repo:", owner+"/"+repo) var opts gitea.CreateIssueOption - if err := promptIssueProperties(login, owner, repo, &opts); err != nil { + if err := promptIssueProperties(ctx, login, owner, repo, &opts); err != nil { return err } - return task.CreateIssue(login, owner, repo, opts) + return task.CreateIssue(ctx, login, owner, repo, opts) } -func promptIssueProperties(login *config.Login, owner, repo string, o *gitea.CreateIssueOption) error { +func promptIssueProperties(ctx context.Context, login *config.Login, owner, repo string, o *gitea.CreateIssueOption) error { var milestoneName string var err error selectableChan := make(chan (issueSelectables), 1) - go fetchIssueSelectables(login, owner, repo, selectableChan) + go fetchIssueSelectables(ctx, login, owner, repo, selectableChan) // title if err := huh.NewInput(). @@ -139,12 +141,12 @@ type issueSelectables struct { Err error } -func fetchIssueSelectables(login *config.Login, owner, repo string, done chan issueSelectables) { +func fetchIssueSelectables(ctx context.Context, login *config.Login, owner, repo string, done chan issueSelectables) { // TODO PERF make these calls concurrent r := issueSelectables{} c := login.Client() - r.Repo, _, r.Err = c.GetRepo(owner, repo) + r.Repo, _, r.Err = c.Repositories.GetRepo(ctx, owner, repo) if r.Err != nil { done <- r return @@ -156,7 +158,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is return } - assignees, _, err := c.GetAssignees(owner, repo) + assignees, _, err := c.Repositories.GetAssignees(ctx, owner, repo) if err != nil { r.Err = err done <- r @@ -167,7 +169,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is r.Assignees[i] = u.UserName } - milestones, _, err := c.ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{}) + milestones, _, err := c.Repositories.ListMilestones(ctx, owner, repo, gitea.ListMilestoneOption{}) if err != nil { r.Err = err done <- r @@ -183,7 +185,7 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is r.LabelMap = make(map[string]int64) r.LabelList = make([]string, 0) for page := 1; ; { - labels, resp, err := c.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ + labels, resp, err := c.Repositories.ListRepoLabels(ctx, owner, repo, gitea.ListLabelsOptions{ ListOptions: gitea.ListOptions{Page: page, PageSize: 50}, }) if err != nil { diff --git a/modules/interact/issue_edit.go b/modules/interact/issue_edit.go index 53cdcf26..3e61e9c6 100644 --- a/modules/interact/issue_edit.go +++ b/modules/interact/issue_edit.go @@ -4,19 +4,20 @@ package interact import ( + stdctx "context" "slices" "strings" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) // EditIssue interactively edits an issue -func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, error) { +func EditIssue(requestCtx stdctx.Context, ctx context.TeaContext, index int64) (*task.EditIssueOption, error) { opts := task.EditIssueOption{} var err error @@ -27,7 +28,7 @@ func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, erro printTitleAndContent("Target repo:", ctx.Owner+"/"+ctx.Repo) c := ctx.Login.Client() - i, _, err := c.GetIssue(ctx.Owner, ctx.Repo, index) + i, _, err := c.Issues.GetIssue(requestCtx, ctx.Owner, ctx.Repo, index) if err != nil { return &opts, err } @@ -55,20 +56,20 @@ func EditIssue(ctx context.TeaContext, index int64) (*task.EditIssueOption, erro opts.Milestone = &i.Milestone.Title } - if err := promptIssueEditProperties(&ctx, &opts); err != nil { + if err := promptIssueEditProperties(requestCtx, &ctx, &opts); err != nil { return &opts, err } return &opts, err } -func promptIssueEditProperties(ctx *context.TeaContext, o *task.EditIssueOption) error { +func promptIssueEditProperties(requestCtx stdctx.Context, ctx *context.TeaContext, o *task.EditIssueOption) error { var milestoneName string var labelsSelected []string var err error selectableChan := make(chan (issueSelectables), 1) - go fetchIssueSelectables(ctx.Login, ctx.Owner, ctx.Repo, selectableChan) + go fetchIssueSelectables(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, selectableChan) // title if err := huh.NewInput(). diff --git a/modules/interact/login.go b/modules/interact/login.go index a6aef27b..b59d24b9 100644 --- a/modules/interact/login.go +++ b/modules/interact/login.go @@ -4,6 +4,7 @@ package interact import ( + "context" "errors" "fmt" "net/url" @@ -11,17 +12,18 @@ import ( "strconv" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/auth" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/auth" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) // CreateLogin create an login interactive -func CreateLogin() error { +func CreateLogin(ctx context.Context) error { var ( name, token, user, passwd, otp, scopes, sshKey, sshCertPrincipal, sshKeyFingerprint string insecure, sshAgent, versionCheck, helper bool @@ -103,7 +105,7 @@ func CreateLogin() error { } printTitleAndContent("Allow Insecure connections:", strconv.FormatBool(insecure)) - return auth.OAuthLoginWithOptions(name, giteaURL, insecure) + return auth.OAuthLoginWithOptions(ctx, name, giteaURL, insecure) default: // token var hasToken bool if err := huh.NewConfirm(). @@ -269,7 +271,7 @@ func CreateLogin() error { printTitleAndContent("Check version of Gitea instance:", strconv.FormatBool(versionCheck)) } - return task.CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper) + return task.CreateLogin(ctx, name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint, insecure, sshAgent, versionCheck, helper) } var tokenScopeOpts = []string{ diff --git a/modules/interact/milestone_create.go b/modules/interact/milestone_create.go index 4f2240fb..97064346 100644 --- a/modules/interact/milestone_create.go +++ b/modules/interact/milestone_create.go @@ -4,19 +4,20 @@ package interact import ( + stdctx "context" "fmt" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + gitea "gitea.dev/sdk" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) // CreateMilestone interactively creates a milestone -func CreateMilestone(login *config.Login, owner, repo string) error { +func CreateMilestone(requestCtx stdctx.Context, login *config.Login, owner, repo string) error { var title, description, deadline string // owner, repo @@ -59,8 +60,7 @@ func CreateMilestone(login *config.Login, owner, repo string) error { deadlineTM = &tm } - return task.CreateMilestone( - login, + return task.CreateMilestone(requestCtx, login, owner, repo, title, diff --git a/modules/interact/print.go b/modules/interact/print.go index fa2a6cdb..56fc6e2f 100644 --- a/modules/interact/print.go +++ b/modules/interact/print.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "code.gitea.io/tea/modules/theme" + "gitea.dev/tea/modules/theme" "charm.land/lipgloss/v2" ) diff --git a/modules/interact/prompts.go b/modules/interact/prompts.go index 539be868..c2601983 100644 --- a/modules/interact/prompts.go +++ b/modules/interact/prompts.go @@ -9,8 +9,8 @@ import ( "strings" "time" - "code.gitea.io/tea/modules/theme" - "code.gitea.io/tea/modules/utils" + "gitea.dev/tea/modules/theme" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" ) diff --git a/modules/interact/pull_create.go b/modules/interact/pull_create.go index 3bd19d28..0d8a1f3b 100644 --- a/modules/interact/pull_create.go +++ b/modules/interact/pull_create.go @@ -4,16 +4,18 @@ package interact import ( - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + stdctx "context" + + gitea "gitea.dev/sdk" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) // CreatePull interactively creates a PR -func CreatePull(ctx *context.TeaContext) (err error) { +func CreatePull(requestCtx stdctx.Context, ctx *context.TeaContext) (err error) { var ( base, head string allowMaintainerEdits = true @@ -27,7 +29,7 @@ func CreatePull(ctx *context.TeaContext) (err error) { } // base - if base, err = task.GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo); err != nil { + if base, err = task.GetDefaultPRBase(requestCtx, ctx.Login, ctx.Owner, ctx.Repo); err != nil { return err } @@ -85,11 +87,12 @@ func CreatePull(ctx *context.TeaContext) (err error) { } opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)} - if err = promptIssueProperties(ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil { + if err = promptIssueProperties(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil { return err } return task.CreateAgitFlowPull( + requestCtx, ctx, baseRemote, head, @@ -127,11 +130,12 @@ func CreatePull(ctx *context.TeaContext) (err error) { head = task.GetHeadSpec(headOwner, headBranch, ctx.Owner) opts := gitea.CreateIssueOption{Title: task.GetDefaultPRTitle(head)} - if err = promptIssueProperties(ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil { + if err = promptIssueProperties(requestCtx, ctx.Login, ctx.Owner, ctx.Repo, &opts); err != nil { return err } return task.CreatePull( + requestCtx, ctx, base, head, diff --git a/modules/interact/pull_merge.go b/modules/interact/pull_merge.go index f3d99737..2cbd4a06 100644 --- a/modules/interact/pull_merge.go +++ b/modules/interact/pull_merge.go @@ -4,20 +4,22 @@ package interact import ( + stdctx "context" "fmt" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/flags" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/cmd/flags" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/utils" "charm.land/huh/v2" ) // MergePull interactively creates a PR -func MergePull(ctx *context.TeaContext) error { +func MergePull(requestCtx stdctx.Context, ctx *context.TeaContext) error { if ctx.LocalRepo == nil { return fmt.Errorf("pull request index is required") } @@ -27,12 +29,12 @@ func MergePull(ctx *context.TeaContext) error { return err } - idx, err := getPullIndex(ctx, branch) + idx, err := getPullIndex(requestCtx, ctx, branch) if err != nil { 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"), @@ -40,7 +42,7 @@ func MergePull(ctx *context.TeaContext) error { } // getPullIndex interactively determines the PR index -func getPullIndex(ctx *context.TeaContext, branch string) (int64, error) { +func getPullIndex(requestCtx stdctx.Context, ctx *context.TeaContext, branch string) (int64, error) { c := ctx.Login.Client() opts := gitea.ListPullRequestsOptions{ State: gitea.StateOpen, @@ -53,7 +55,7 @@ func getPullIndex(ctx *context.TeaContext, branch string) (int64, error) { var prs []*gitea.PullRequest for { var err error - prs, _, err = c.ListRepoPullRequests(ctx.Owner, ctx.Repo, opts) + prs, _, err = c.PullRequests.ListRepoPullRequests(requestCtx, ctx.Owner, ctx.Repo, opts) if err != nil { return 0, err } diff --git a/modules/interact/pull_review.go b/modules/interact/pull_review.go index 6975fa05..d7110c66 100644 --- a/modules/interact/pull_review.go +++ b/modules/interact/pull_review.go @@ -4,15 +4,17 @@ package interact import ( + stdctx "context" "fmt" "os" "strconv" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - "code.gitea.io/tea/modules/task" - "code.gitea.io/tea/modules/theme" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + "gitea.dev/tea/modules/task" + "gitea.dev/tea/modules/theme" "charm.land/huh/v2" ) @@ -25,7 +27,7 @@ var reviewStates = map[string]gitea.ReviewStateType{ var reviewStateOptions = []string{"comment", "request changes", "approve"} // ReviewPull interactively reviews a PR -func ReviewPull(ctx *context.TeaContext, idx int64) error { +func ReviewPull(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) error { var state gitea.ReviewStateType var comment string var codeComments []gitea.CreatePullReviewComment @@ -43,7 +45,7 @@ func ReviewPull(ctx *context.TeaContext, idx int64) error { printTitleAndContent("Review / comment the diff?", strconv.FormatBool(reviewDiff)) if reviewDiff { - if codeComments, err = DoDiffReview(ctx, idx); err != nil { + if codeComments, err = DoDiffReview(requestCtx, ctx, idx); err != nil { fmt.Printf("Error during diff review: %s\n", err) } fmt.Printf("Found %d code comments in your review\n", len(codeComments)) @@ -77,14 +79,14 @@ func ReviewPull(ctx *context.TeaContext, idx int64) error { } printTitleAndContent("Concluding comment(markdown):", comment) - return task.CreatePullReview(ctx, idx, state, comment, codeComments) + return task.CreatePullReview(requestCtx, ctx, idx, state, comment, codeComments) } // DoDiffReview (1) fetches & saves diff in tempfile, (2) starts $VISUAL or $EDITOR to comment on diff, // (3) parses resulting file into code comments. // It doesn't really make sense to use survey.Editor() here, as we'd read the file content at least twice. -func DoDiffReview(ctx *context.TeaContext, idx int64) ([]gitea.CreatePullReviewComment, error) { - tmpFile, err := task.SavePullDiff(ctx, idx) +func DoDiffReview(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) ([]gitea.CreatePullReviewComment, error) { + tmpFile, err := task.SavePullDiff(requestCtx, ctx, idx) if err != nil { return nil, err } diff --git a/modules/print/actions.go b/modules/print/actions.go index d2bb232d..27d4bbe4 100644 --- a/modules/print/actions.go +++ b/modules/print/actions.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // ActionSecretsList prints a list of action secrets diff --git a/modules/print/actions_runs.go b/modules/print/actions_runs.go index aaf37995..7e0809c4 100644 --- a/modules/print/actions_runs.go +++ b/modules/print/actions_runs.go @@ -7,7 +7,7 @@ import ( "fmt" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // formatDurationMinutes formats duration in a human-readable way diff --git a/modules/print/actions_runs_test.go b/modules/print/actions_runs_test.go index 5a3a2630..fe9dff2d 100644 --- a/modules/print/actions_runs_test.go +++ b/modules/print/actions_runs_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/require" ) diff --git a/modules/print/actions_test.go b/modules/print/actions_test.go index 129e55c2..4cdfb753 100644 --- a/modules/print/actions_test.go +++ b/modules/print/actions_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/require" ) diff --git a/modules/print/attachment.go b/modules/print/attachment.go index 074b85cb..fd04122e 100644 --- a/modules/print/attachment.go +++ b/modules/print/attachment.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) func formatByteSize(size int64) string { diff --git a/modules/print/branch.go b/modules/print/branch.go index b5d91507..9b751c87 100644 --- a/modules/print/branch.go +++ b/modules/print/branch.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // BranchesList prints a listing of the branches diff --git a/modules/print/branch_test.go b/modules/print/branch_test.go index d6db9d89..74f01e4c 100644 --- a/modules/print/branch_test.go +++ b/modules/print/branch_test.go @@ -6,7 +6,7 @@ package print import ( "testing" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" ) diff --git a/modules/print/comment.go b/modules/print/comment.go index a1856b54..0f42e295 100644 --- a/modules/print/comment.go +++ b/modules/print/comment.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // Comments renders a list of comments to stdout diff --git a/modules/print/formatters.go b/modules/print/formatters.go index 512cf536..ce05b313 100644 --- a/modules/print/formatters.go +++ b/modules/print/formatters.go @@ -9,7 +9,7 @@ import ( "regexp" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/muesli/termenv" "golang.org/x/term" ) diff --git a/modules/print/issue.go b/modules/print/issue.go index ca4fc5aa..86110422 100644 --- a/modules/print/issue.go +++ b/modules/print/issue.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/enescakir/emoji" ) diff --git a/modules/print/label.go b/modules/print/label.go index 4be87531..3c2a5b2e 100644 --- a/modules/print/label.go +++ b/modules/print/label.go @@ -6,7 +6,7 @@ package print import ( "strconv" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // LabelsList prints a listing of labels diff --git a/modules/print/login.go b/modules/print/login.go index 9e98fe87..fd992fe9 100644 --- a/modules/print/login.go +++ b/modules/print/login.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" ) // LoginDetails print login entry to stdout diff --git a/modules/print/milestone.go b/modules/print/milestone.go index e53a63cb..840a3c72 100644 --- a/modules/print/milestone.go +++ b/modules/print/milestone.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // MilestoneDetails print an milestone formatted to stdout diff --git a/modules/print/notification.go b/modules/print/notification.go index d0e0c1dd..419ed05b 100644 --- a/modules/print/notification.go +++ b/modules/print/notification.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // NotificationsList prints a listing of notification threads diff --git a/modules/print/organization.go b/modules/print/organization.go index 9b627a12..885bd6fd 100644 --- a/modules/print/organization.go +++ b/modules/print/organization.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // OrganizationDetails prints details of an org with formatting diff --git a/modules/print/pull.go b/modules/print/pull.go index 09d6cd6f..5e415836 100644 --- a/modules/print/pull.go +++ b/modules/print/pull.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) var ciStatusSymbols = map[gitea.StatusState]string{ diff --git a/modules/print/pull_review_comment.go b/modules/print/pull_review_comment.go index 738d7eeb..f7a1da22 100644 --- a/modules/print/pull_review_comment.go +++ b/modules/print/pull_review_comment.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // PullReviewCommentFields are all available fields to print with PullReviewCommentsList() diff --git a/modules/print/pull_test.go b/modules/print/pull_test.go index 7ce2147d..d771ff82 100644 --- a/modules/print/pull_test.go +++ b/modules/print/pull_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/modules/print/release.go b/modules/print/release.go index 07ab1419..03791223 100644 --- a/modules/print/release.go +++ b/modules/print/release.go @@ -4,7 +4,7 @@ package print import ( - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // ReleasesList prints a listing of releases diff --git a/modules/print/repo.go b/modules/print/repo.go index 353bc8b7..abf429cb 100644 --- a/modules/print/repo.go +++ b/modules/print/repo.go @@ -8,7 +8,7 @@ import ( "strings" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // ReposList prints a listing of the repos diff --git a/modules/print/repo_test.go b/modules/print/repo_test.go index 767d7a01..101b7cc5 100644 --- a/modules/print/repo_test.go +++ b/modules/print/repo_test.go @@ -8,7 +8,7 @@ import ( "encoding/json" "testing" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/require" ) diff --git a/modules/print/sshkey.go b/modules/print/sshkey.go index f08376bb..3d582219 100644 --- a/modules/print/sshkey.go +++ b/modules/print/sshkey.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // SSHKeysList prints a table of SSH public keys diff --git a/modules/print/times.go b/modules/print/times.go index cb3b1185..5a025d4b 100644 --- a/modules/print/times.go +++ b/modules/print/times.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // TrackedTimesList print list of tracked times to stdout diff --git a/modules/print/user.go b/modules/print/user.go index a60c0ad1..a0b98a4f 100644 --- a/modules/print/user.go +++ b/modules/print/user.go @@ -6,7 +6,7 @@ package print import ( "fmt" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // UserDetails print a formatted user to stdout diff --git a/modules/print/webhook.go b/modules/print/webhook.go index 577bddce..275f33c7 100644 --- a/modules/print/webhook.go +++ b/modules/print/webhook.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // WebhooksList prints a listing of webhooks diff --git a/modules/print/webhook_test.go b/modules/print/webhook_test.go index 017379cd..18deadac 100644 --- a/modules/print/webhook_test.go +++ b/modules/print/webhook_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" "github.com/stretchr/testify/assert" ) diff --git a/modules/task/issue_create.go b/modules/task/issue_create.go index f1ccf3b8..35b9c245 100644 --- a/modules/task/issue_create.go +++ b/modules/task/issue_create.go @@ -4,21 +4,23 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/print" ) // CreateIssue creates an issue in the given repo and prints the result -func CreateIssue(login *config.Login, repoOwner, repoName string, opts gitea.CreateIssueOption) error { +func CreateIssue(requestCtx stdctx.Context, rlogin *config.Login, repoOwner, repoName string, opts gitea.CreateIssueOption) error { // title is required if len(opts.Title) == 0 { return fmt.Errorf("title is required") } - issue, _, err := login.Client().CreateIssue(repoOwner, repoName, opts) + issue, _, err := rlogin.Client().Issues.CreateIssue(requestCtx, repoOwner, repoName, opts) if err != nil { return fmt.Errorf("could not create issue: %s", err) } diff --git a/modules/task/issue_edit.go b/modules/task/issue_edit.go index 6a4b9fd3..51711720 100644 --- a/modules/task/issue_edit.go +++ b/modules/task/issue_edit.go @@ -4,11 +4,13 @@ package task import ( + stdctx "context" "fmt" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/context" ) // EditIssueOption wraps around gitea.EditIssueOption which has bad & incosistent semantics. @@ -29,12 +31,12 @@ type EditIssueOption struct { // Normalizes the options into parameters that can be passed to the sdk. // the returned value will be nil, when no change to this part of the issue is requested. -func (o EditIssueOption) toSdkOptions(ctx *context.TeaContext, client *gitea.Client) (*gitea.EditIssueOption, *gitea.IssueLabelsOption, *gitea.IssueLabelsOption, error) { - addLabelOpts, err := ResolveLabelOpts(client, ctx.Owner, ctx.Repo, o.AddLabels) +func (o EditIssueOption) toSdkOptions(requestCtx stdctx.Context, ctx *context.TeaContext, client *gitea.Client) (*gitea.EditIssueOption, *gitea.IssueLabelsOption, *gitea.IssueLabelsOption, error) { + addLabelOpts, err := ResolveLabelOpts(requestCtx, client, ctx.Owner, ctx.Repo, o.AddLabels) if err != nil { return nil, nil, nil, err } - rmLabelOpts, err := ResolveLabelOpts(client, ctx.Owner, ctx.Repo, o.RemoveLabels) + rmLabelOpts, err := ResolveLabelOpts(requestCtx, client, ctx.Owner, ctx.Repo, o.RemoveLabels) if err != nil { return nil, nil, nil, err } @@ -54,7 +56,7 @@ func (o EditIssueOption) toSdkOptions(ctx *context.TeaContext, client *gitea.Cli issueOptsDirty = true } if o.Milestone != nil { - id, err := ResolveMilestoneID(client, ctx.Owner, ctx.Repo, *o.Milestone) + id, err := ResolveMilestoneID(requestCtx, client, ctx.Owner, ctx.Repo, *o.Milestone) if err != nil { return nil, nil, nil, err } @@ -80,28 +82,28 @@ func (o EditIssueOption) toSdkOptions(ctx *context.TeaContext, client *gitea.Cli } // EditIssue edits an issue and returns the updated issue. -func EditIssue(ctx *context.TeaContext, client *gitea.Client, opts EditIssueOption) (*gitea.Issue, error) { +func EditIssue(requestCtx stdctx.Context, ctx *context.TeaContext, client *gitea.Client, opts EditIssueOption) (*gitea.Issue, error) { if client == nil { client = ctx.Login.Client() } - issueOpts, addLabelOpts, rmLabelOpts, err := opts.toSdkOptions(ctx, client) + issueOpts, addLabelOpts, rmLabelOpts, err := opts.toSdkOptions(requestCtx, ctx, client) if err != nil { return nil, err } - if err := ApplyLabelChanges(client, ctx.Owner, ctx.Repo, opts.Index, addLabelOpts, rmLabelOpts); err != nil { + if err := ApplyLabelChanges(requestCtx, client, ctx.Owner, ctx.Repo, opts.Index, addLabelOpts, rmLabelOpts); err != nil { return nil, err } var issue *gitea.Issue if issueOpts != nil { - issue, _, err = client.EditIssue(ctx.Owner, ctx.Repo, opts.Index, *issueOpts) + issue, _, err = client.Issues.EditIssue(requestCtx, ctx.Owner, ctx.Repo, opts.Index, *issueOpts) if err != nil { return nil, fmt.Errorf("could not edit issue: %s", err) } } else { - issue, _, err = client.GetIssue(ctx.Owner, ctx.Repo, opts.Index) + issue, _, err = client.Issues.GetIssue(requestCtx, ctx.Owner, ctx.Repo, opts.Index) if err != nil { return nil, fmt.Errorf("could not get issue: %s", err) } diff --git a/modules/task/labels.go b/modules/task/labels.go index 79fc6725..e34608e3 100644 --- a/modules/task/labels.go +++ b/modules/task/labels.go @@ -4,18 +4,20 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/utils" ) // ResolveLabelNames returns a list of label IDs for a given list of label names -func ResolveLabelNames(client *gitea.Client, owner, repo string, labelNames []string) ([]int64, error) { +func ResolveLabelNames(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, labelNames []string) ([]int64, error) { labelIDs := make([]int64, 0, len(labelNames)) page := 1 for { - labels, resp, err := client.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ + labels, resp, err := client.Repositories.ListRepoLabels(requestCtx, owner, repo, gitea.ListLabelsOptions{ ListOptions: gitea.ListOptions{Page: page, PageSize: 50}, }) if err != nil { @@ -35,11 +37,11 @@ func ResolveLabelNames(client *gitea.Client, owner, repo string, labelNames []st } // ResolveLabelOpts resolves label names to IssueLabelsOption. Returns nil if names is empty. -func ResolveLabelOpts(client *gitea.Client, owner, repo string, names []string) (*gitea.IssueLabelsOption, error) { +func ResolveLabelOpts(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, names []string) (*gitea.IssueLabelsOption, error) { if len(names) == 0 { return nil, nil } - ids, err := ResolveLabelNames(client, owner, repo, names) + ids, err := ResolveLabelNames(requestCtx, client, owner, repo, names) if err != nil { return nil, err } @@ -47,18 +49,18 @@ func ResolveLabelOpts(client *gitea.Client, owner, repo string, names []string) } // ApplyLabelChanges adds and removes labels on an issue or pull request. -func ApplyLabelChanges(client *gitea.Client, owner, repo string, index int64, add, rm *gitea.IssueLabelsOption) error { +func ApplyLabelChanges(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, index int64, add, rm *gitea.IssueLabelsOption) error { if rm != nil { // NOTE: as of 1.17, there is no API to remove multiple labels at once. for _, id := range rm.Labels { - _, err := client.DeleteIssueLabel(owner, repo, index, id) + _, err := client.Issues.DeleteIssueLabel(requestCtx, owner, repo, index, id) if err != nil { return fmt.Errorf("could not remove labels: %s", err) } } } if add != nil { - _, _, err := client.AddIssueLabels(owner, repo, index, *add) + _, _, err := client.Issues.AddIssueLabels(requestCtx, owner, repo, index, *add) if err != nil { return fmt.Errorf("could not add labels: %s", err) } @@ -67,9 +69,9 @@ func ApplyLabelChanges(client *gitea.Client, owner, repo string, index int64, ad } // ApplyReviewerChanges adds and removes reviewers on a pull request. -func ApplyReviewerChanges(client *gitea.Client, owner, repo string, index int64, add, rm []string) error { +func ApplyReviewerChanges(requestCtx stdctx.Context, client *gitea.Client, owner, repo string, index int64, add, rm []string) error { if len(rm) != 0 { - _, err := client.DeleteReviewRequests(owner, repo, index, gitea.PullReviewRequestOptions{ + _, err := client.PullRequests.DeleteReviewRequests(requestCtx, owner, repo, index, gitea.PullReviewRequestOptions{ Reviewers: rm, }) if err != nil { @@ -77,7 +79,7 @@ func ApplyReviewerChanges(client *gitea.Client, owner, repo string, index int64, } } if len(add) != 0 { - _, err := client.CreateReviewRequests(owner, repo, index, gitea.PullReviewRequestOptions{ + _, err := client.PullRequests.CreateReviewRequests(requestCtx, owner, repo, index, gitea.PullReviewRequestOptions{ Reviewers: add, }) if err != nil { @@ -88,11 +90,11 @@ func ApplyReviewerChanges(client *gitea.Client, owner, repo string, index int64, } // ResolveMilestoneID resolves a milestone name to its ID. Returns 0 for empty name. -func ResolveMilestoneID(client *gitea.Client, owner, repo, name string) (int64, error) { +func ResolveMilestoneID(requestCtx stdctx.Context, client *gitea.Client, owner, repo, name string) (int64, error) { if name == "" { return 0, nil } - ms, _, err := client.GetMilestoneByName(owner, repo, name) + ms, _, err := client.Repositories.GetMilestoneByName(requestCtx, owner, repo, name) if err != nil { return 0, fmt.Errorf("could not resolve milestone '%s': %w", name, err) } diff --git a/modules/task/labels_export.go b/modules/task/labels_export.go index b4d9dbc5..7beb8031 100644 --- a/modules/task/labels_export.go +++ b/modules/task/labels_export.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "code.gitea.io/sdk/gitea" + "gitea.dev/sdk" ) // LabelsExport save list of labels to disc diff --git a/modules/task/login_create.go b/modules/task/login_create.go index 2d54c48d..1db94f8c 100644 --- a/modules/task/login_create.go +++ b/modules/task/login_create.go @@ -4,16 +4,17 @@ package task import ( + stdctx "context" "fmt" "os" "os/exec" "strings" "time" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/utils" ) // SetupHelper add tea helper to config global @@ -48,7 +49,7 @@ func SetupHelper(login config.Login) (ok bool, err error) { } // CreateLogin create a login to be stored in config -func CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string, insecure, sshAgent, versionCheck, addHelper bool) error { +func CreateLogin(ctx stdctx.Context, name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCertPrincipal, sshKeyFingerprint string, insecure, sshAgent, versionCheck, addHelper bool) error { // checks ... // ... if we have a url if len(giteaURL) == 0 { @@ -105,7 +106,7 @@ func CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCe } if len(token) == 0 && sshCertPrincipal == "" && !sshAgent && sshKey == "" { - if login.Token, err = generateToken(login, user, passwd, otp, scopes); err != nil { + if login.Token, err = generateToken(ctx, login, user, passwd, otp, scopes); err != nil { return err } } @@ -113,7 +114,7 @@ func CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCe client := login.Client() // Verify if authentication works and get user info - u, _, err := client.GetMyUserInfo() + u, _, err := client.Users.GetMyUserInfo(ctx) if err != nil { return err } @@ -130,7 +131,7 @@ func CreateLogin(name, token, user, passwd, otp, scopes, sshKey, giteaURL, sshCe login.SSHHost = serverURL.Host if len(sshKey) == 0 { - login.SSHKey, err = findSSHKey(client) + login.SSHKey, err = findSSHKey(ctx, client) if err != nil { fmt.Printf("Warning: problem while finding a SSH key: %s\n", err) } @@ -159,7 +160,7 @@ func shouldCheckTokenUniqueness(token string, sshAgent bool, sshKey, sshCertPrin } // generateToken creates a new token when given BasicAuth credentials -func generateToken(login config.Login, user, pass, otp, scopes string) (string, error) { +func generateToken(ctx stdctx.Context, login config.Login, user, pass, otp, scopes string) (string, error) { opts := []gitea.ClientOption{gitea.SetBasicAuth(user, pass)} if otp != "" { opts = append(opts, gitea.SetOTP(otp)) @@ -168,7 +169,7 @@ func generateToken(login config.Login, user, pass, otp, scopes string) (string, var tl []*gitea.AccessToken for page := 1; ; { - page_tokens, resp, err := client.ListAccessTokens(gitea.ListAccessTokensOptions{ + page_tokens, resp, err := client.Users.ListAccessTokens(ctx, gitea.ListAccessTokensOptions{ ListOptions: gitea.ListOptions{Page: page, PageSize: 50}, }) if err != nil { @@ -200,7 +201,7 @@ func generateToken(login config.Login, user, pass, otp, scopes string) (string, } } - t, _, err := client.CreateAccessToken(gitea.CreateAccessTokenOption{ + t, _, err := client.Users.CreateAccessToken(ctx, gitea.CreateAccessTokenOption{ Name: tokenName, Scopes: tokenScopes, }) diff --git a/modules/task/login_httpsign.go b/modules/task/login_httpsign.go index 0b0ad8e8..1e4a9b69 100644 --- a/modules/task/login_httpsign.go +++ b/modules/task/login_httpsign.go @@ -8,9 +8,10 @@ import ( "path/filepath" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/utils" + "gitea.dev/sdk" "golang.org/x/crypto/ssh" + + "gitea.dev/tea/modules/utils" ) // ListSSHPubkey lists all the ssh keys in the ssh agent and the ~/.ssh/*.pub files diff --git a/modules/task/login_ssh.go b/modules/task/login_ssh.go index eebcb28b..4bcfcbbc 100644 --- a/modules/task/login_ssh.go +++ b/modules/task/login_ssh.go @@ -4,24 +4,25 @@ package task import ( + stdctx "context" "encoding/base64" "os" "path/filepath" "strings" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/modules/utils" "golang.org/x/crypto/ssh" ) // findSSHKey retrieves the ssh keys registered in gitea, and tries to find // a matching private key in ~/.ssh/. If no match is found, path is empty. -func findSSHKey(client *gitea.Client) (string, error) { +func findSSHKey(ctx stdctx.Context, client *gitea.Client) (string, error) { // get keys registered on gitea instance var keys []*gitea.PublicKey for page := 1; ; { - page_keys, resp, err := client.ListMyPublicKeys(gitea.ListPublicKeysOptions{ + page_keys, resp, err := client.Users.ListMyPublicKeys(ctx, gitea.ListPublicKeysOptions{ ListOptions: gitea.ListOptions{Page: page, PageSize: 50}, }) if err != nil { diff --git a/modules/task/milestone_create.go b/modules/task/milestone_create.go index d6ee0936..8eaf0699 100644 --- a/modules/task/milestone_create.go +++ b/modules/task/milestone_create.go @@ -4,23 +4,24 @@ package task import ( + stdctx "context" "fmt" "time" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/print" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/print" ) // CreateMilestone creates a milestone in the given repo and prints the result -func CreateMilestone(login *config.Login, repoOwner, repoName, title, description string, deadline *time.Time, state gitea.StateType) error { +func CreateMilestone(ctx stdctx.Context, login *config.Login, repoOwner, repoName, title, description string, deadline *time.Time, state gitea.StateType) error { // title is required if len(title) == 0 { return fmt.Errorf("title is required") } - mile, _, err := login.Client().CreateMilestone(repoOwner, repoName, gitea.CreateMilestoneOption{ + mile, _, err := login.Client().Repositories.CreateMilestone(ctx, repoOwner, repoName, gitea.CreateMilestoneOption{ Title: title, Description: description, Deadline: deadline, diff --git a/modules/task/pull_checkout.go b/modules/task/pull_checkout.go index bdf98b89..7d4854a4 100644 --- a/modules/task/pull_checkout.go +++ b/modules/task/pull_checkout.go @@ -4,6 +4,7 @@ package task import ( + stdctx "context" "encoding/base64" "fmt" "os" @@ -11,17 +12,16 @@ import ( "strconv" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - local_git "code.gitea.io/tea/modules/git" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" - "github.com/go-git/go-git/v5" - git_plumbing "github.com/go-git/go-git/v5/plumbing" + "gitea.dev/tea/modules/config" + local_git "gitea.dev/tea/modules/git" + "gitea.dev/tea/modules/utils" ) // PullCheckout checkout current workdir to the head branch of specified pull request func PullCheckout( + ctx stdctx.Context, login *config.Login, repoOwner, repoName string, forceCreateBranch bool, @@ -29,7 +29,7 @@ func PullCheckout( callback func(string) (string, error), ) error { client := login.Client() - pr, _, err := client.GetPullRequest(repoOwner, repoName, index) + pr, _, err := client.PullRequests.GetPullRequest(ctx, repoOwner, repoName, index) if err != nil { return fmt.Errorf("couldn't fetch PR: %s", err) } @@ -80,7 +80,7 @@ func doPRFetch( login *config.Login, pr *gitea.PullRequest, localRepo *local_git.TeaRepo, - localRemote *git.Remote, + localRemote *local_git.Remote, callback func(string) (string, error), ) (string, error) { _ = callback @@ -90,6 +90,10 @@ func doPRFetch( if err != nil { return "", err } + auth, err := local_git.GetAuthForURL(url, login.GetAccessToken(), login.SSHKey, callback) + if err != nil { + return "", err + } refspecs := []string{} if isRemoteDeleted(pr) { // When the head branch is already deleted, pr.Head.Ref points to @@ -97,15 +101,15 @@ func doPRFetch( // This ref must be fetched explicitly, and does not allow pushing, so we use it // only in this case as fallback. localBranchName = fmt.Sprintf("pulls/%d", pr.Index) - refspecs = append(refspecs, fmt.Sprintf("%s:refs/remotes/%s/%s", + refspecs = []string{fmt.Sprintf("%s:refs/remotes/%s/%s", pr.Head.Ref, localRemoteName, localBranchName, - )) + )} } fmt.Printf("Fetching PR %v (head %s:%s) from remote '%s'\n", pr.Index, url, pr.Head.Ref, localRemoteName) - err = runGitFetch(localRemoteName, url.String(), login.GetAccessToken(), login.SSHKey, refspecs...) + err = localRepo.Fetch(localRemoteName, refspecs, auth) if err != nil { return "", err } @@ -122,12 +126,12 @@ func doPRCheckout( ) error { // determine the ref to checkout, depending on existence of a matching commit on a local branch var info string - var checkoutRef git_plumbing.ReferenceName + var checkoutRef local_git.ReferenceName if b, _ := localRepo.TeaFindBranchBySha(pr.Head.Sha, remoteURL); b != nil { // if a matching branch exists, use that - checkoutRef = git_plumbing.NewBranchReferenceName(b.Name) + checkoutRef = local_git.NewBranchReferenceName(b.Name) info = fmt.Sprintf("Found matching local branch %s, checking it out", checkoutRef.Short()) } else if forceCreateBranch { @@ -137,10 +141,10 @@ func doPRCheckout( if isRemoteDeleted(pr) { localBranchName += "-" + pr.Head.Ref } - checkoutRef = git_plumbing.NewBranchReferenceName(localBranchName) + checkoutRef = local_git.NewBranchReferenceName(localBranchName) if err := localRepo.TeaCreateBranch(localBranchName, localRemoteBranchName, localRemoteName); err == nil { info = fmt.Sprintf("Created branch '%s'\n", localBranchName) - } else if err == git.ErrBranchExists { + } else if err == local_git.ErrBranchExists { info = "There may be changes since you last checked out, run `git pull` to get them." } else { return err @@ -149,7 +153,7 @@ func doPRCheckout( } else { // use the remote tracking branch - checkoutRef = git_plumbing.NewRemoteReferenceName(localRemoteName, localRemoteBranchName) + checkoutRef = local_git.NewRemoteReferenceName(localRemoteName, localRemoteBranchName) info = fmt.Sprintf( "Checking out remote tracking branch %s. To make changes, create a new branch:\n git checkout %s", checkoutRef.String(), localRemoteBranchName) diff --git a/modules/task/pull_clean.go b/modules/task/pull_clean.go index 5b3512b3..d96dab0b 100644 --- a/modules/task/pull_clean.go +++ b/modules/task/pull_clean.go @@ -4,21 +4,20 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/tea/modules/config" - local_git "code.gitea.io/tea/modules/git" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" - git_config "github.com/go-git/go-git/v5/config" - git_plumbing "github.com/go-git/go-git/v5/plumbing" + "gitea.dev/tea/modules/config" + local_git "gitea.dev/tea/modules/git" ) // PullClean deletes local & remote feature-branches for a closed pull -func PullClean(login *config.Login, repoOwner, repoName string, index int64, ignoreSHA bool, callback func(string) (string, error)) error { +func PullClean(ctx stdctx.Context, login *config.Login, repoOwner, repoName string, index int64, ignoreSHA bool, callback func(string) (string, error)) error { client := login.Client() - repo, _, err := client.GetRepo(repoOwner, repoName) + repo, _, err := client.Repositories.GetRepo(ctx, repoOwner, repoName) if err != nil { return err } @@ -28,7 +27,7 @@ func PullClean(login *config.Login, repoOwner, repoName string, index int64, ign } // fetch PR source-repo & -branch from gitea - pr, _, err := client.GetPullRequest(repoOwner, repoName, index) + pr, _, err := client.PullRequests.GetPullRequest(ctx, repoOwner, repoName, index) if err != nil { return err } @@ -51,7 +50,7 @@ func PullClean(login *config.Login, repoOwner, repoName string, index int64, ign } // find a branch with matching sha or name, that has a remote matching the repo url - var branch *git_config.Branch + var branch *local_git.Branch if ignoreSHA { branch, err = r.TeaFindBranchByName(remoteBranch, pr.Head.Repository.CloneURL) } else { @@ -77,7 +76,7 @@ call me again with the --ignore-sha flag`, remoteBranch) } if headRef.Name().Short() == branch.Name { fmt.Printf("Checking out '%s' to delete local branch '%s'\n", defaultBranch, branch.Name) - ref := git_plumbing.NewBranchReferenceName(defaultBranch) + ref := local_git.NewBranchReferenceName(defaultBranch) if err = r.TeaCheckout(ref); err != nil { return err } diff --git a/modules/task/pull_create.go b/modules/task/pull_create.go index 58c56bb5..9bd2f597 100644 --- a/modules/task/pull_create.go +++ b/modules/task/pull_create.go @@ -4,16 +4,18 @@ package task import ( + stdctx "context" "fmt" "regexp" "strings" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/context" - local_git "code.gitea.io/tea/modules/git" - "code.gitea.io/tea/modules/print" - "code.gitea.io/tea/modules/utils" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/context" + local_git "gitea.dev/tea/modules/git" + "gitea.dev/tea/modules/print" + "gitea.dev/tea/modules/utils" ) var ( @@ -23,10 +25,10 @@ var ( ) // CreatePull creates a PR in the given repo and prints the result -func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits *bool, opts *gitea.CreateIssueOption) (err error) { +func CreatePull(requestCtx stdctx.Context, ctx *context.TeaContext, base, head string, allowMaintainerEdits *bool, opts *gitea.CreateIssueOption) (err error) { // default is default branch if len(base) == 0 { - base, err = GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo) + base, err = GetDefaultPRBase(requestCtx, ctx.Login, ctx.Owner, ctx.Repo) if err != nil { return err } @@ -61,7 +63,7 @@ func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits client := ctx.Login.Client() - pr, _, err := client.CreatePullRequest(ctx.Owner, ctx.Repo, gitea.CreatePullRequestOption{ + pr, _, err := client.PullRequests.CreatePullRequest(requestCtx, ctx.Owner, ctx.Repo, gitea.CreatePullRequestOption{ Head: head, Base: base, Title: opts.Title, @@ -76,7 +78,7 @@ func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits } if allowMaintainerEdits != nil && pr.AllowMaintainerEdit != *allowMaintainerEdits { - pr, _, err = client.EditPullRequest(ctx.Owner, ctx.Repo, pr.Index, gitea.EditPullRequestOption{ + pr, _, err = client.PullRequests.EditPullRequest(requestCtx, ctx.Owner, ctx.Repo, pr.Index, gitea.EditPullRequestOption{ AllowMaintainerEdit: allowMaintainerEdits, }) if err != nil { @@ -92,8 +94,8 @@ func CreatePull(ctx *context.TeaContext, base, head string, allowMaintainerEdits } // GetDefaultPRBase retrieves the default base branch for the given repo -func GetDefaultPRBase(login *config.Login, owner, repo string) (string, error) { - meta, _, err := login.Client().GetRepo(owner, repo) +func GetDefaultPRBase(requestCtx stdctx.Context, login *config.Login, owner, repo string) (string, error) { + meta, _, err := login.Client().Repositories.GetRepo(requestCtx, owner, repo) if err != nil { return "", fmt.Errorf("could not fetch repo meta: %s", err) } @@ -155,13 +157,13 @@ func GetDefaultPRTitle(header string) string { } // CreateAgitFlowPull creates a agit flow PR in the given repo and prints the result -func CreateAgitFlowPull(ctx *context.TeaContext, remote, head, base, topic string, +func CreateAgitFlowPull(requestCtx stdctx.Context, ctx *context.TeaContext, remote, head, base, topic string, opts *gitea.CreateIssueOption, callback func(string) (string, error), ) (err error) { // default is default branch if len(base) == 0 { - base, err = GetDefaultPRBase(ctx.Login, ctx.Owner, ctx.Repo) + base, err = GetDefaultPRBase(requestCtx, ctx.Login, ctx.Owner, ctx.Repo) if err != nil { return err } diff --git a/modules/task/pull_edit.go b/modules/task/pull_edit.go index 0d73cfdc..c53dc39f 100644 --- a/modules/task/pull_edit.go +++ b/modules/task/pull_edit.go @@ -4,23 +4,24 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" + "gitea.dev/tea/modules/context" ) // EditPull edits a pull request and returns the updated pull request. -func EditPull(ctx *context.TeaContext, client *gitea.Client, opts EditIssueOption) (*gitea.PullRequest, error) { +func EditPull(requestCtx stdctx.Context, ctx *context.TeaContext, client *gitea.Client, opts EditIssueOption) (*gitea.PullRequest, error) { if client == nil { client = ctx.Login.Client() } - addLabelOpts, err := ResolveLabelOpts(client, ctx.Owner, ctx.Repo, opts.AddLabels) + addLabelOpts, err := ResolveLabelOpts(requestCtx, client, ctx.Owner, ctx.Repo, opts.AddLabels) if err != nil { return nil, err } - rmLabelOpts, err := ResolveLabelOpts(client, ctx.Owner, ctx.Repo, opts.RemoveLabels) + rmLabelOpts, err := ResolveLabelOpts(requestCtx, client, ctx.Owner, ctx.Repo, opts.RemoveLabels) if err != nil { return nil, err } @@ -36,7 +37,7 @@ func EditPull(ctx *context.TeaContext, client *gitea.Client, opts EditIssueOptio prOptsDirty = true } if opts.Milestone != nil { - id, err := ResolveMilestoneID(client, ctx.Owner, ctx.Repo, *opts.Milestone) + id, err := ResolveMilestoneID(requestCtx, client, ctx.Owner, ctx.Repo, *opts.Milestone) if err != nil { return nil, err } @@ -55,22 +56,22 @@ func EditPull(ctx *context.TeaContext, client *gitea.Client, opts EditIssueOptio prOptsDirty = true } - if err := ApplyLabelChanges(client, ctx.Owner, ctx.Repo, opts.Index, addLabelOpts, rmLabelOpts); err != nil { + if err := ApplyLabelChanges(requestCtx, client, ctx.Owner, ctx.Repo, opts.Index, addLabelOpts, rmLabelOpts); err != nil { return nil, err } - if err := ApplyReviewerChanges(client, ctx.Owner, ctx.Repo, opts.Index, opts.AddReviewers, opts.RemoveReviewers); err != nil { + if err := ApplyReviewerChanges(requestCtx, client, ctx.Owner, ctx.Repo, opts.Index, opts.AddReviewers, opts.RemoveReviewers); err != nil { return nil, err } var pr *gitea.PullRequest if prOptsDirty { - pr, _, err = client.EditPullRequest(ctx.Owner, ctx.Repo, opts.Index, prOpts) + pr, _, err = client.PullRequests.EditPullRequest(requestCtx, ctx.Owner, ctx.Repo, opts.Index, prOpts) if err != nil { return nil, fmt.Errorf("could not edit pull request: %s", err) } } else { - pr, _, err = client.GetPullRequest(ctx.Owner, ctx.Repo, opts.Index) + pr, _, err = client.PullRequests.GetPullRequest(requestCtx, ctx.Owner, ctx.Repo, opts.Index) if err != nil { return nil, fmt.Errorf("could not get pull request: %s", err) } diff --git a/modules/task/pull_merge.go b/modules/task/pull_merge.go index 1e28a58b..171f5d2b 100644 --- a/modules/task/pull_merge.go +++ b/modules/task/pull_merge.go @@ -4,16 +4,18 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/config" ) // PullMerge merges a PR -func PullMerge(login *config.Login, repoOwner, repoName string, index int64, opt gitea.MergePullRequestOption) error { +func PullMerge(requestCtx stdctx.Context, login *config.Login, repoOwner, repoName string, index int64, opt gitea.MergePullRequestOption) error { client := login.Client() - success, _, err := client.MergePullRequest(repoOwner, repoName, index, opt) + success, _, err := client.PullRequests.MergePullRequest(requestCtx, repoOwner, repoName, index, opt) if err != nil { return err } diff --git a/modules/task/pull_review.go b/modules/task/pull_review.go index a2f2ba51..2c650129 100644 --- a/modules/task/pull_review.go +++ b/modules/task/pull_review.go @@ -4,15 +4,16 @@ package task import ( + stdctx "context" "fmt" "os" "os/exec" "strings" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" - "code.gitea.io/sdk/gitea" unidiff "gitea.com/noerw/unidiff-comments" + "gitea.dev/tea/modules/context" ) var diffReviewHelp = `# This is the current diff of PR #%d on %s. @@ -28,10 +29,10 @@ var diffReviewHelp = `# This is the current diff of PR #%d on %s. ` // CreatePullReview submits a review for a PR -func CreatePullReview(ctx *context.TeaContext, idx int64, status gitea.ReviewStateType, comment string, codeComments []gitea.CreatePullReviewComment) error { +func CreatePullReview(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64, status gitea.ReviewStateType, comment string, codeComments []gitea.CreatePullReviewComment) error { c := ctx.Login.Client() - review, _, err := c.CreatePullReview(ctx.Owner, ctx.Repo, idx, gitea.CreatePullReviewOptions{ + review, _, err := c.PullRequests.CreatePullReview(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.CreatePullReviewOptions{ State: status, Body: comment, Comments: codeComments, @@ -46,8 +47,8 @@ func CreatePullReview(ctx *context.TeaContext, idx int64, status gitea.ReviewSta // SavePullDiff fetches the diff of a pull request and stores it as a temporary file. // The path to the file is returned. -func SavePullDiff(ctx *context.TeaContext, idx int64) (string, error) { - diff, _, err := ctx.Login.Client().GetPullRequestDiff(ctx.Owner, ctx.Repo, idx, gitea.PullRequestDiffOptions{}) +func SavePullDiff(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) (string, error) { + diff, _, err := ctx.Login.Client().PullRequests.GetPullRequestDiff(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.PullRequestDiffOptions{}) if err != nil { return "", err } diff --git a/modules/task/pull_review_comment.go b/modules/task/pull_review_comment.go index f1e541be..4e010b22 100644 --- a/modules/task/pull_review_comment.go +++ b/modules/task/pull_review_comment.go @@ -4,19 +4,21 @@ package task import ( + stdctx "context" "fmt" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/context" + gitea "gitea.dev/sdk" + + "gitea.dev/tea/modules/context" ) // ListPullReviewComments lists all review comments across all reviews for a PR -func ListPullReviewComments(ctx *context.TeaContext, idx int64) ([]*gitea.PullReviewComment, error) { +func ListPullReviewComments(requestCtx stdctx.Context, ctx *context.TeaContext, idx int64) ([]*gitea.PullReviewComment, error) { c := ctx.Login.Client() var reviews []*gitea.PullReview for page := 1; ; { - page_reviews, resp, err := c.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{ + page_reviews, resp, err := c.PullRequests.ListPullReviews(requestCtx, ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{ ListOptions: gitea.ListOptions{Page: page, PageSize: 50}, }) if err != nil { @@ -31,7 +33,7 @@ func ListPullReviewComments(ctx *context.TeaContext, idx int64) ([]*gitea.PullRe var allComments []*gitea.PullReviewComment for _, review := range reviews { - comments, _, err := c.ListPullReviewComments(ctx.Owner, ctx.Repo, idx, review.ID) + comments, _, err := c.PullRequests.ListPullReviewComments(requestCtx, ctx.Owner, ctx.Repo, idx, review.ID) if err != nil { return nil, err } @@ -42,10 +44,10 @@ func ListPullReviewComments(ctx *context.TeaContext, idx int64) ([]*gitea.PullRe } // ResolvePullReviewComment resolves a review comment -func ResolvePullReviewComment(ctx *context.TeaContext, commentID int64) error { +func ResolvePullReviewComment(requestCtx stdctx.Context, ctx *context.TeaContext, commentID int64) error { c := ctx.Login.Client() - _, err := c.ResolvePullReviewComment(ctx.Owner, ctx.Repo, commentID) + _, err := c.PullRequests.ResolvePullReviewComment(requestCtx, ctx.Owner, ctx.Repo, commentID) if err != nil { return err } @@ -55,10 +57,10 @@ func ResolvePullReviewComment(ctx *context.TeaContext, commentID int64) error { } // ReplyToPullReviewComment replies to a review comment on a pull request. -func ReplyToPullReviewComment(ctx *context.TeaContext, idx, commentID int64, body string) error { +func ReplyToPullReviewComment(requestCtx stdctx.Context, ctx *context.TeaContext, idx, commentID int64, body string) error { c := ctx.Login.Client() - comment, _, err := c.CreatePullReviewCommentReply(ctx.Owner, ctx.Repo, idx, commentID, gitea.CreatePullReviewCommentReplyOptions{ + comment, _, err := c.PullRequests.CreatePullReviewCommentReply(requestCtx, ctx.Owner, ctx.Repo, idx, commentID, gitea.CreatePullReviewCommentReplyOptions{ Body: body, }) if err != nil { @@ -70,10 +72,10 @@ func ReplyToPullReviewComment(ctx *context.TeaContext, idx, commentID int64, bod } // UnresolvePullReviewComment unresolves a review comment -func UnresolvePullReviewComment(ctx *context.TeaContext, commentID int64) error { +func UnresolvePullReviewComment(requestCtx stdctx.Context, ctx *context.TeaContext, commentID int64) error { c := ctx.Login.Client() - _, err := c.UnresolvePullReviewComment(ctx.Owner, ctx.Repo, commentID) + _, err := c.PullRequests.UnresolvePullReviewComment(requestCtx, ctx.Owner, ctx.Repo, commentID) if err != nil { return err } diff --git a/modules/task/repo_clone.go b/modules/task/repo_clone.go index b23af213..185c6bf2 100644 --- a/modules/task/repo_clone.go +++ b/modules/task/repo_clone.go @@ -4,28 +4,26 @@ package task import ( - "fmt" + stdctx "context" "net/url" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - local_git "code.gitea.io/tea/modules/git" + gitea "gitea.dev/sdk" - "github.com/go-git/go-git/v5" - git_config "github.com/go-git/go-git/v5/config" - "github.com/go-git/go-git/v5/plumbing" + "gitea.dev/tea/modules/config" + local_git "gitea.dev/tea/modules/git" ) // RepoClone creates a local git clone in the given path, and sets up upstream remote // for fork repos, for good usability with tea. func RepoClone( + ctx stdctx.Context, path string, login *config.Login, repoOwner, repoName string, callback func(string) (string, error), depth int, ) (*local_git.TeaRepo, error) { - repoMeta, _, err := login.Client().GetRepo(repoOwner, repoName) + repoMeta, _, err := login.Client().Repositories.GetRepo(ctx, repoOwner, repoName) if err != nil { return nil, err } @@ -45,12 +43,7 @@ func RepoClone( path = repoName } - repo, err := git.PlainClone(path, false, &git.CloneOptions{ - URL: originURL.String(), - Auth: auth, - Depth: depth, - InsecureSkipTLS: login.Insecure, - }) + repo, err := local_git.Clone(path, originURL.String(), auth, depth, login.Insecure) if err != nil { return nil, err } @@ -62,28 +55,15 @@ func RepoClone( return nil, err } upstreamBranch := repoMeta.Parent.DefaultBranch - _, err = repo.CreateRemote(&git_config.RemoteConfig{ - Name: "upstream", - URLs: []string{upstreamURL.String()}, - }) - if err != nil { + if err = repo.AddRemote("upstream", upstreamURL.String()); err != nil { return nil, err } - - repoConf, err := repo.Config() - if err != nil { - return nil, err - } - if b, ok := repoConf.Branches[upstreamBranch]; ok { - b.Remote = "upstream" - b.Merge = plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", upstreamBranch)) - } - if err = repo.SetConfig(repoConf); err != nil { + if err = repo.SetBranchUpstream(upstreamBranch, "upstream", upstreamBranch); err != nil { return nil, err } } - return &local_git.TeaRepo{Repository: repo}, nil + return repo, nil } func cloneURL(repo *gitea.Repository, login *config.Login) (*url.URL, error) { diff --git a/renovate.json5 b/renovate.json5 index c7e09e46..72388496 100644 --- a/renovate.json5 +++ b/renovate.json5 @@ -1,6 +1,8 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ - "local>gitea/renovate-config" + "local>gitea/renovate-config", + "local>gitea/renovate-config:security", + "local>gitea/renovate-config:go-deps" ] } diff --git a/tests/integration/admin_users_test.go b/tests/integration/admin_users_test.go index bd849411..586aff84 100644 --- a/tests/integration/admin_users_test.go +++ b/tests/integration/admin_users_test.go @@ -4,31 +4,31 @@ package integration import ( - "context" "fmt" "os" "path/filepath" "testing" "time" - "code.gitea.io/sdk/gitea" - teacmd "code.gitea.io/tea/cmd" + gitea "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + teacmd "gitea.dev/tea/cmd" ) func runAdminCommand(t *testing.T, args []string) error { t.Helper() adminCmd := teacmd.CmdAdmin - return adminCmd.Run(context.Background(), args) + return adminCmd.Run(t.Context(), args) } func createAdminTestUser(t *testing.T, client *gitea.Client, username, password string) { t.Helper() mustChangePassword := false - user, _, err := client.AdminCreateUser(gitea.CreateUserOption{ + user, _, err := client.Admin.CreateUser(t.Context(), gitea.CreateUserOption{ LoginName: username, Username: username, Email: username + "@example.com", @@ -39,7 +39,7 @@ func createAdminTestUser(t *testing.T, client *gitea.Client, username, password require.Equal(t, username, user.UserName) t.Cleanup(func() { - if _, err := client.AdminDeleteUser(username); err != nil { + if _, err := client.Admin.DeleteUser(t.Context(), username); err != nil { t.Logf("failed to delete integration test user %q: %v", username, err) } }) @@ -75,7 +75,7 @@ func TestAdminUsersCreateAndDelete(t *testing.T) { }) require.NoError(t, err) - createdUser, _, err := client.GetUserInfo(username) + createdUser, _, err := client.Users.GetUserInfo(t.Context(), username) require.NoError(t, err) assert.Equal(t, username, createdUser.UserName) assert.Equal(t, username+"@example.com", createdUser.Email) @@ -90,7 +90,7 @@ func TestAdminUsersCreateAndDelete(t *testing.T) { }) require.NoError(t, err) - _, _, err = client.GetUserInfo(username) + _, _, err = client.Users.GetUserInfo(t.Context(), username) require.Error(t, err) } @@ -117,7 +117,7 @@ func TestAdminUsersEdit(t *testing.T) { }) require.NoError(t, err) - updatedUser, _, err := client.GetUserInfo(username) + updatedUser, _, err := client.Users.GetUserInfo(t.Context(), username) require.NoError(t, err) assert.Equal(t, username+"+new@example.com", updatedUser.Email) assert.Equal(t, "Tea Integration", updatedUser.FullName) @@ -133,7 +133,7 @@ func TestAdminUsersEdit(t *testing.T) { ) require.NoError(t, err) - me, _, err := passwordClient.GetMyUserInfo() + me, _, err := passwordClient.Users.GetMyUserInfo(t.Context()) require.NoError(t, err) assert.Equal(t, username, me.UserName) } diff --git a/tests/integration/config_lock_unix_test.go b/tests/integration/config_lock_unix_test.go index ff712c62..5516aca2 100644 --- a/tests/integration/config_lock_unix_test.go +++ b/tests/integration/config_lock_unix_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "code.gitea.io/tea/modules/config" + "gitea.dev/tea/modules/config" ) func TestConfigLock_CrossProcess(t *testing.T) { diff --git a/tests/integration/context_init_test.go b/tests/integration/context_init_test.go index a220af25..c9bde9b6 100644 --- a/tests/integration/context_init_test.go +++ b/tests/integration/context_init_test.go @@ -8,13 +8,14 @@ import ( "os/exec" "testing" - "code.gitea.io/tea/modules/config" - teacontext "code.gitea.io/tea/modules/context" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/modules/config" + teacontext "gitea.dev/tea/modules/context" ) -func TestInitCommand_WithRepoSlugSkipsLocalRepoDetection(t *testing.T) { +func TestInitCommand_WithRepoSlugKeepsLocalRepoDetection(t *testing.T) { tmpDir := t.TempDir() config.SetConfigForTesting(config.LocalConfig{ Logins: []config.Login{{ @@ -53,7 +54,26 @@ func TestInitCommand_WithRepoSlugSkipsLocalRepoDetection(t *testing.T) { require.Equal(t, "owner", ctx.Owner) require.Equal(t, "repo", ctx.Repo) require.Equal(t, "owner/repo", ctx.RepoSlug) - require.Nil(t, ctx.LocalRepo) + require.NotNil(t, ctx.LocalRepo) + require.NotNil(t, ctx.Login) + require.Equal(t, "test-login", ctx.Login.Name) + + cliCmd = cli.Command{ + Name: "pr", + Flags: []cli.Flag{ + &cli.StringFlag{Name: "repo"}, + &cli.StringFlag{Name: "base"}, + }, + } + require.NoError(t, cliCmd.Set("repo", "owner/repo")) + require.NoError(t, cliCmd.Set("base", "main")) + + ctx, err = teacontext.InitCommand(&cliCmd) + require.NoError(t, err) + require.Equal(t, "repo", ctx.Repo) + require.Equal(t, "owner/repo", ctx.RepoSlug) + require.Equal(t, "main", ctx.String("base")) + require.NotNil(t, ctx.LocalRepo) require.NotNil(t, ctx.Login) require.Equal(t, "test-login", ctx.Login.Name) } diff --git a/tests/integration/git_repo_test.go b/tests/integration/git_repo_test.go index 5dbf9f41..47b0b6e3 100644 --- a/tests/integration/git_repo_test.go +++ b/tests/integration/git_repo_test.go @@ -9,8 +9,9 @@ import ( "path/filepath" "testing" - teagit "code.gitea.io/tea/modules/git" "github.com/stretchr/testify/assert" + + teagit "gitea.dev/tea/modules/git" ) func TestRepoFromPath_Worktree(t *testing.T) { diff --git a/tests/integration/helpers_test.go b/tests/integration/helpers_test.go index 0761ba67..2f131aae 100644 --- a/tests/integration/helpers_test.go +++ b/tests/integration/helpers_test.go @@ -4,16 +4,18 @@ package integration import ( + stdctx "context" "fmt" "os" "path/filepath" "testing" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/modules/config" - "code.gitea.io/tea/modules/task" + gitea "gitea.dev/sdk" "github.com/stretchr/testify/require" + + "gitea.dev/tea/modules/config" + "gitea.dev/tea/modules/task" ) var ( @@ -43,7 +45,7 @@ func TestMain(m *testing.M) { if integrationSetupErr == nil { tokenName := fmt.Sprintf("tea-integration-%d", time.Now().UnixNano()) var token *gitea.AccessToken - token, _, integrationSetupErr = integrationClient.CreateAccessToken(gitea.CreateAccessTokenOption{ + token, _, integrationSetupErr = integrationClient.Users.CreateAccessToken(stdctx.Background(), gitea.CreateAccessTokenOption{ Name: tokenName, Scopes: []gitea.AccessTokenScope{gitea.AccessTokenScopeAll}, }) @@ -58,7 +60,7 @@ func TestMain(m *testing.M) { exitCode := m.Run() if integrationClient != nil && integrationTokenID != 0 { - if _, err := integrationClient.DeleteAccessToken(integrationTokenID); err != nil { + if _, err := integrationClient.Users.DeleteAccessToken(stdctx.Background(), integrationTokenID); err != nil { fmt.Fprintf(os.Stderr, "failed to delete integration token %d: %v\n", integrationTokenID, err) if exitCode == 0 { exitCode = 1 @@ -94,7 +96,7 @@ func createIntegrationLogin(t *testing.T) *config.Login { require.NotEmpty(t, integrationToken, "integration token setup failed") - require.NoError(t, task.CreateLogin("integration", integrationToken, "", "", "", "", "", integrationGiteaURL, "", "", true, false, false, false)) + require.NoError(t, task.CreateLogin(t.Context(), "integration", integrationToken, "", "", "", "", "", integrationGiteaURL, "", "", true, false, false, false)) login, err := config.GetLoginByName("integration") require.NoError(t, err) diff --git a/tests/integration/repos_create_test.go b/tests/integration/repos_create_test.go index c551e113..20dbcf9e 100644 --- a/tests/integration/repos_create_test.go +++ b/tests/integration/repos_create_test.go @@ -4,16 +4,16 @@ package integration import ( - "context" "fmt" "testing" "time" - "code.gitea.io/sdk/gitea" - "code.gitea.io/tea/cmd/repos" + gitea "gitea.dev/sdk" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/urfave/cli/v3" + + "gitea.dev/tea/cmd/repos" ) func TestCreateRepoObjectFormat(t *testing.T) { @@ -64,7 +64,7 @@ func TestCreateRepoObjectFormat(t *testing.T) { args := append([]string{"repos", "create"}, tt.args...) args = append(args, "--login", login.Name) - err := reposCmd.Run(context.Background(), args) + err := reposCmd.Run(t.Context(), args) if tt.wantErr { assert.Error(t, err) if tt.errContains != "" { @@ -75,7 +75,7 @@ func TestCreateRepoObjectFormat(t *testing.T) { require.NoError(t, err) t.Cleanup(func() { - if _, delErr := client.DeleteRepo(login.User, tt.wantOpts.Name); delErr != nil { + if _, delErr := client.Repositories.DeleteRepo(t.Context(), login.User, tt.wantOpts.Name); delErr != nil { t.Logf("failed to delete integration test repo %q: %v", tt.wantOpts.Name, delErr) } }) diff --git a/tests/integration/sshkeys_test.go b/tests/integration/sshkeys_test.go index f6323d32..c59112fa 100644 --- a/tests/integration/sshkeys_test.go +++ b/tests/integration/sshkeys_test.go @@ -4,7 +4,6 @@ package integration import ( - "context" "crypto/ed25519" "crypto/rand" "encoding/base64" @@ -14,8 +13,9 @@ import ( "testing" "time" - "code.gitea.io/sdk/gitea" - sshkeyscmd "code.gitea.io/tea/cmd/sshkeys" + gitea "gitea.dev/sdk" + + sshkeyscmd "gitea.dev/tea/cmd/sshkeys" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -64,14 +64,14 @@ func TestSSHKeyAddAndDelete(t *testing.T) { cmd := sshKeysCmd() client := login.Client() - err := cmd.Run(context.Background(), []string{ + err := cmd.Run(t.Context(), []string{ "ssh-keys", "add", pubKeyFile, "--title", keyTitle, "--login", login.Name, }) require.NoError(t, err) - keys, _, err := client.ListMyPublicKeys(gitea.ListPublicKeysOptions{ + keys, _, err := client.Users.ListMyPublicKeys(t.Context(), gitea.ListPublicKeysOptions{ ListOptions: gitea.ListOptions{Page: -1}, }) require.NoError(t, err) @@ -86,17 +86,17 @@ func TestSSHKeyAddAndDelete(t *testing.T) { require.NotNil(t, addedKey, "added key not found in key list") t.Cleanup(func() { - client.DeletePublicKey(addedKey.ID) //nolint:errcheck + client.Users.DeletePublicKey(t.Context(), addedKey.ID) //nolint:errcheck }) - err = cmd.Run(context.Background(), []string{ + err = cmd.Run(t.Context(), []string{ "ssh-keys", "delete", strconv.FormatInt(addedKey.ID, 10), "--confirm", "--login", login.Name, }) assert.NoError(t, err) - _, resp, err := client.GetPublicKey(addedKey.ID) + _, resp, err := client.Users.GetPublicKey(t.Context(), addedKey.ID) assert.Error(t, err) if assert.NotNil(t, resp) { assert.Equal(t, 404, resp.StatusCode) @@ -107,7 +107,7 @@ func TestSSHKeyList(t *testing.T) { login := createIntegrationLogin(t) cmd := sshKeysCmd() - err := cmd.Run(context.Background(), []string{ + err := cmd.Run(t.Context(), []string{ "ssh-keys", "list", "--login", login.Name, })