mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-05 16:03:32 +02:00
replace log.Fatal/os.Exit with error returns (#941)
* Use stdlib encoders * Reduce some duplication * Remove global pagination state * Dedupe JSON detail types * Bump golangci-lint Reviewed-on: https://gitea.com/gitea/tea/pulls/941 Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
This commit is contained in:
committed by
techknowlogick
parent
21881525a8
commit
b05e03416b
@@ -50,7 +50,10 @@ var CmdMilestonesCreate = cli.Command{
|
||||
}
|
||||
|
||||
func runMilestonesCreate(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
date := ctx.String("deadline")
|
||||
deadline := &time.Time{}
|
||||
|
||||
@@ -24,10 +24,15 @@ var CmdMilestonesDelete = cli.Command{
|
||||
}
|
||||
|
||||
func deleteMilestone(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
client := ctx.Login.Client()
|
||||
|
||||
_, err := client.DeleteMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First())
|
||||
_, err = client.DeleteMilestoneByName(ctx.Owner, ctx.Repo, ctx.Args().First())
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -71,8 +71,13 @@ var CmdMilestoneRemoveIssue = cli.Command{
|
||||
}
|
||||
|
||||
func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
client := ctx.Login.Client()
|
||||
|
||||
state, err := flags.ParseState(ctx.String("state"))
|
||||
@@ -97,7 +102,7 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
issues, _, err := client.ListRepoIssues(ctx.Owner, ctx.Repo, gitea.ListIssueOption{
|
||||
ListOptions: flags.GetListOptions(),
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
Milestones: []string{milestone},
|
||||
Type: kind,
|
||||
State: state,
|
||||
@@ -110,13 +115,17 @@ func runMilestoneIssueList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
print.IssuesPullsList(issues, ctx.Output, fields)
|
||||
return nil
|
||||
return print.IssuesPullsList(issues, ctx.Output, fields)
|
||||
}
|
||||
|
||||
func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
client := ctx.Login.Client()
|
||||
if ctx.Args().Len() != 2 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
@@ -145,8 +154,13 @@ func runMilestoneIssueAdd(_ stdctx.Context, cmd *cli.Command) error {
|
||||
}
|
||||
|
||||
func runMilestoneIssueRemove(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
client := ctx.Login.Client()
|
||||
if ctx.Args().Len() != 2 {
|
||||
return fmt.Errorf("need two arguments")
|
||||
|
||||
@@ -40,8 +40,13 @@ var CmdMilestonesList = cli.Command{
|
||||
|
||||
// RunMilestonesList list milestones
|
||||
func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fields, err := fieldsFlag.GetValues(cmd)
|
||||
if err != nil {
|
||||
@@ -58,13 +63,12 @@ func RunMilestonesList(_ stdctx.Context, cmd *cli.Command) error {
|
||||
|
||||
client := ctx.Login.Client()
|
||||
milestones, _, err := client.ListRepoMilestones(ctx.Owner, ctx.Repo, gitea.ListMilestoneOption{
|
||||
ListOptions: flags.GetListOptions(),
|
||||
ListOptions: flags.GetListOptions(cmd),
|
||||
State: state,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
print.MilestonesList(milestones, ctx.Output, fields)
|
||||
return nil
|
||||
return print.MilestonesList(milestones, ctx.Output, fields)
|
||||
}
|
||||
|
||||
@@ -29,8 +29,13 @@ var CmdMilestonesReopen = cli.Command{
|
||||
}
|
||||
|
||||
func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
|
||||
ctx := context.InitCommand(cmd)
|
||||
ctx.Ensure(context.CtxRequirement{RemoteRepo: true})
|
||||
ctx, err := context.InitCommand(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ctx.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.Args().Len() == 0 {
|
||||
return fmt.Errorf("missing required argument: %s", ctx.Command.ArgsUsage)
|
||||
}
|
||||
@@ -41,6 +46,13 @@ func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
|
||||
}
|
||||
|
||||
client := ctx.Login.Client()
|
||||
repoURL := ""
|
||||
if ctx.Args().Len() > 1 {
|
||||
repoURL, err = ctx.GetRemoteRepoHTMLURL()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, ms := range ctx.Args().Slice() {
|
||||
opts := gitea.EditMilestoneOption{
|
||||
State: &state,
|
||||
@@ -52,7 +64,7 @@ func editMilestoneStatus(_ stdctx.Context, cmd *cli.Command, close bool) error {
|
||||
}
|
||||
|
||||
if ctx.Args().Len() > 1 {
|
||||
fmt.Printf("%s/milestone/%d\n", ctx.GetRemoteRepoHTMLURL(), milestone.ID)
|
||||
fmt.Printf("%s/milestone/%d\n", repoURL, milestone.ID)
|
||||
} else {
|
||||
print.MilestoneDetails(milestone)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user