Code Cleanup (#869)

- switch to golangci-lint for linting
- switch to gofmpt for formatting
- fix lint and fmt issues that came up from switch to new tools
- upgrade go-sdk to 0.23.2
- support pagination for listing tracked times
- remove `FixPullHeadSha` workaround (upstream fix has been merged for 5+ years at this point)
- standardize on US spelling (previously a mix of US&UK spelling)
- remove some unused code
- reduce some duplication in parsing state and issue type
- reduce some duplication in reading input for secrets and variables
- reduce some duplication with PR Review code
- report error for when yaml parsing fails
- various other misc cleanup

Reviewed-on: https://gitea.com/gitea/tea/pulls/869
Co-authored-by: techknowlogick <techknowlogick@gitea.com>
Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:
techknowlogick
2026-02-02 22:39:26 +00:00
committed by techknowlogick
parent ae740a66e8
commit 20da414145
62 changed files with 399 additions and 356 deletions

View File

@@ -6,17 +6,13 @@ package secrets
import (
stdctx "context"
"fmt"
"io"
"os"
"strings"
"syscall"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v3"
"golang.org/x/term"
)
// CmdSecretsCreate represents a sub command to create action secrets
@@ -48,42 +44,19 @@ func runSecretsCreate(ctx stdctx.Context, cmd *cli.Command) error {
client := c.Login.Client()
secretName := cmd.Args().First()
var secretValue string
// Determine how to get the secret value
if cmd.String("file") != "" {
// Read from file
content, err := os.ReadFile(cmd.String("file"))
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
secretValue = strings.TrimSpace(string(content))
} else if cmd.Bool("stdin") {
// Read from stdin
content, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("failed to read from stdin: %w", err)
}
secretValue = strings.TrimSpace(string(content))
} else if cmd.Args().Len() >= 2 {
// Use provided argument
secretValue = cmd.Args().Get(1)
} else {
// Interactive prompt (hidden input)
fmt.Printf("Enter secret value for '%s': ", secretName)
byteValue, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
return fmt.Errorf("failed to read secret value: %w", err)
}
fmt.Println() // Add newline after hidden input
secretValue = string(byteValue)
// Read secret value using the utility
secretValue, err := utils.ReadValue(cmd, utils.ReadValueOptions{
ResourceName: "secret",
PromptMsg: fmt.Sprintf("Enter secret value for '%s'", secretName),
Hidden: true,
AllowEmpty: false,
})
if err != nil {
return err
}
if secretValue == "" {
return fmt.Errorf("secret value cannot be empty")
}
_, err := client.CreateRepoActionSecret(c.Owner, c.Repo, gitea.CreateSecretOption{
_, err = client.CreateRepoActionSecret(c.Owner, c.Repo, gitea.CreateSecretOption{
Name: secretName,
Data: secretValue,
})

View File

@@ -45,7 +45,7 @@ func runSecretsDelete(ctx stdctx.Context, cmd *cli.Command) error {
var response string
fmt.Scanln(&response)
if response != "y" && response != "Y" && response != "yes" {
fmt.Println("Deletion cancelled.")
fmt.Println("Deletion canceled.")
return nil
}
}

View File

@@ -45,7 +45,7 @@ func runVariablesDelete(ctx stdctx.Context, cmd *cli.Command) error {
var response string
fmt.Scanln(&response)
if response != "y" && response != "Y" && response != "yes" {
fmt.Println("Deletion cancelled.")
fmt.Println("Deletion canceled.")
return nil
}
}

View File

@@ -6,13 +6,11 @@ package variables
import (
stdctx "context"
"fmt"
"io"
"os"
"regexp"
"strings"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/utils"
"github.com/urfave/cli/v3"
)
@@ -46,39 +44,26 @@ func runVariablesSet(ctx stdctx.Context, cmd *cli.Command) error {
client := c.Login.Client()
variableName := cmd.Args().First()
var variableValue string
// Determine how to get the variable value
if cmd.String("file") != "" {
// Read from file
content, err := os.ReadFile(cmd.String("file"))
if err != nil {
return fmt.Errorf("failed to read file: %w", err)
}
variableValue = strings.TrimSpace(string(content))
} else if cmd.Bool("stdin") {
// Read from stdin
content, err := io.ReadAll(os.Stdin)
if err != nil {
return fmt.Errorf("failed to read from stdin: %w", err)
}
variableValue = strings.TrimSpace(string(content))
} else if cmd.Args().Len() >= 2 {
// Use provided argument
variableValue = cmd.Args().Get(1)
} else {
// Interactive prompt
fmt.Printf("Enter variable value for '%s': ", variableName)
var input string
fmt.Scanln(&input)
variableValue = input
if err := validateVariableName(variableName); err != nil {
return err
}
if variableValue == "" {
return fmt.Errorf("variable value cannot be empty")
// Read variable value using the utility
variableValue, err := utils.ReadValue(cmd, utils.ReadValueOptions{
ResourceName: "variable",
PromptMsg: fmt.Sprintf("Enter variable value for '%s'", variableName),
Hidden: false,
AllowEmpty: false,
})
if err != nil {
return err
}
_, err := client.CreateRepoActionVariable(c.Owner, c.Repo, variableName, variableValue)
if err := validateVariableValue(variableValue); err != nil {
return err
}
_, err = client.CreateRepoActionVariable(c.Owner, c.Repo, variableName, variableValue)
if err != nil {
return err
}

View File

@@ -81,21 +81,3 @@ func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
return nil
}
func getReleaseAttachmentByName(owner, repo string, release int64, name string, client *gitea.Client) (*gitea.Attachment, error) {
al, _, err := client.ListReleaseAttachments(owner, repo, release, gitea.ListReleaseAttachmentsOptions{
ListOptions: gitea.ListOptions{Page: -1},
})
if err != nil {
return nil, err
}
if len(al) == 0 {
return nil, fmt.Errorf("Release does not have any attachments")
}
for _, a := range al {
if a.Name == name {
return a, nil
}
}
return nil, fmt.Errorf("Attachment does not exist")
}

View File

@@ -52,7 +52,6 @@ func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
branches, _, err = ctx.Login.Client().ListRepoBranches(owner, ctx.Repo, gitea.ListRepoBranchesOptions{
ListOptions: flags.GetListOptions(),
})
if err != nil {
return err
}
@@ -60,7 +59,6 @@ func RunBranchesList(_ stdctx.Context, cmd *cli.Command) error {
protections, _, err = ctx.Login.Client().ListBranchProtections(owner, ctx.Repo, gitea.ListBranchProtectionsOptions{
ListOptions: flags.GetListOptions(),
})
if err != nil {
return err
}

View File

@@ -58,7 +58,7 @@ func runRepoClone(ctx stdctx.Context, cmd *cli.Command) error {
var (
login *config.Login = teaCmd.Login
owner string = teaCmd.Login.User
owner string
repo string
)

View File

@@ -141,3 +141,34 @@ var NotificationStateFlag = NewCsvFlag(
func FieldsFlag(availableFields, defaultFields []string) *CsvFlag {
return NewCsvFlag("fields", "fields to print", []string{"f"}, availableFields, defaultFields)
}
// ParseState parses a state string and returns the corresponding gitea.StateType
func ParseState(stateStr string) (gitea.StateType, error) {
switch stateStr {
case "all":
return gitea.StateAll, nil
case "", "open":
return gitea.StateOpen, nil
case "closed":
return gitea.StateClosed, nil
default:
return "", errors.New("unknown state '" + stateStr + "'")
}
}
// ParseIssueKind parses a kind string and returns the corresponding gitea.IssueType.
// If kindStr is empty, returns the provided defaultKind.
func ParseIssueKind(kindStr string, defaultKind gitea.IssueType) (gitea.IssueType, error) {
switch kindStr {
case "":
return defaultKind, nil
case "all":
return gitea.IssueTypeAll, nil
case "issue", "issues":
return gitea.IssueTypeIssue, nil
case "pull", "pulls", "pr":
return gitea.IssueTypePull, nil
default:
return "", errors.New("unknown kind '" + kindStr + "'")
}
}

View File

@@ -55,7 +55,7 @@ func TestPaginationFlags(t *testing.T) {
expectedPage: 2,
expectedLimit: 20,
},
{ //TODO: Should no paging be applied as -1 or a separate flag? It's not obvious that page=-1 turns off paging and limit is ignored
{ // TODO: Should no paging be applied as -1 or a separate flag? It's not obvious that page=-1 turns off paging and limit is ignored
name: "no paging",
args: []string{"test", "--limit", "20", "--page", "-1"},
expectedPage: -1,
@@ -78,8 +78,8 @@ func TestPaginationFlags(t *testing.T) {
require.NoError(t, err)
})
}
}
func TestPaginationFailures(t *testing.T) {
cases := []struct {
name string
@@ -102,7 +102,7 @@ func TestPaginationFailures(t *testing.T) {
expectedError: ErrPage,
},
{
//urfave does not validate all flags in one pass
// urfave does not validate all flags in one pass
name: "negative paging and paging",
args: []string{"test", "--page", "-2", "--limit", "-10"},
expectedError: ErrPage,

View File

@@ -5,7 +5,6 @@ package issues
import (
stdctx "context"
"errors"
"fmt"
"code.gitea.io/tea/cmd/flags"
@@ -35,7 +34,7 @@ func editIssueState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditIssueOpti
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {
return errors.New(ctx.Command.ArgsUsage)
return fmt.Errorf("missing required argument: %s", ctx.Command.ArgsUsage)
}
indices, err := utils.ArgsToIndices(ctx.Args().Slice())

View File

@@ -29,7 +29,7 @@ func runIssuesCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.NumFlags() == 0 {
if ctx.IsInteractiveMode() {
err := interact.CreateIssue(ctx.Login, ctx.Owner, ctx.Repo)
if err != nil && !interact.IsQuitting(err) {
return err

View File

@@ -49,7 +49,7 @@ func runIssuesEdit(_ stdctx.Context, cmd *cli.Command) error {
client := ctx.Login.Client()
for _, opts.Index = range indices {
if ctx.NumFlags() == 0 {
if ctx.IsInteractiveMode() {
var err error
opts, err = interact.EditIssue(*ctx, opts.Index)
if err != nil {

View File

@@ -5,7 +5,6 @@ package issues
import (
stdctx "context"
"fmt"
"time"
"code.gitea.io/tea/cmd/flags"
@@ -36,31 +35,16 @@ var CmdIssuesList = cli.Command{
func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
state := gitea.StateOpen
switch ctx.String("state") {
case "all":
state = gitea.StateAll
case "", "open":
state = gitea.StateOpen
case "closed":
state = gitea.StateClosed
default:
return fmt.Errorf("unknown state '%s'", ctx.String("state"))
state, err := flags.ParseState(ctx.String("state"))
if err != nil {
return err
}
kind := gitea.IssueTypeIssue
switch ctx.String("kind") {
case "", "issues", "issue":
kind = gitea.IssueTypeIssue
case "pulls", "pull", "pr":
kind = gitea.IssueTypePull
case "all":
kind = gitea.IssueTypeAll
default:
return fmt.Errorf("unknown kind '%s'", ctx.String("kind"))
kind, err := flags.ParseIssueKind(ctx.String("kind"), gitea.IssueTypeIssue)
if err != nil {
return err
}
var err error
var from, until time.Time
if ctx.IsSet("from") {
from, err = dateparse.ParseLocal(ctx.String("from"))
@@ -97,7 +81,6 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
Since: from,
Before: until,
})
if err != nil {
return err
}
@@ -116,7 +99,6 @@ func RunIssuesList(_ stdctx.Context, cmd *cli.Command) error {
Before: until,
Owner: owner,
})
if err != nil {
return err
}

View File

@@ -20,7 +20,7 @@ var CmdIssuesReopen = cli.Command{
Description: `Change state of one or more issues to 'open'`,
ArgsUsage: "<issue index> [<issue index>...]",
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateOpen
s := gitea.StateOpen
return editIssueState(ctx, cmd, gitea.EditIssueOption{State: &s})
},
Flags: flags.AllDefaultFlags,

View File

@@ -26,7 +26,7 @@ const (
)
func createTestIssue(comments int, isClosed bool) gitea.Issue {
var issue = gitea.Issue{
issue := gitea.Issue{
ID: 42,
Index: 1,
Title: "Test issue",
@@ -55,11 +55,11 @@ func createTestIssue(comments int, isClosed bool) gitea.Issue {
{UserName: "testUser3"},
},
HTMLURL: "<space holder>",
Closed: nil, //2025-11-10T21:20:19Z
Closed: nil, // 2025-11-10T21:20:19Z
}
if isClosed {
var closed = time.Date(2025, 11, 10, 21, 20, 19, 0, time.UTC)
closed := time.Date(2025, 11, 10, 21, 20, 19, 0, time.UTC)
issue.Closed = &closed
}
@@ -70,7 +70,6 @@ func createTestIssue(comments int, isClosed bool) gitea.Issue {
}
return issue
}
func createTestIssueComments(comments int) []gitea.Comment {
@@ -90,7 +89,6 @@ func createTestIssueComments(comments int) []gitea.Comment {
}
return result
}
func TestRunIssueDetailAsJSON(t *testing.T) {
@@ -99,9 +97,6 @@ func TestRunIssueDetailAsJSON(t *testing.T) {
issue gitea.Issue
comments []gitea.Comment
flagComments bool
flagOutput string
flagOut string
closed bool
}
cmd := cli.Command{
@@ -205,7 +200,7 @@ func TestRunIssueDetailAsJSON(t *testing.T) {
require.NotEmpty(t, out, "Unexpected empty output from runIssueDetailAsJSON")
//setting expectations
// setting expectations
var expectedLabels []labelData
expectedLabels = []labelData{}
@@ -266,5 +261,4 @@ func TestRunIssueDetailAsJSON(t *testing.T) {
assert.Equal(t, expected, actual, "Expected structs differ from expected one")
})
}
}

View File

@@ -50,40 +50,43 @@ func runLabelCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
labelFile := ctx.String("file")
var err error
if len(labelFile) == 0 {
_, _, err = ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
_, _, err := ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
Name: ctx.String("name"),
Color: ctx.String("color"),
Description: ctx.String("description"),
})
} else {
f, err := os.Open(labelFile)
if err != nil {
return err
}
defer f.Close()
scanner := bufio.NewScanner(f)
var i = 1
for scanner.Scan() {
line := scanner.Text()
color, name, description := splitLabelLine(line)
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{
Name: name,
Color: color,
Description: description,
})
}
i++
}
return err
}
return err
f, err := os.Open(labelFile)
if err != nil {
return err
}
defer f.Close()
scanner := bufio.NewScanner(f)
i := 1
for scanner.Scan() {
line := scanner.Text()
color, name, description := splitLabelLine(line)
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{
Name: name,
Color: color,
Description: description,
})
if err != nil {
return err
}
}
i++
}
return nil
}
func splitLabelLine(line string) (string, string, string) {

View File

@@ -20,7 +20,7 @@ func TestParseLabelLine(t *testing.T) {
`
scanner := bufio.NewScanner(strings.NewReader(labels))
var i = 1
i := 1
for scanner.Scan() {
line := scanner.Text()
color, name, description := splitLabelLine(line)

View File

@@ -67,7 +67,6 @@ func runLabelUpdate(_ stdctx.Context, cmd *cli.Command) error {
Color: pColor,
Description: pDescription,
})
if err != nil {
return err
}

View File

@@ -67,7 +67,7 @@ func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
state = gitea.StateClosed
}
if ctx.NumFlags() == 0 {
if ctx.IsInteractiveMode() {
if err := interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo); err != nil && !interact.IsQuitting(err) {
return err
}

View File

@@ -75,29 +75,23 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
client := ctx.Login.Client()
state := gitea.StateOpen
switch ctx.String("state") {
case "all":
state = gitea.StateAll
case "closed":
state = gitea.StateClosed
state, err := flags.ParseState(ctx.String("state"))
if err != nil {
return err
}
kind := gitea.IssueTypeAll
switch ctx.String("kind") {
case "issue":
kind = gitea.IssueTypeIssue
case "pull":
kind = gitea.IssueTypePull
kind, err := flags.ParseIssueKind(ctx.String("kind"), gitea.IssueTypeAll)
if err != nil {
return err
}
if ctx.Args().Len() != 1 {
return fmt.Errorf("Must specify milestone name")
return fmt.Errorf("milestone name is required")
}
milestone := ctx.Args().First()
// make sure milestone exist
_, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestone)
_, _, err = client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestone)
if err != nil {
return err
}

View File

@@ -48,15 +48,12 @@ func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
return err
}
state := gitea.StateOpen
switch ctx.String("state") {
case "all":
state = gitea.StateAll
if !cmd.IsSet("fields") { // add to default fields
fields = append(fields, "state")
}
case "closed":
state = gitea.StateClosed
state, err := flags.ParseState(ctx.String("state"))
if err != nil {
return err
}
if state == gitea.StateAll && !cmd.IsSet("fields") {
fields = append(fields, "state")
}
client := ctx.Login.Client()
@@ -64,7 +61,6 @@ func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
ListOptions: flags.GetListOptions(),
State: state,
})
if err != nil {
return err
}

View File

@@ -5,7 +5,6 @@ package milestones
import (
stdctx "context"
"errors"
"fmt"
"code.gitea.io/tea/cmd/flags"
@@ -33,7 +32,7 @@ func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {
return errors.New(ctx.Command.ArgsUsage)
return fmt.Errorf("missing required argument: %s", ctx.Command.ArgsUsage)
}
state := gitea.StateOpen

View File

@@ -56,7 +56,7 @@ func RunOrganizationCreate(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
if ctx.Args().Len() < 1 {
return fmt.Errorf("You have to specify the organization name you want to create")
return fmt.Errorf("organization name is required")
}
var visibility gitea.VisibleType

View File

@@ -33,7 +33,7 @@ func RunOrganizationDelete(_ stdctx.Context, cmd *cli.Command) error {
client := ctx.Login.Client()
if ctx.Args().Len() < 1 {
return fmt.Errorf("You have to specify the organization name you want to delete")
return fmt.Errorf("organization name is required")
}
response, err := client.DeleteOrg(ctx.Args().First())

View File

@@ -12,7 +12,6 @@ import (
"code.gitea.io/tea/modules/interact"
"code.gitea.io/tea/modules/print"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/tea/modules/workaround"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v3"
@@ -67,9 +66,6 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
if err != nil {
return err
}
if err := workaround.FixPullHeadSha(client, pr); err != nil {
return err
}
reviews, _, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
ListOptions: gitea.ListOptions{Page: -1},

View File

@@ -4,16 +4,11 @@
package pulls
import (
"fmt"
"strings"
stdctx "context"
"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"
"github.com/urfave/cli/v3"
)
@@ -26,20 +21,7 @@ var CmdPullsApprove = cli.Command{
ArgsUsage: "<pull index> [<comment>]",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {
return fmt.Errorf("Must specify a PR index")
}
idx, err := utils.ArgToIndex(ctx.Args().First())
if err != nil {
return err
}
comment := strings.Join(ctx.Args().Tail(), " ")
return task.CreatePullReview(ctx, idx, gitea.ReviewStateApproved, comment, nil)
return runPullReview(ctx, gitea.ReviewStateApproved, false)
},
Flags: flags.AllDefaultFlags,
}

View File

@@ -40,7 +40,7 @@ func runPullsCheckout(_ stdctx.Context, cmd *cli.Command) error {
RemoteRepo: true,
})
if ctx.Args().Len() != 1 {
return fmt.Errorf("Must specify a PR index")
return fmt.Errorf("pull request index is required")
}
idx, err := utils.ArgToIndex(ctx.Args().First())
if err != nil {

View File

@@ -35,7 +35,7 @@ func runPullsClean(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
if ctx.Args().Len() != 1 {
return fmt.Errorf("Must specify a PR index")
return fmt.Errorf("pull request index is required")
}
idx, err := utils.ArgToIndex(ctx.Args().First())

View File

@@ -19,7 +19,7 @@ var CmdPullsClose = cli.Command{
Description: `Change state of one or more pull requests to 'closed'`,
ArgsUsage: "<pull index> [<pull index>...]",
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateClosed
s := gitea.StateClosed
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
},
Flags: flags.AllDefaultFlags,

View File

@@ -48,7 +48,7 @@ func runPullsCreate(_ stdctx.Context, cmd *cli.Command) error {
})
// no args -> interactive mode
if ctx.NumFlags() == 0 {
if ctx.IsInteractiveMode() {
if err := interact.CreatePull(ctx); err != nil && !interact.IsQuitting(err) {
return err
}

View File

@@ -20,7 +20,7 @@ func editPullState(_ stdctx.Context, cmd *cli.Command, opts gitea.EditPullReques
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() == 0 {
return fmt.Errorf("Please provide a Pull Request index")
return fmt.Errorf("pull request index is required")
}
indices, err := utils.ArgsToIndices(ctx.Args().Slice())

View File

@@ -33,21 +33,15 @@ func RunPullsList(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
state := gitea.StateOpen
switch ctx.String("state") {
case "all":
state = gitea.StateAll
case "open":
state = gitea.StateOpen
case "closed":
state = gitea.StateClosed
state, err := flags.ParseState(ctx.String("state"))
if err != nil {
return err
}
prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
ListOptions: flags.GetListOptions(),
State: state,
})
if err != nil {
return err
}

View File

@@ -5,15 +5,10 @@ package pulls
import (
stdctx "context"
"fmt"
"strings"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/cmd/flags"
"code.gitea.io/tea/modules/context"
"github.com/urfave/cli/v3"
)
@@ -25,20 +20,7 @@ var CmdPullsReject = cli.Command{
ArgsUsage: "<pull index> <reason>",
Action: func(_ stdctx.Context, cmd *cli.Command) error {
ctx := context.InitCommand(cmd)
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
if ctx.Args().Len() < 2 {
return fmt.Errorf("Must specify a PR index and comment")
}
idx, err := utils.ArgToIndex(ctx.Args().First())
if err != nil {
return err
}
comment := strings.Join(ctx.Args().Tail(), " ")
return task.CreatePullReview(ctx, idx, gitea.ReviewStateRequestChanges, comment, nil)
return runPullReview(ctx, gitea.ReviewStateRequestChanges, true)
},
Flags: flags.AllDefaultFlags,
}

View File

@@ -20,7 +20,7 @@ var CmdPullsReopen = cli.Command{
Description: `Change state of one or more pull requests to 'open'`,
ArgsUsage: "<pull index> [<pull index>...]",
Action: func(ctx context.Context, cmd *cli.Command) error {
var s = gitea.StateOpen
s := gitea.StateOpen
return editPullState(ctx, cmd, gitea.EditPullRequestOption{State: &s})
},
Flags: flags.AllDefaultFlags,

View File

@@ -0,0 +1,40 @@
// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package pulls
import (
"fmt"
"strings"
"code.gitea.io/sdk/gitea"
"code.gitea.io/tea/modules/context"
"code.gitea.io/tea/modules/task"
"code.gitea.io/tea/modules/utils"
)
// runPullReview handles the common logic for approving/rejecting pull requests
func runPullReview(ctx *context.TeaContext, state gitea.ReviewStateType, requireComment bool) error {
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
minArgs := 1
if requireComment {
minArgs = 2
}
if ctx.Args().Len() < minArgs {
if requireComment {
return fmt.Errorf("pull request index and comment are required")
}
return fmt.Errorf("pull request index is required")
}
idx, err := utils.ArgToIndex(ctx.Args().First())
if err != nil {
return err
}
comment := strings.Join(ctx.Args().Tail(), " ")
return task.CreatePullReview(ctx, idx, state, comment, nil)
}

View File

@@ -68,16 +68,23 @@ func RunReposList(_ stdctx.Context, cmd *cli.Command) error {
ListOptions: flags.GetListOptions(),
StarredByUserID: user.ID,
})
if err != nil {
return err
}
} else if teaCmd.Bool("watched") {
var err error
rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination..
if err != nil {
return err
}
} else {
var err error
rps, _, err = client.ListMyRepos(gitea.ListReposOptions{
ListOptions: flags.GetListOptions(),
})
}
if err != nil {
return err
if err != nil {
return err
}
}
reposFiltered := rps

View File

@@ -157,7 +157,6 @@ func runRepoMigrate(_ stdctx.Context, cmd *cli.Command) error {
}
repo, _, err = client.MigrateRepo(opts)
if err != nil {
return err
}

View File

@@ -62,7 +62,7 @@ func runReposSearch(_ stdctx.Context, cmd *cli.Command) error {
var ownerID int64
if teaCmd.IsSet("owner") {
// test if owner is a organisation
// test if owner is an organization
org, _, err := client.GetOrg(teaCmd.String("owner"))
if err != nil {
// HACK: the client does not return a response on 404, so we can't check res.StatusCode

View File

@@ -65,6 +65,8 @@ Depending on your permissions on the repository, only your own tracked times mig
Usage: "Show all times tracked by you across all repositories (overrides command arguments)",
},
timeFieldsFlag,
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
}, flags.AllDefaultFlags...),
}
@@ -92,11 +94,15 @@ func RunTimesList(_ stdctx.Context, cmd *cli.Command) error {
}
}
opts := gitea.ListTrackedTimesOptions{Since: from, Before: until}
opts := gitea.ListTrackedTimesOptions{
ListOptions: flags.GetListOptions(),
Since: from,
Before: until,
}
user := ctx.Args().First()
if ctx.Bool("mine") {
times, _, err = client.GetMyTrackedTimes()
times, _, err = client.ListMyTrackedTimes(opts)
fields = []string{"created", "repo", "issue", "duration"}
} else if user == "" {
// get all tracked times on the repo
@@ -104,9 +110,9 @@ func RunTimesList(_ stdctx.Context, cmd *cli.Command) error {
fields = []string{"created", "issue", "user", "duration"}
} else if strings.HasPrefix(user, "#") {
// get all tracked times on the specified issue
issue, err := utils.ArgToIndex(user)
if err != nil {
return err
issue, parseErr := utils.ArgToIndex(user)
if parseErr != nil {
return parseErr
}
times, _, err = client.ListIssueTrackedTimes(ctx.Owner, ctx.Repo, issue, opts)
fields = []string{"created", "user", "duration"}

View File

@@ -63,7 +63,7 @@ func runWebhooksDelete(ctx stdctx.Context, cmd *cli.Command) error {
var response string
fmt.Scanln(&response)
if response != "y" && response != "Y" && response != "yes" {
fmt.Println("Deletion cancelled.")
fmt.Println("Deletion canceled.")
return nil
}
}

View File

@@ -435,9 +435,9 @@ func TestDeleteSuccessMessage(t *testing.T) {
}
func TestDeleteCancellationMessage(t *testing.T) {
expectedMessage := "Deletion cancelled."
expectedMessage := "Deletion canceled."
assert.NotEmpty(t, expectedMessage)
assert.Contains(t, expectedMessage, "cancelled")
assert.Contains(t, expectedMessage, "canceled")
assert.NotContains(t, expectedMessage, "\n", "Cancellation message should not end with newline")
}