mirror of
https://gitea.com/gitea/tea.git
synced 2025-09-02 18:08:30 +02:00
replace flag globals, require context for commands (#291)
introduce TeaContext clean up InitCommand move GetListOptions to TeaContext ensure context for each command so we fail early with a good error message instead of "Error: 404" etc make linter happy Merge branch 'master' into refactor-global-flags move TeaContext & InitCommand to modules/context Merge branch 'master' into refactor-global-flags CI.restart() Merge branch 'master' into refactor-global-flags Merge branch 'master' into refactor-global-flags Co-authored-by: Norwin Roosen <git@nroo.de> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/291 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io> Reviewed-by: 6543 <6543@obermui.de> Co-Authored-By: Norwin <noerw@noreply.gitea.io> Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
@ -5,53 +5,35 @@
|
||||
package flags
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// create global variables for global Flags to simplify
|
||||
// access to the options without requiring cli.Context
|
||||
var (
|
||||
// GlobalLoginValue contain value of --login|-l arg
|
||||
GlobalLoginValue string
|
||||
// GlobalRepoValue contain value of --repo|-r arg
|
||||
GlobalRepoValue string
|
||||
// GlobalOutputValue contain value of --output|-o arg
|
||||
GlobalOutputValue string
|
||||
// GlobalRemoteValue contain value of --remote|-R arg
|
||||
GlobalRemoteValue string
|
||||
)
|
||||
|
||||
// LoginFlag provides flag to specify tea login profile
|
||||
var LoginFlag = cli.StringFlag{
|
||||
Name: "login",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "Use a different Gitea login. Optional",
|
||||
Destination: &GlobalLoginValue,
|
||||
Name: "login",
|
||||
Aliases: []string{"l"},
|
||||
Usage: "Use a different Gitea Login. Optional",
|
||||
}
|
||||
|
||||
// RepoFlag provides flag to specify repository
|
||||
var RepoFlag = cli.StringFlag{
|
||||
Name: "repo",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "Override local repository path or gitea repository slug to interact with. Optional",
|
||||
Destination: &GlobalRepoValue,
|
||||
Name: "repo",
|
||||
Aliases: []string{"r"},
|
||||
Usage: "Override local repository path or gitea repository slug to interact with. Optional",
|
||||
}
|
||||
|
||||
// RemoteFlag provides flag to specify remote repository
|
||||
var RemoteFlag = cli.StringFlag{
|
||||
Name: "remote",
|
||||
Aliases: []string{"R"},
|
||||
Usage: "Discover Gitea login from remote. Optional",
|
||||
Destination: &GlobalRemoteValue,
|
||||
Name: "remote",
|
||||
Aliases: []string{"R"},
|
||||
Usage: "Discover Gitea login from remote. Optional",
|
||||
}
|
||||
|
||||
// OutputFlag provides flag to specify output type
|
||||
var OutputFlag = cli.StringFlag{
|
||||
Name: "output",
|
||||
Aliases: []string{"o"},
|
||||
Usage: "Output format. (csv, simple, table, tsv, yaml)",
|
||||
Destination: &GlobalOutputValue,
|
||||
Name: "output",
|
||||
Aliases: []string{"o"},
|
||||
Usage: "Output format. (csv, simple, table, tsv, yaml)",
|
||||
}
|
||||
|
||||
// StateFlag provides flag to specify issue/pr state, defaulting to "open"
|
||||
@ -109,16 +91,3 @@ var IssuePRFlags = append([]cli.Flag{
|
||||
&PaginationPageFlag,
|
||||
&PaginationLimitFlag,
|
||||
}, AllDefaultFlags...)
|
||||
|
||||
// GetListOptions return ListOptions based on PaginationFlags
|
||||
func GetListOptions(ctx *cli.Context) gitea.ListOptions {
|
||||
page := ctx.Int("page")
|
||||
limit := ctx.Int("limit")
|
||||
if limit != 0 && page == 0 {
|
||||
page = 1
|
||||
}
|
||||
return gitea.ListOptions{
|
||||
Page: page,
|
||||
PageSize: limit,
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package cmd
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/issues"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -33,19 +33,20 @@ var CmdIssues = cli.Command{
|
||||
|
||||
func runIssues(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runIssueDetail(ctx.Args().First())
|
||||
return runIssueDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return issues.RunIssuesList(ctx)
|
||||
}
|
||||
|
||||
func runIssueDetail(index string) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runIssueDetail(cmd *cli.Context, index string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
idx, err := utils.ArgToIndex(index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
issue, _, err := login.Client().GetIssue(owner, repo, idx)
|
||||
issue, _, err := ctx.Login.Client().GetIssue(ctx.Owner, ctx.Repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -30,8 +30,9 @@ var CmdIssuesClose = cli.Command{
|
||||
}
|
||||
|
||||
// editIssueState abstracts the arg parsing to edit the given issue
|
||||
func editIssueState(ctx *cli.Context, opts gitea.EditIssueOption) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func editIssueState(cmd *cli.Context, opts gitea.EditIssueOption) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
if ctx.Args().Len() == 0 {
|
||||
log.Fatal(ctx.Command.ArgsUsage)
|
||||
}
|
||||
@ -41,7 +42,7 @@ func editIssueState(ctx *cli.Context, opts gitea.EditIssueOption) error {
|
||||
return err
|
||||
}
|
||||
|
||||
issue, _, err := login.Client().EditIssue(owner, repo, index, opts)
|
||||
issue, _, err := ctx.Login.Client().EditIssue(ctx.Owner, ctx.Repo, index, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package issues
|
||||
|
||||
import (
|
||||
"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/task"
|
||||
|
||||
@ -33,17 +33,18 @@ var CmdIssuesCreate = cli.Command{
|
||||
}, flags.LoginRepoFlags...),
|
||||
}
|
||||
|
||||
func runIssuesCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runIssuesCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
if ctx.NumFlags() == 0 {
|
||||
return interact.CreateIssue(login, owner, repo)
|
||||
return interact.CreateIssue(ctx.Login, ctx.Owner, ctx.Repo)
|
||||
}
|
||||
|
||||
return task.CreateIssue(
|
||||
login,
|
||||
owner,
|
||||
repo,
|
||||
ctx.Login,
|
||||
ctx.Owner,
|
||||
ctx.Repo,
|
||||
ctx.String("title"),
|
||||
ctx.String("body"),
|
||||
)
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -26,8 +26,9 @@ var CmdIssuesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunIssuesList list issues
|
||||
func RunIssuesList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunIssuesList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
@ -39,8 +40,8 @@ func RunIssuesList(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
issues, _, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
issues, _, err := ctx.Login.Client().ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
State: state,
|
||||
Type: gitea.IssueTypeIssue,
|
||||
})
|
||||
@ -49,6 +50,6 @@ func RunIssuesList(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.IssuesList(issues, flags.GlobalOutputValue)
|
||||
print.IssuesList(issues, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -43,13 +42,14 @@ var CmdLabelCreate = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
labelFile := ctx.String("file")
|
||||
var err error
|
||||
if len(labelFile) == 0 {
|
||||
_, _, err = login.Client().CreateLabel(owner, 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"),
|
||||
@ -69,7 +69,7 @@ func runLabelCreate(ctx *cli.Context) error {
|
||||
if color == "" || name == "" {
|
||||
log.Printf("Line %d ignored because lack of enough fields: %s\n", i, line)
|
||||
} else {
|
||||
_, _, err = login.Client().CreateLabel(owner, repo, gitea.CreateLabelOption{
|
||||
_, _, err = ctx.Login.Client().CreateLabel(ctx.Owner, ctx.Repo, gitea.CreateLabelOption{
|
||||
Name: name,
|
||||
Color: color,
|
||||
Description: description,
|
||||
|
@ -7,8 +7,7 @@ package labels
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -27,10 +26,11 @@ var CmdLabelDelete = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelDelete(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
_, err := login.Client().DeleteLabel(owner, repo, ctx.Int64("id"))
|
||||
_, err := ctx.Login.Client().DeleteLabel(ctx.Owner, ctx.Repo, ctx.Int64("id"))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
|
||||
@ -35,10 +35,14 @@ var CmdLabelsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLabelsList list labels.
|
||||
func RunLabelsList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunLabelsList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
labels, _, err := login.Client().ListRepoLabels(owner, repo, gitea.ListLabelsOptions{ListOptions: flags.GetListOptions(ctx)})
|
||||
client := ctx.Login.Client()
|
||||
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@ -47,6 +51,6 @@ func RunLabelsList(ctx *cli.Context) error {
|
||||
return task.LabelsExport(labels, ctx.String("save"))
|
||||
}
|
||||
|
||||
print.LabelsList(labels, flags.GlobalOutputValue)
|
||||
print.LabelsList(labels, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ package labels
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -40,8 +39,9 @@ var CmdLabelUpdate = cli.Command{
|
||||
},
|
||||
}
|
||||
|
||||
func runLabelUpdate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runLabelUpdate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
id := ctx.Int64("id")
|
||||
var pName, pColor, pDescription *string
|
||||
@ -61,7 +61,7 @@ func runLabelUpdate(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
var err error
|
||||
_, _, err = login.Client().EditLabel(owner, repo, id, gitea.EditLabelOption{
|
||||
_, _, err = ctx.Login.Client().EditLabel(ctx.Owner, ctx.Repo, id, gitea.EditLabelOption{
|
||||
Name: pName,
|
||||
Color: pColor,
|
||||
Description: pDescription,
|
||||
|
@ -7,7 +7,6 @@ package cmd
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/login"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
@ -46,6 +45,6 @@ func runLoginDetail(name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
print.LoginDetails(l, flags.GlobalOutputValue)
|
||||
print.LoginDetails(l)
|
||||
return nil
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ var CmdLoginList = cli.Command{
|
||||
}
|
||||
|
||||
// RunLoginList list all logins
|
||||
func RunLoginList(_ *cli.Context) error {
|
||||
func RunLoginList(cmd *cli.Context) error {
|
||||
logins, err := config.GetLogins()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.LoginsList(logins, flags.GlobalOutputValue)
|
||||
print.LoginsList(logins, cmd.String("output"))
|
||||
return nil
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ package cmd
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/milestones"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -34,16 +34,17 @@ var CmdMilestones = cli.Command{
|
||||
|
||||
func runMilestones(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runMilestoneDetail(ctx.Args().First())
|
||||
return runMilestoneDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return milestones.RunMilestonesList(ctx)
|
||||
}
|
||||
|
||||
func runMilestoneDetail(name string) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runMilestoneDetail(cmd *cli.Context, name string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
milestone, _, err := client.GetMilestoneByName(owner, repo, name)
|
||||
milestone, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -41,8 +41,9 @@ var CmdMilestonesCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runMilestonesCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runMilestonesCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
title := ctx.String("title")
|
||||
if len(title) == 0 {
|
||||
@ -55,7 +56,7 @@ func runMilestonesCreate(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
mile, _, err := login.Client().CreateMilestone(owner, repo, gitea.CreateMilestoneOption{
|
||||
mile, _, err := ctx.Login.Client().CreateMilestone(ctx.Owner, ctx.Repo, gitea.CreateMilestoneOption{
|
||||
Title: title,
|
||||
Description: ctx.String("description"),
|
||||
State: state,
|
||||
|
@ -6,7 +6,7 @@ package milestones
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -22,10 +22,11 @@ var CmdMilestonesDelete = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func deleteMilestone(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func deleteMilestone(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
_, err := client.DeleteMilestoneByName(owner, repo, ctx.Args().First())
|
||||
_, err := client.DeleteMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First())
|
||||
return err
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -65,9 +65,10 @@ var CmdMilestoneRemoveIssue = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runMilestoneIssueList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runMilestoneIssueList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
@ -91,13 +92,13 @@ func runMilestoneIssueList(ctx *cli.Context) error {
|
||||
|
||||
milestone := ctx.Args().First()
|
||||
// make sure milestone exist
|
||||
_, _, err := client.GetMilestoneByName(owner, repo, milestone)
|
||||
_, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, milestone)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
issues, _, err := client.ListRepoIssues(owner, repo, gitea.ListIssueOption{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
issues, _, err := client.ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
@ -106,13 +107,14 @@ func runMilestoneIssueList(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
print.IssuesPullsList(issues, flags.GlobalOutputValue)
|
||||
print.IssuesPullsList(issues, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runMilestoneIssueAdd(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runMilestoneIssueAdd(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
if ctx.Args().Len() != 2 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
}
|
||||
@ -125,20 +127,21 @@ func runMilestoneIssueAdd(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
// make sure milestone exist
|
||||
mile, _, err := client.GetMilestoneByName(owner, repo, mileName)
|
||||
mile, _, err := client.GetMilestoneByName(ctx.Owner, ctx.Repo, mileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, _, err = client.EditIssue(owner, repo, idx, gitea.EditIssueOption{
|
||||
_, _, err = client.EditIssue(ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
|
||||
Milestone: &mile.ID,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func runMilestoneIssueRemove(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runMilestoneIssueRemove(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
if ctx.Args().Len() != 2 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
}
|
||||
@ -150,7 +153,7 @@ func runMilestoneIssueRemove(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
issue, _, err := client.GetIssue(owner, repo, idx)
|
||||
issue, _, err := client.GetIssue(ctx.Owner, ctx.Repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -164,7 +167,7 @@ func runMilestoneIssueRemove(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
zero := int64(0)
|
||||
_, _, err = client.EditIssue(owner, repo, idx, gitea.EditIssueOption{
|
||||
_, _, err = client.EditIssue(ctx.Owner, ctx.Repo, idx, gitea.EditIssueOption{
|
||||
Milestone: &zero,
|
||||
})
|
||||
return err
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -34,8 +34,9 @@ var CmdMilestonesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunMilestonesList list milestones
|
||||
func RunMilestonesList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunMilestonesList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
@ -45,8 +46,9 @@ func RunMilestonesList(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
milestones, _, err := login.Client().ListRepoMilestones(owner, repo, gitea.ListMilestoneOption{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
client := ctx.Login.Client()
|
||||
milestones, _, err := client.ListRepoMilestones(ctx.Owner, ctx.Repo, gitea.ListMilestoneOption{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
State: state,
|
||||
})
|
||||
|
||||
@ -54,6 +56,6 @@ func RunMilestonesList(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.MilestonesList(milestones, flags.GlobalOutputValue, state)
|
||||
print.MilestonesList(milestones, ctx.Output, state)
|
||||
return nil
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package milestones
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -25,15 +25,16 @@ var CmdMilestonesReopen = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func editMilestoneStatus(ctx *cli.Context, close bool) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func editMilestoneStatus(cmd *cli.Context, close bool) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
state := gitea.StateOpen
|
||||
if close {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
_, _, err := client.EditMilestoneByName(owner, repo, ctx.Args().First(), gitea.EditMilestoneOption{
|
||||
_, _, err := client.EditMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First(), gitea.EditMilestoneOption{
|
||||
State: &state,
|
||||
Title: ctx.Args().First(),
|
||||
})
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -43,13 +43,14 @@ var CmdNotifications = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runNotifications(ctx *cli.Context) error {
|
||||
func runNotifications(cmd *cli.Context) error {
|
||||
var news []*gitea.NotificationThread
|
||||
var err error
|
||||
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
listOpts := flags.GetListOptions(ctx)
|
||||
listOpts := ctx.GetListOptions()
|
||||
if listOpts.Page == 0 {
|
||||
listOpts.Page = 1
|
||||
}
|
||||
@ -63,12 +64,13 @@ func runNotifications(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
if ctx.Bool("all") {
|
||||
news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{
|
||||
news, _, err = client.ListNotifications(gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
} else {
|
||||
news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
news, _, err = client.ListRepoNotifications(ctx.Owner, ctx.Repo, gitea.ListNotificationOptions{
|
||||
ListOptions: listOpts,
|
||||
Status: status,
|
||||
})
|
||||
@ -77,6 +79,6 @@ func runNotifications(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.NotificationsList(news, flags.GlobalOutputValue, ctx.Bool("all"))
|
||||
print.NotificationsList(news, ctx.Output, ctx.Bool("all"))
|
||||
return nil
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
local_git "code.gitea.io/tea/modules/git"
|
||||
|
||||
"github.com/skratchdot/open-golang/open"
|
||||
@ -26,8 +26,9 @@ var CmdOpen = cli.Command{
|
||||
Flags: append([]cli.Flag{}, flags.LoginRepoFlags...),
|
||||
}
|
||||
|
||||
func runOpen(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runOpen(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
var suffix string
|
||||
number := ctx.Args().Get(0)
|
||||
@ -73,7 +74,7 @@ func runOpen(ctx *cli.Context) error {
|
||||
suffix = number
|
||||
}
|
||||
|
||||
u := path.Join(login.URL, owner, repo, suffix)
|
||||
u := path.Join(ctx.Login.URL, ctx.RepoSlug, suffix)
|
||||
err := open.Run(u)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -7,8 +7,7 @@ package organizations
|
||||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@ -23,10 +22,10 @@ var CmdOrganizationDelete = cli.Command{
|
||||
}
|
||||
|
||||
// RunOrganizationDelete delete user organization
|
||||
func RunOrganizationDelete(ctx *cli.Context) error {
|
||||
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunOrganizationDelete(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
|
||||
client := login.Client()
|
||||
client := ctx.Login.Client()
|
||||
|
||||
if ctx.Args().Len() < 1 {
|
||||
log.Fatal("You have to specify the organization name you want to delete.")
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -29,17 +29,18 @@ var CmdOrganizationList = cli.Command{
|
||||
}
|
||||
|
||||
// RunOrganizationList list user organizations
|
||||
func RunOrganizationList(ctx *cli.Context) error {
|
||||
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunOrganizationList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
client := login.Client()
|
||||
|
||||
userOrganizations, _, err := client.ListUserOrgs(login.User, gitea.ListOrgsOptions{ListOptions: flags.GetListOptions(ctx)})
|
||||
userOrganizations, _, err := client.ListUserOrgs(ctx.Login.User, gitea.ListOrgsOptions{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.OrganizationsList(userOrganizations, flags.GlobalOutputValue)
|
||||
print.OrganizationsList(userOrganizations, ctx.Output)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
15
cmd/pulls.go
15
cmd/pulls.go
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/pulls"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -36,25 +36,26 @@ var CmdPulls = cli.Command{
|
||||
|
||||
func runPulls(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runPullDetail(ctx.Args().First())
|
||||
return runPullDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return pulls.RunPullsList(ctx)
|
||||
}
|
||||
|
||||
func runPullDetail(index string) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runPullDetail(cmd *cli.Context, index string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
idx, err := utils.ArgToIndex(index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client := login.Client()
|
||||
pr, _, err := client.GetPullRequest(owner, repo, idx)
|
||||
client := ctx.Login.Client()
|
||||
pr, _, err := client.GetPullRequest(ctx.Owner, ctx.Repo, idx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reviews, _, err := client.ListPullReviews(owner, repo, idx, gitea.ListPullReviewsOptions{})
|
||||
reviews, _, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{})
|
||||
if err != nil {
|
||||
fmt.Printf("error while loading reviews: %v\n", err)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"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/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
@ -26,8 +26,9 @@ var CmdPullsCheckout = cli.Command{
|
||||
Flags: flags.AllDefaultFlags,
|
||||
}
|
||||
|
||||
func runPullsCheckout(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runPullsCheckout(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
|
||||
if ctx.Args().Len() != 1 {
|
||||
log.Fatal("Must specify a PR index")
|
||||
}
|
||||
@ -36,5 +37,5 @@ func runPullsCheckout(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return task.PullCheckout(login, owner, repo, idx, interact.PromptPassword)
|
||||
return task.PullCheckout(ctx.Login, ctx.Owner, ctx.Repo, idx, interact.PromptPassword)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"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/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
@ -31,8 +31,9 @@ var CmdPullsClean = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPullsClean(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runPullsClean(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
|
||||
if ctx.Args().Len() != 1 {
|
||||
return fmt.Errorf("Must specify a PR index")
|
||||
}
|
||||
@ -42,5 +43,5 @@ func runPullsClean(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return task.PullClean(login, owner, repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword)
|
||||
return task.PullClean(ctx.Login, ctx.Owner, ctx.Repo, idx, ctx.Bool("ignore-sha"), interact.PromptPassword)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ package pulls
|
||||
|
||||
import (
|
||||
"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/task"
|
||||
|
||||
@ -42,19 +42,20 @@ var CmdPullsCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runPullsCreate(ctx *cli.Context) error {
|
||||
login, ownerArg, repoArg := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runPullsCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{LocalRepo: true})
|
||||
|
||||
// no args -> interactive mode
|
||||
if ctx.NumFlags() == 0 {
|
||||
return interact.CreatePull(login, ownerArg, repoArg)
|
||||
return interact.CreatePull(ctx.Login, ctx.Owner, ctx.Repo)
|
||||
}
|
||||
|
||||
// else use args to create PR
|
||||
return task.CreatePull(
|
||||
login,
|
||||
ownerArg,
|
||||
repoArg,
|
||||
ctx.Login,
|
||||
ctx.Owner,
|
||||
ctx.Repo,
|
||||
ctx.String("base"),
|
||||
ctx.String("head"),
|
||||
ctx.String("title"),
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -26,8 +26,9 @@ var CmdPullsList = cli.Command{
|
||||
}
|
||||
|
||||
// RunPullsList return list of pulls
|
||||
func RunPullsList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunPullsList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
state := gitea.StateOpen
|
||||
switch ctx.String("state") {
|
||||
@ -39,7 +40,7 @@ func RunPullsList(ctx *cli.Context) error {
|
||||
state = gitea.StateClosed
|
||||
}
|
||||
|
||||
prs, _, err := login.Client().ListRepoPullRequests(owner, repo, gitea.ListPullRequestsOptions{
|
||||
prs, _, err := ctx.Login.Client().ListRepoPullRequests(ctx.Owner, ctx.Repo, gitea.ListPullRequestsOptions{
|
||||
State: state,
|
||||
})
|
||||
|
||||
@ -47,6 +48,6 @@ func RunPullsList(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.PullsList(prs, flags.GlobalOutputValue)
|
||||
print.PullsList(prs, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -61,10 +61,11 @@ var CmdReleaseCreate = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseCreate(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runReleaseCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
release, resp, err := login.Client().CreateRelease(owner, repo, gitea.CreateReleaseOption{
|
||||
release, resp, err := ctx.Login.Client().CreateRelease(ctx.Owner, ctx.Repo, gitea.CreateReleaseOption{
|
||||
TagName: ctx.String("tag"),
|
||||
Target: ctx.String("target"),
|
||||
Title: ctx.String("title"),
|
||||
@ -90,7 +91,7 @@ func runReleaseCreate(ctx *cli.Context) error {
|
||||
|
||||
filePath := filepath.Base(asset)
|
||||
|
||||
if _, _, err = login.Client().CreateReleaseAttachment(owner, repo, release.ID, file, filePath); err != nil {
|
||||
if _, _, err = ctx.Login.Client().CreateReleaseAttachment(ctx.Owner, ctx.Repo, release.ID, file, filePath); err != nil {
|
||||
file.Close()
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
@ -33,9 +33,10 @@ var CmdReleaseDelete = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runReleaseDelete(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
tag := ctx.Args().First()
|
||||
if len(tag) == 0 {
|
||||
@ -48,7 +49,7 @@ func runReleaseDelete(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
release, err := getReleaseByTag(owner, repo, tag, client)
|
||||
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -56,13 +57,13 @@ func runReleaseDelete(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = client.DeleteRelease(owner, repo, release.ID)
|
||||
_, err = client.DeleteRelease(ctx.Owner, ctx.Repo, release.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ctx.Bool("delete-tag") {
|
||||
_, err = client.DeleteReleaseTag(owner, repo, tag)
|
||||
_, err = client.DeleteReleaseTag(ctx.Owner, ctx.Repo, tag)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -56,9 +56,10 @@ var CmdReleaseEdit = cli.Command{
|
||||
}, flags.AllDefaultFlags...),
|
||||
}
|
||||
|
||||
func runReleaseEdit(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runReleaseEdit(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
tag := ctx.Args().First()
|
||||
if len(tag) == 0 {
|
||||
@ -66,7 +67,7 @@ func runReleaseEdit(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
release, err := getReleaseByTag(owner, repo, tag, client)
|
||||
release, err := getReleaseByTag(ctx.Owner, ctx.Repo, tag, client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -82,7 +83,7 @@ func runReleaseEdit(ctx *cli.Context) error {
|
||||
isPre = gitea.OptionalBool(strings.ToLower(ctx.String("prerelease"))[:1] == "t")
|
||||
}
|
||||
|
||||
_, _, err = client.EditRelease(owner, repo, release.ID, gitea.EditReleaseOption{
|
||||
_, _, err = client.EditRelease(ctx.Owner, ctx.Repo, release.ID, gitea.EditReleaseOption{
|
||||
TagName: ctx.String("tag"),
|
||||
Target: ctx.String("target"),
|
||||
Title: ctx.String("title"),
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -30,15 +30,18 @@ var CmdReleaseList = cli.Command{
|
||||
}
|
||||
|
||||
// RunReleasesList list releases
|
||||
func RunReleasesList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func RunReleasesList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
releases, _, err := login.Client().ListReleases(owner, repo, gitea.ListReleasesOptions{ListOptions: flags.GetListOptions(ctx)})
|
||||
releases, _, err := ctx.Login.Client().ListReleases(ctx.Owner, ctx.Repo, gitea.ListReleasesOptions{
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print.ReleasesList(releases, flags.GlobalOutputValue)
|
||||
print.ReleasesList(releases, ctx.Output)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
15
cmd/repos.go
15
cmd/repos.go
@ -5,9 +5,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/cmd/repos"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -33,20 +32,20 @@ var CmdRepos = cli.Command{
|
||||
|
||||
func runRepos(ctx *cli.Context) error {
|
||||
if ctx.Args().Len() == 1 {
|
||||
return runRepoDetail(ctx.Args().First())
|
||||
return runRepoDetail(ctx, ctx.Args().First())
|
||||
}
|
||||
return repos.RunReposList(ctx)
|
||||
}
|
||||
|
||||
func runRepoDetail(path string) error {
|
||||
login, ownerFallback, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
repoOwner, repoName := utils.GetOwnerAndRepo(path, ownerFallback)
|
||||
func runRepoDetail(cmd *cli.Context, path string) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
repoOwner, repoName := utils.GetOwnerAndRepo(path, ctx.Owner)
|
||||
repo, _, err := client.GetRepo(repoOwner, repoName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
topics, _, err := client.ListRepoTopics(repo.Owner.UserName, repo.Name, gitea.ListRepoTopicsOptions{})
|
||||
topics, _, err := client.ListRepoTopics(repoOwner, repoName, gitea.ListRepoTopicsOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -82,9 +82,9 @@ var CmdRepoCreate = cli.Command{
|
||||
}, flags.LoginOutputFlags...),
|
||||
}
|
||||
|
||||
func runRepoCreate(ctx *cli.Context) error {
|
||||
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runRepoCreate(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
var (
|
||||
repo *gitea.Repository
|
||||
err error
|
||||
|
@ -6,7 +6,7 @@ package repos
|
||||
|
||||
import (
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -44,11 +44,11 @@ var CmdReposList = cli.Command{
|
||||
}
|
||||
|
||||
// RunReposList list repositories
|
||||
func RunReposList(ctx *cli.Context) error {
|
||||
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func RunReposList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
typeFilter, err := getTypeFilter(ctx)
|
||||
typeFilter, err := getTypeFilter(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -60,14 +60,14 @@ func RunReposList(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
rps, _, err = client.SearchRepos(gitea.SearchRepoOptions{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
StarredByUserID: user.ID,
|
||||
})
|
||||
} else if ctx.Bool("watched") {
|
||||
rps, _, err = client.GetMyWatchedRepos() // TODO: this does not expose pagination..
|
||||
} else {
|
||||
rps, _, err = client.ListMyRepos(gitea.ListReposOptions{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ func RunReposList(ctx *cli.Context) error {
|
||||
reposFiltered = filterReposByType(rps, typeFilter)
|
||||
}
|
||||
|
||||
print.ReposList(reposFiltered, flags.GlobalOutputValue, getFields(ctx))
|
||||
print.ReposList(reposFiltered, ctx.Output, getFields(cmd))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -56,9 +56,9 @@ var CmdReposSearch = cli.Command{
|
||||
}, flags.LoginOutputFlags...),
|
||||
}
|
||||
|
||||
func runReposSearch(ctx *cli.Context) error {
|
||||
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runReposSearch(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
client := ctx.Login.Client()
|
||||
|
||||
var ownerID int64
|
||||
if ctx.IsSet("owner") {
|
||||
@ -93,7 +93,7 @@ func runReposSearch(ctx *cli.Context) error {
|
||||
isPrivate = &private
|
||||
}
|
||||
|
||||
mode, err := getTypeFilter(ctx)
|
||||
mode, err := getTypeFilter(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -109,7 +109,7 @@ func runReposSearch(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
rps, _, err := client.SearchRepos(gitea.SearchRepoOptions{
|
||||
ListOptions: flags.GetListOptions(ctx),
|
||||
ListOptions: ctx.GetListOptions(),
|
||||
OwnerID: ownerID,
|
||||
IsPrivate: isPrivate,
|
||||
IsArchived: isArchived,
|
||||
@ -123,6 +123,6 @@ func runReposSearch(ctx *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
print.ReposList(rps, flags.GlobalOutputValue, getFields(ctx))
|
||||
print.ReposList(rps, ctx.Output, getFields(cmd))
|
||||
return nil
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ var CmdTrackedTimes = cli.Command{
|
||||
Depending on your permissions on the repository, only your own tracked
|
||||
times might be listed.`,
|
||||
ArgsUsage: "[username | #issue]",
|
||||
Action: runTrackedTimes,
|
||||
Action: times.RunTimesList,
|
||||
Subcommands: []*cli.Command{
|
||||
×.CmdTrackedTimesAdd,
|
||||
×.CmdTrackedTimesDelete,
|
||||
@ -26,7 +26,3 @@ var CmdTrackedTimes = cli.Command{
|
||||
×.CmdTrackedTimesList,
|
||||
},
|
||||
}
|
||||
|
||||
func runTrackedTimes(ctx *cli.Context) error {
|
||||
return times.RunTimesList(ctx)
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
@ -31,8 +31,9 @@ var CmdTrackedTimesAdd = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesAdd(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
func runTrackedTimesAdd(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
|
||||
if ctx.Args().Len() < 2 {
|
||||
return fmt.Errorf("No issue or duration specified.\nUsage:\t%s", ctx.Command.UsageText)
|
||||
@ -48,7 +49,7 @@ func runTrackedTimesAdd(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, err = login.Client().AddTime(owner, repo, issue, gitea.AddTimeOption{
|
||||
_, _, err = ctx.Login.Client().AddTime(ctx.Owner, ctx.Repo, issue, gitea.AddTimeOption{
|
||||
Time: int64(duration.Seconds()),
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -26,9 +26,10 @@ var CmdTrackedTimesDelete = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesDelete(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runTrackedTimesDelete(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
if ctx.Args().Len() < 2 {
|
||||
return fmt.Errorf("No issue or time ID specified.\nUsage:\t%s", ctx.Command.UsageText)
|
||||
@ -44,7 +45,7 @@ func runTrackedTimesDelete(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = client.DeleteTime(owner, repo, issue, timeID)
|
||||
_, err = client.DeleteTime(ctx.Owner, ctx.Repo, issue, timeID)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/print"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
@ -50,9 +50,10 @@ var CmdTrackedTimesList = cli.Command{
|
||||
}
|
||||
|
||||
// RunTimesList list repositories
|
||||
func RunTimesList(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func RunTimesList(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
var times []*gitea.TrackedTime
|
||||
var err error
|
||||
@ -61,17 +62,17 @@ func RunTimesList(ctx *cli.Context) error {
|
||||
fmt.Println(ctx.Command.ArgsUsage)
|
||||
if user == "" {
|
||||
// get all tracked times on the repo
|
||||
times, _, err = client.GetRepoTrackedTimes(owner, repo)
|
||||
times, _, err = client.GetRepoTrackedTimes(ctx.Owner, ctx.Repo)
|
||||
} else if strings.HasPrefix(user, "#") {
|
||||
// get all tracked times on the specified issue
|
||||
issue, err := utils.ArgToIndex(user)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
times, _, err = client.ListTrackedTimes(owner, repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
times, _, err = client.ListTrackedTimes(ctx.Owner, ctx.Repo, issue, gitea.ListTrackedTimesOptions{})
|
||||
} else {
|
||||
// get all tracked times by the specified user
|
||||
times, _, err = client.GetUserTrackedTimes(owner, repo, user)
|
||||
times, _, err = client.GetUserTrackedTimes(ctx.Owner, ctx.Repo, user)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -92,6 +93,6 @@ func RunTimesList(ctx *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
print.TrackedTimesList(times, flags.GlobalOutputValue, from, until, ctx.Bool("total"))
|
||||
print.TrackedTimesList(times, ctx.Output, from, until, ctx.Bool("total"))
|
||||
return nil
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/cmd/flags"
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -25,9 +25,10 @@ var CmdTrackedTimesReset = cli.Command{
|
||||
Flags: flags.LoginRepoFlags,
|
||||
}
|
||||
|
||||
func runTrackedTimesReset(ctx *cli.Context) error {
|
||||
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
|
||||
client := login.Client()
|
||||
func runTrackedTimesReset(cmd *cli.Context) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
client := ctx.Login.Client()
|
||||
|
||||
if ctx.Args().Len() != 1 {
|
||||
return fmt.Errorf("No issue specified.\nUsage:\t%s", ctx.Command.UsageText)
|
||||
@ -38,7 +39,7 @@ func runTrackedTimesReset(ctx *cli.Context) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = client.ResetIssueTime(owner, repo, issue)
|
||||
_, err = client.ResetIssueTime(ctx.Owner, ctx.Repo, issue)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user