Add interactive mode for tea milestone create
#310
|
@ -11,9 +11,9 @@ import (
|
|||
"code.gitea.io/tea/modules/context"
|
||||
"code.gitea.io/tea/modules/interact"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -36,8 +36,9 @@ var CmdMilestonesCreate = cli.Command{
|
|||
Usage: "milestone description to create",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "deadline",
|
||||
Usage: "set milestone deadline (default is no due date)",
|
||||
Name: "deadline",
|
||||
Aliases: []string{"expires", "x"},
|
||||
Usage: "set milestone deadline (default is no due date)",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "state",
|
||||
|
@ -53,11 +54,11 @@ func runMilestonesCreate(cmd *cli.Context) error {
|
|||
date := ctx.String("deadline")
|
||||
deadline := &time.Time{}
|
||||
if date != "" {
|
||||
t, err := utils.GetIso8601Date(date)
|
||||
t, err := dateparse.ParseAny(date)
|
||||
if err == nil {
|
||||
return err
|
||||
}
|
||||
deadline = t
|
||||
deadline = &t
|
||||
}
|
||||
|
||||
state := gitea.StateOpen
|
||||
|
@ -66,7 +67,7 @@ func runMilestonesCreate(cmd *cli.Context) error {
|
|||
}
|
||||
|
||||
if ctx.NumFlags() == 0 {
|
||||
YakoYakoYokuYoku marked this conversation as resolved
Outdated
6543
commented
Outdated
Review
```diff
- return interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo, deadline, state)
+ return interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo)
```
|
||||
return interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo, deadline, state)
|
||||
return interact.CreateMilestone(ctx.Login, ctx.Owner, ctx.Repo)
|
||||
}
|
||||
|
||||
return task.CreateMilestone(
|
||||
|
|
|
@ -5,19 +5,21 @@
|
|||
package interact
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/tea/modules/config"
|
||||
"code.gitea.io/tea/modules/task"
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/araddon/dateparse"
|
||||
)
|
||||
|
||||
// CreateMilestone interactively creates a milestone
|
||||
YakoYakoYokuYoku marked this conversation as resolved
Outdated
noerw
commented
No need for the deadline & state params: They will never be set anyway No need for the deadline & state params: They will never be set anyway
6543
commented
didn't he add a flag for this? didn't he add a flag for this?
noerw
commented
Yeah, but interactive mode won't be enabled if there is a flag set.. Yeah, but interactive mode won't be enabled if there is a flag set..
We could ofcourse change the condition to go into interactive mode, if not all mandatory flags are provided, but idk if that's better
6543
commented
no interactive should only if no flags are pressent - how would you integrate tea into scripts if it would ask you the whole time ... no interactive should only if no flags are pressent - how would you integrate tea into scripts if it would ask you the whole time ...
6543
commented
```diff
-func CreateMilestone(login *config.Login, owner, repo string, deadline *time.Time, state gitea.StateType) error {
+func CreateMilestone(login *config.Login, owner, repo string) error {
```
|
||||
func CreateMilestone(login *config.Login, owner, repo string, deadline *time.Time, state gitea.StateType) error {
|
||||
func CreateMilestone(login *config.Login, owner, repo string) error {
|
||||
YakoYakoYokuYoku marked this conversation as resolved
Outdated
6543
commented
```diff
- var title, description, dueDate string
+ var title, description, dueDate string
+ var deadline *time.Time
```
|
||||
var title, description, dueDate string
|
||||
var deadline *time.Time
|
||||
|
||||
// owner, repo
|
||||
owner, repo, err := promptRepoSlug(owner, repo)
|
||||
|
@ -40,17 +42,29 @@ func CreateMilestone(login *config.Login, owner, repo string, deadline *time.Tim
|
|||
|
||||
YakoYakoYokuYoku marked this conversation as resolved
Outdated
noerw
commented
I'd put the date parsing inside a I'd put the date parsing inside a `survey.Validator` similar to `promptRepoSlug()`. This lets users iterate on wrong inputs, instead of failing the entire command
YakoYakoYokuYoku
commented
Gotcha, thx for pointing that out ? Gotcha, thx for pointing that out ?
|
||||
// deadline
|
||||
promptI = &survey.Input{Message: "Milestone deadline [no due date]:"}
|
||||
if err := survey.AskOne(promptI, &dueDate, nil); err != nil {
|
||||
err = survey.AskOne(
|
||||
promptI,
|
||||
&dueDate,
|
||||
survey.WithValidator(func(input interface{}) error {
|
||||
if str, ok := input.(string); ok {
|
||||
if len(str) == 0 {
|
||||
return nil
|
||||
}
|
||||
t, err := dateparse.ParseAny(str)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
deadline = &t
|
||||
} else {
|
||||
return fmt.Errorf("invalid result type")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
YakoYakoYokuYoku marked this conversation as resolved
Outdated
6543
commented
```diff
- state)
+ gitea.StateOpen)
```
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if dueDate != "" {
|
||||
deadline, err = utils.GetIso8601Date(dueDate)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
deadline = nil
|
||||
}
|
||||
|
||||
return task.CreateMilestone(
|
||||
login,
|
||||
|
@ -59,5 +73,5 @@ func CreateMilestone(login *config.Login, owner, repo string, deadline *time.Tim
|
|||
title,
|
||||
description,
|
||||
deadline,
|
||||
state)
|
||||
gitea.StateOpen)
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ArgToIndex take issue/pull index as string and return int64
|
||||
|
@ -40,16 +39,3 @@ func GetOwnerAndRepo(repoPath, user string) (string, string) {
|
|||
}
|
||||
return user, repoPath
|
||||
}
|
||||
|
||||
// GetIso8601Date parses a date from a string
|
||||
func GetIso8601Date(date string) (*time.Time, error) {
|
||||
t, err := time.Parse("2006-01-02", date)
|
||||
if err != nil {
|
||||
t, err := time.Parse(time.RFC3339, date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user