add more issue / pr creation params #331
|
@ -14,7 +14,6 @@ import (
|
||||||
"code.gitea.io/tea/modules/context"
|
"code.gitea.io/tea/modules/context"
|
||||||
"code.gitea.io/tea/modules/interact"
|
"code.gitea.io/tea/modules/interact"
|
||||||
"code.gitea.io/tea/modules/task"
|
"code.gitea.io/tea/modules/task"
|
||||||
"code.gitea.io/tea/modules/utils"
|
|
||||||
|
|
||||||
"github.com/araddon/dateparse"
|
"github.com/araddon/dateparse"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
@ -73,6 +72,8 @@ func runIssuesCreate(cmd *cli.Context) error {
|
||||||
client *gitea.Client
|
client *gitea.Client
|
||||||
milestoneID int64
|
milestoneID int64
|
||||||
deadline *time.Time
|
deadline *time.Time
|
||||||
|
labelIDs []int64
|
||||||
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
date := ctx.String("deadline")
|
date := ctx.String("deadline")
|
||||||
|
@ -85,20 +86,13 @@ func runIssuesCreate(cmd *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
labelNames := strings.Split(ctx.String("labels"), ",")
|
labelNames := strings.Split(ctx.String("labels"), ",")
|
||||||
labelIDs := make([]int64, len(labelNames))
|
|
||||||
if len(labelNames) != 0 {
|
if len(labelNames) != 0 {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
client = ctx.Login.Client()
|
client = ctx.Login.Client()
|
||||||
}
|
}
|
||||||
labels, _, err := client.ListRepoLabels(ctx.Owner, ctx.Repo, gitea.ListLabelsOptions{})
|
if labelIDs, err = task.ResolveLabelNames(client, ctx.Owner, ctx.Repo, labelNames); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, l := range labels {
|
|
||||||
if utils.Contains(labelNames, l.Name) {
|
|
||||||
labelIDs = append(labelIDs, l.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if milestoneName := ctx.String("milestone"); len(milestoneName) != 0 {
|
if milestoneName := ctx.String("milestone"); len(milestoneName) != 0 {
|
||||||
|
|
|
@ -5,16 +5,24 @@
|
||||||
package interact
|
package interact
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"code.gitea.io/tea/modules/config"
|
"code.gitea.io/tea/modules/config"
|
||||||
"code.gitea.io/tea/modules/task"
|
"code.gitea.io/tea/modules/task"
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
|
"github.com/araddon/dateparse"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CreateIssue interactively creates an issue
|
// CreateIssue interactively creates an issue
|
||||||
func CreateIssue(login *config.Login, owner, repo string) error {
|
func CreateIssue(login *config.Login, owner, repo string) error {
|
||||||
var title, description string
|
var title, description, dueDate, assignees, milestone, labels string
|
||||||
|
var deadline *time.Time
|
||||||
|
var msID int64
|
||||||
|
var labelIDs []int64
|
||||||
|
|
||||||
// owner, repo
|
// owner, repo
|
||||||
owner, repo, err := promptRepoSlug(owner, repo)
|
owner, repo, err := promptRepoSlug(owner, repo)
|
||||||
|
@ -30,18 +38,78 @@ func CreateIssue(login *config.Login, owner, repo string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// description
|
// description
|
||||||
promptM := &survey.Multiline{Message: "Issue description:"}
|
promptD := &survey.Multiline{Message: "Issue description:"}
|
||||||
if err := survey.AskOne(promptM, &description); err != nil {
|
if err := survey.AskOne(promptD, &description); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assignees // TODO: add suggestions
|
||||||
|
promptA := &survey.Input{Message: "Assignees:"}
|
||||||
|
if err := survey.AskOne(promptA, &assignees); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// milestone // TODO: add suggestions
|
||||||
|
promptM := &survey.Input{Message: "Milestone:"}
|
||||||
|
if err := survey.AskOne(promptM, &milestone); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// labels // TODO: add suggestions
|
||||||
|
promptL := &survey.Input{Message: "Labels:"}
|
||||||
|
if err := survey.AskOne(promptL, &labels); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// deadline
|
||||||
|
promptI = &survey.Input{Message: "Due date [no due date]:"}
|
||||||
|
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
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
// resolve IDs
|
||||||
|
client := login.Client()
|
||||||
|
if len(milestone) != 0 {
|
||||||
|
ms, _, err := client.GetMilestoneByName(owner, repo, milestone)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Milestone '%s' not found", milestone)
|
||||||
|
}
|
||||||
|
msID = ms.ID
|
||||||
|
}
|
||||||
|
if len(labels) != 0 {
|
||||||
|
labelIDs, err = task.ResolveLabelNames(client, owner, repo, strings.Split(labels, ","))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return task.CreateIssue(
|
return task.CreateIssue(
|
||||||
login,
|
login,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
gitea.CreateIssueOption{
|
gitea.CreateIssueOption{
|
||||||
Title: title,
|
Title: title,
|
||||||
Body: description,
|
Body: description,
|
||||||
|
Deadline: deadline,
|
||||||
|
Assignees: strings.Split(assignees, ","),
|
||||||
|
Milestone: msID,
|
||||||
|
Labels: labelIDs,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
26
modules/task/labels.go
Normal file
26
modules/task/labels.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package task
|
||||||
|
|
||||||
|
import (
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
"code.gitea.io/tea/modules/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ResolveLabelNames returns a list of label IDs for a given list of label names
|
||||||
|
func ResolveLabelNames(client *gitea.Client, owner, repo string, labelNames []string) ([]int64, error) {
|
||||||
|
// labelNames := strings.Split(ctx.String("labels"), ",")
|
||||||
|
labelIDs := make([]int64, len(labelNames))
|
||||||
|
labels, _, err := client.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, l := range labels {
|
||||||
|
if utils.Contains(labelNames, l.Name) {
|
||||||
|
labelIDs = append(labelIDs, l.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return labelIDs, nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user