-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
192 lines (165 loc) · 3.63 KB
/
main.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
183
184
185
186
187
188
189
190
191
192
package main
import (
"bufio"
"encoding/csv"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"os"
jira "github.com/irahardianto/go-jira"
)
func main() {
base := ""
tp := jira.BasicAuthTransport{
Username: "",
Password: "",
}
jiraClient, err := jira.NewClient(tp.Client(), base)
if err != nil {
panic(err)
}
roadmapKey, err := createRoadMapEpic(jiraClient, "Just a demo roadmap", "2019-09-02", "2019-09-22")
if err != nil {
panic(err)
}
epicKey, err := createProjectEpic(jiraClient, roadmapKey, "DEMO", "Just a demo epic", "Just a demo epic")
if err != nil {
panic(err)
}
issueKey, err := createProjectTasks(jiraClient, epicKey, "DEMO", "Story", "Just a demo story")
if err != nil {
panic(err)
}
fmt.Println(issueKey)
}
func createRoadMapEpic(jc *jira.Client, epicSummary string, startDate string, dueDate string) (string, error) {
i := jira.Issue{
Fields: &jira.IssueFields{
Type: jira.IssueType{
Name: "Epic",
},
StartDate: startDate,
Duedate: dueDate,
Project: jira.Project{
Key: "DEMO",
},
Summary: epicSummary,
},
}
issue, _, err := jc.Issue.Create(&i)
if err != nil {
return "", err
}
return issue.Key, nil
}
func createProjectEpic(jc *jira.Client, roadmapKey string, projectKey string, epicSummary string, epicName string) (string, error) {
// WIP
// a := []*jira.IssueLink{}
// jil := jira.IssueLink{
// Type: jira.IssueLinkType{
// Name: "Blocks",
// },
// OutwardIssue: &jira.Issue{
// Key: roadmapKey,
// },
// }
//
//a = append(a, &jil)
i := jira.Issue{
Fields: &jira.IssueFields{
// Assignee: &jira.User{
// Name: "",
// },
// Reporter: &jira.User{
// Name: "",
// },
// Description: "Test Epic",
Type: jira.IssueType{
Name: "Epic",
},
EpicName: epicName,
Project: jira.Project{
Key: projectKey,
},
// IssueLinks: a, WIP
Summary: epicSummary,
},
}
issue, resp, err := jc.Issue.Create(&i)
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
fmt.Println(bodyString)
if err != nil {
panic(err)
}
fmt.Println(issue.Key)
return issue.Key, nil
}
func createProjectTasks(jc *jira.Client, epicKey string, projectKey string, issueType string, ticketSummary string) (string, error) {
i := jira.Issue{
Fields: &jira.IssueFields{
// Assignee: &jira.User{
// Name: "",
// },
// Reporter: &jira.User{
// Name: "",
// },
// Description: "Test Issue",
Type: jira.IssueType{
Name: issueType,
},
EpicLink: epicKey,
Project: jira.Project{
Key: projectKey,
},
Summary: ticketSummary,
},
}
issue, _, err := jc.Issue.Create(&i)
if err != nil {
panic(err)
}
fmt.Println(issue.Key)
return issue.Key, nil
}
func readCSV() []Issue {
csvFile, _ := os.Open("people.csv")
reader := csv.NewReader(bufio.NewReader(csvFile))
var issues []Issue
for {
line, error := reader.Read()
if error == io.EOF {
break
} else if error != nil {
log.Fatal(error)
}
issues = append(issues, Issue{
Summary: line[0],
IssueType: line[1],
Labels: line[2],
Assignee: line[3],
DueDate: line[4],
Description: line[5],
Blocks: line[6],
Epic: line[7],
})
}
issuesJson, _ := json.Marshal(issues)
fmt.Println(string(issuesJson))
return issues
}
type Issue struct {
Summary string `json:"summary"`
IssueType string `json:"lastname"`
Labels string `json:"labels"`
Assignee string `json:"assignee"`
DueDate string `json:"duedate"`
Description string `json:"description"`
Blocks string `json:"blocks"`
Epic string `json:"epic"`
}