-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
118 lines (99 loc) · 2.63 KB
/
delete.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
package issue
import (
"fmt"
"log"
"github.com/AlecAivazis/survey/v2"
"github.com/andygrunwald/go-jira"
"github.com/briandowns/spinner"
"github.com/locona/jira/pkg/issue"
"github.com/locona/jira/pkg/prompt"
"github.com/spf13/cobra"
)
type DeleteOption struct {
Interactive bool
IssueIDList []string
Search *issue.Search
}
func NewCommandDelete() *cobra.Command {
deleteOption := &DeleteOption{
Search: &issue.Search{},
}
cmd := &cobra.Command{
Use: "delete",
RunE: func(cmd *cobra.Command, args []string) error {
return Delete(deleteOption)
},
}
cmd.Flags().BoolVarP(&deleteOption.Interactive, "interactive", "i", false, "Interactive.")
cmd.Flags().StringSliceVar(&deleteOption.IssueIDList, "issueid", []string{}, "Issue ID.")
// search
cmd.Flags().StringSliceVar(&deleteOption.Search.Labels, "labels", []string{}, "Labels.")
cmd.Flags().StringVar(&deleteOption.Search.Status, "status", "", "Status.")
cmd.Flags().StringVar(&deleteOption.Search.Summary, "summary", "", "Summary.")
cmd.Flags().StringVar(&deleteOption.Search.Assignee, "assignee", "own", "Assignee.")
cmd.Flags().StringVar(&deleteOption.Search.Reporter, "reporter", "", "Reporter.")
return cmd
}
func Delete(option *DeleteOption) error {
if !option.Interactive {
// BatchDelete(option.IssueIDList)
return nil
}
issueList, err := issue.List(option.Search)
if err != nil {
return err
}
options, mapOptionToIssue := issue.Options(issueList)
deletePrompt := &survey.MultiSelect{
Message: "Select Delete ISSUE ID",
Options: options,
}
deleteIssueOptions := make([]string, 0)
err = survey.AskOne(deletePrompt, &deleteIssueOptions, nil)
if err != nil {
return err
}
deleteIssueSlice := make([]jira.Issue, 0)
for _, op := range deleteIssueOptions {
issue := mapOptionToIssue[op]
deleteIssueSlice = append(deleteIssueSlice, issue)
}
confirm := false
prompt := &survey.Confirm{
Message: "Do you really want to delete this?",
}
survey.AskOne(prompt, &confirm, nil)
if !confirm {
return nil
}
BatchDelete(deleteIssueSlice)
return nil
}
type DeleteCommand struct {
Issue jira.Issue
}
func (cmd *DeleteCommand) Request(s *spinner.Spinner) error {
label := issue.Label(cmd.Issue)
var suf = make([]byte, 100)
copy(suf, label)
s.Suffix = string(suf)
s.FinalMSG = fmt.Sprintf("%v %v \n", prompt.IconClear, label)
err := issue.Delete(cmd.Issue.Key)
if err != nil {
return err
}
return nil
}
func (cmd *DeleteCommand) Response() error {
return nil
}
func BatchDelete(issueSlice []jira.Issue) {
for _, issue := range issueSlice {
err := prompt.Progress(&DeleteCommand{
Issue: issue,
})
if err != nil {
log.Println(err)
}
}
}