forked from plouc/go-gitlab-client
/
add_project_hook_cmd.go
182 lines (161 loc) · 3.74 KB
/
add_project_hook_cmd.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package cmd
import (
"github.com/fatih/color"
"github.com/manifoldco/promptui"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/plouc/go-gitlab-client/gitlab"
"github.com/spf13/cobra"
"strconv"
)
func init() {
addCmd.AddCommand(addProjectHookCmd)
}
var addProjectHookCmd = &cobra.Command{
Use: resourceCmd("project-hook", "project"),
Aliases: []string{"ph"},
Short: "Create a new hook for given project",
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := config.aliasIdsOrArgs(currentAlias, "project", args)
if err != nil {
return err
}
color.Yellow("Creating hook for project (project id: %s)…", ids["project_id"])
hook := gitlab.HookAddPayload{}
prompt := promptui.Prompt{
Label: "Url",
}
u, err := prompt.Run()
if err != nil {
return err
}
hook.Url = u
selectPrompt := promptui.Select{
Label: color.YellowString("Push events?"),
Items: []string{"yes", "no"},
}
idx, _, err := selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.PushEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Issue events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.IssuesEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Confidential issues events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.ConfidentialIssuesEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Merge requests events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.MergeRequestsEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Tag push events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.TagPushEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Note events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.NoteEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Job events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.JobEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Pipeline events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.PipelineEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Wiki page events?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.WikiPageEvents = true
}
selectPrompt = promptui.Select{
Label: color.YellowString("Enable ssl verification?"),
Items: []string{"yes", "no"},
}
idx, _, err = selectPrompt.Run()
if err != nil {
return err
}
if idx == 0 {
hook.EnableSslVerification = true
}
loader.Start()
createdHook, meta, err := client.AddProjectHook(ids["project_id"], &hook)
loader.Stop()
if err != nil {
return err
}
out.Hook(output, outputFormat, createdHook)
printMeta(meta, false)
relatedCommands([]*relatedCommand{
newRelatedCommand(listProjectHooksCmd, map[string]string{
"project_id": ids["project_id"],
}),
newRelatedCommand(getProjectHookCmd, map[string]string{
"project_id": ids["project_id"],
"hook_id": strconv.Itoa(createdHook.Id),
}),
})
return nil
},
}