-
Notifications
You must be signed in to change notification settings - Fork 3
/
clubhouse_options.go
158 lines (125 loc) · 3.53 KB
/
clubhouse_options.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
package main
import (
"fmt"
"log"
ch "github.com/jnormington/clubhouse-go"
)
//ClubhouseOptions stores the options selected by the user
type ClubhouseOptions struct {
Project *ch.Project
State *ch.State
ClubhouseEntry *ch.Clubhouse
StoryType string
AddCommentWithTrelloLink bool
ImportMember *ch.Member
}
type worfklowState struct {
WorkflowIdx int
StateIdx int
DisplayText string
}
// ListMember makes the call to Clubhouse package for the list
// of members. And fails hard if an err occurs.
func (co *ClubhouseOptions) ListMembers() *[]ch.Member {
u, err := co.ClubhouseEntry.ListMembers()
if err != nil {
log.Fatal(err)
}
return &u
}
// SetupClubhouseOptions calls all the functions which consist of questions
// for building ClubhouseOptions and returns a pointer to ClubhouseOptions instance
func SetupClubhouseOptions() *ClubhouseOptions {
var co ClubhouseOptions
co.ClubhouseEntry = ch.New(clubHouseToken)
co.getProjectsAndPromptUser()
co.getWorkflowStatesAndPromptUser()
co.getMembersAndPromptUser()
co.promptUserForStoryType()
co.promptUserIfAddCommentWithTrelloLink()
return &co
}
func (co *ClubhouseOptions) promptUserIfAddCommentWithTrelloLink() {
fmt.Println("Would you like a comment added with the original trello ticket link?")
for i, b := range yesNoOpts {
fmt.Printf("[%d] %s\n", i, b)
}
i := promptUserSelectResource()
if i >= len(yesNoOpts) {
log.Fatal(errOutOfRange)
}
if i == 0 {
co.AddCommentWithTrelloLink = true
}
}
func (co *ClubhouseOptions) getProjectsAndPromptUser() {
projects, err := co.ClubhouseEntry.ListProjects()
if err != nil {
log.Fatal(err)
}
fmt.Println("Please select a project by it number to import the cards into")
for i, p := range projects {
fmt.Printf("[%d] %s\n", i, p.Name)
}
i := promptUserSelectResource()
if i >= len(projects) {
log.Fatal(errOutOfRange)
}
co.Project = &projects[i]
}
func (co *ClubhouseOptions) getMembersAndPromptUser() {
members, err := co.ClubhouseEntry.ListMembers()
if err != nil {
log.Fatal(err)
}
fmt.Println("Please select a backup user account if a user is not mapped correctly")
for i, u := range members {
fmt.Printf("[%d] %s\n", i, u.Profile.Name)
}
i := promptUserSelectResource()
if i >= len(members) {
log.Fatal(errOutOfRange)
}
co.ImportMember = &members[i]
}
func (co *ClubhouseOptions) getWorkflowStatesAndPromptUser() {
workflows, err := co.ClubhouseEntry.ListWorkflow()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Please select a workflow state linked to '%s' - to import the trello cards into\n", co.Project.Name)
var options []worfklowState
for wIdx, w := range workflows {
if w.TeamID != co.Project.TeamID {
continue
}
for sIdx, s := range w.States {
options = append(options, worfklowState{
WorkflowIdx: wIdx,
StateIdx: sIdx,
DisplayText: fmt.Sprintf("%s - %s", w.Name, s.Name),
})
}
}
for i, o := range options {
fmt.Printf("[%d] %s\n", i, o.DisplayText)
}
i := promptUserSelectResource()
if i >= len(options) {
log.Fatal(errOutOfRange)
}
selected := options[i]
co.State = &workflows[selected.WorkflowIdx].States[selected.StateIdx]
}
func (co *ClubhouseOptions) promptUserForStoryType() {
types := []string{"feature", "chore", "bug"}
fmt.Println("Please select the story type all cards should be imported as")
for i, t := range types {
fmt.Printf("[%d] %s\n", i, t)
}
i := promptUserSelectResource()
if i >= len(types) {
log.Fatal(errOutOfRange)
}
co.StoryType = types[i]
}