This repository has been archived by the owner on Nov 22, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 163
/
issue_create.go
101 lines (95 loc) · 3.45 KB
/
issue_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package commands
import (
"strings"
"github.com/spf13/cobra"
"github.com/xanzy/go-gitlab"
"glab/internal/git"
"glab/internal/manip"
)
var issueCreateCmd = &cobra.Command{
Use: "create [flags]",
Short: `Create an issue`,
Long: ``,
Aliases: []string{"new"},
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
cmdErr(cmd, args)
return nil
}
l := &gitlab.CreateIssueOptions{}
var issueTitle string
var issueLabel string
var issueDescription string
if title, _ := cmd.Flags().GetString("title"); title != "" {
issueTitle = strings.Trim(title, " ")
} else {
issueTitle = manip.AskQuestionWithInput("Title", "", true)
}
if description, _ := cmd.Flags().GetString("description"); description != "" {
issueDescription = strings.Trim(description, " ")
} else {
if editor, _ := cmd.Flags().GetBool("no-editor"); editor {
issueDescription = manip.AskQuestionMultiline("Description:", "")
} else {
issueDescription = manip.Editor(manip.EditorOptions{
Label: "Description:",
Help: "Enter the issue description. ",
FileName: "*_ISSUE_EDITMSG.md",
})
}
}
if label, _ := cmd.Flags().GetString("label"); label != "" {
issueLabel = strings.Trim(label, "[] ")
} else {
issueLabel = manip.AskQuestionWithInput("Label(s) [Comma Separated]", "", false)
}
l.Title = gitlab.String(issueTitle)
l.Labels = &gitlab.Labels{issueLabel}
l.Description = &issueDescription
if confidential, _ := cmd.Flags().GetBool("confidential"); confidential {
l.Confidential = gitlab.Bool(confidential)
}
if weight, _ := cmd.Flags().GetInt("weight"); weight != -1 {
l.Weight = gitlab.Int(weight)
}
if a, _ := cmd.Flags().GetInt("linked-mr"); a != -1 {
l.MergeRequestToResolveDiscussionsOf = gitlab.Int(a)
}
if a, _ := cmd.Flags().GetInt("milestone"); a != -1 {
l.MilestoneID = gitlab.Int(a)
}
if a, _ := cmd.Flags().GetString("assignee"); a != "" {
assignID := a
arrIds := strings.Split(strings.Trim(assignID, "[] "), ",")
var t2 []int
for _, i := range arrIds {
j := manip.StringToInt(i)
t2 = append(t2, j)
}
l.AssigneeIDs = t2
}
gitlabClient, repo := git.InitGitlabClient()
if r, _ := cmd.Flags().GetString("repo"); r != "" {
repo = r
}
issue, _, err := gitlabClient.Issues.CreateIssue(repo, l)
if err != nil {
return err
}
displayIssue(issue)
return nil
},
}
func init() {
issueCreateCmd.Flags().StringP("title", "t", "", "Supply a title for issue")
issueCreateCmd.Flags().StringP("description", "d", "", "Supply a description for issue")
issueCreateCmd.Flags().StringP("label", "l", "", "Add label by name. Multiple labels should be comma separated")
issueCreateCmd.Flags().StringP("assignee", "a", "", "Assign issue to people by their ID. Multiple values should be comma separated ")
issueCreateCmd.Flags().IntP("milestone", "m", -1, "The global ID of a milestone to assign issue")
issueCreateCmd.Flags().BoolP("confidential", "c", false, "Set an issue to be confidential. Default is false")
issueCreateCmd.Flags().IntP("linked-mr", "", -1, "The IID of a merge request in which to resolve all issues")
issueCreateCmd.Flags().IntP("weight", "w", -1, "The weight of the issue. Valid values are greater than or equal to 0.")
issueCreateCmd.Flags().BoolP("no-editor", "", false, "Don't open editor to enter description. If set to true, uses prompt. Default is false")
issueCmd.AddCommand(issueCreateCmd)
}