-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue_delete.go
195 lines (164 loc) · 4.36 KB
/
issue_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
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
193
194
195
package main
import (
// "context"
"fmt"
"io/ioutil"
"os"
"github.com/andygrunwald/go-jira"
"github.com/bregydoc/gtranslate"
"github.com/gocarina/gocsv"
"github.com/tkanos/gonfig"
"github.com/trivago/tgo/tcontainer"
)
type Configuration struct {
JiraUrl string
JiraUserName string
JiraUserToken string
}
type CsvIssue struct {
Label string `csv:"Label"` // .csv column headers
Key string `csv:"Issue_key"`
Id string `csv:"Issue_id"`
}
func main() {
// open Jira Connections
// jiraClientSrc := openJira("secrets_src.json")
jiraClientDst := openJira("secrets_dst.json")
// // Initial Test
// issue, _, _ := jiraClientSrc.Issue.Get("MSS-260", nil)
// printIssue(issue)
// issue, _, _ = jiraClientDst.Issue.Get("DMOB-1202", nil)
// printIssue(issue)
// Read csv
issuesCSV := readCSV("Jira.csv")
for _, issue_csv := range issuesCSV {
fmt.Printf("------------------------------\n")
fmt.Println("** Processing Issue: ", issue_csv.Key)
// get Issue from SRC
issue, _, _ := jiraClientDst.Issue.Get(issue_csv.Key, nil)
printIssue(issue)
issue.Fields.Summary = "delete"
// ctx := context.Background()
// ctx = context.WithValue(ctx, "update", "{\"labels\": [{\"add\":\"triaged\"}}")
// ctx = context.WithValue(ctx, "update", "{\"summary\":[{\"set\":\"delete\"}]]}")
i := make(map[string]interface{})
fields :=map[string]interface{}{"summary": "delete"}
i["fields"] = fields
jiraClientDst.Issue.UpdateIssue(issue_csv.Key, i)
issue, _, _ = jiraClientDst.Issue.Get(issue_csv.Key, nil)
printIssue(issue)
}
}
func openJira(conf_file string) *jira.Client {
configuration := Configuration{}
err := gonfig.GetConf(conf_file, &configuration)
if err != nil {
panic(err)
}
fmt.Printf("Start Jira with username: %s\n", configuration.JiraUserName)
base := configuration.JiraUrl
tp := jira.BasicAuthTransport{
Username: configuration.JiraUserName,
Password: configuration.JiraUserToken,
}
jiraClient, err := jira.NewClient(tp.Client(), base)
if err != nil {
panic(err)
}
return jiraClient
}
func readCSV(csv_file string) []*CsvIssue {
in, err := os.Open(csv_file)
if err != nil {
panic(err)
}
defer in.Close()
issues := []*CsvIssue{}
if err := gocsv.UnmarshalFile(in, &issues); err != nil {
panic(err)
}
return issues
}
func printIssue(issue *jira.Issue) {
fmt.Printf("Self :%s\n", issue.Self)
fmt.Printf("Key :%s\n", issue.Key)
fmt.Printf("Summary: %+v\n", issue.Fields.Summary)
fmt.Printf("Type: %s\n", issue.Fields.Type.Name)
fmt.Printf("Priority: %s\n", issue.Fields.Priority.Name)
fmt.Printf("Description: %s\n", issue.Fields.Description)
fmt.Printf("Labels: %s\n", issue.Fields.Labels)
}
func translateSummary(text string) string {
translated, err := gtranslate.TranslateWithParams(
text,
gtranslate.TranslationParams{
From: "pt",
To: "en",
},
)
if err != nil {
panic(err)
}
return translated
}
func translateDescription(text string) string {
translated, err := gtranslate.TranslateWithParams(
text,
gtranslate.TranslationParams{
From: "pt",
To: "en",
},
)
if err != nil {
panic(err)
}
header := "\n----\n*[pt-br original]*\n"
return translated + header + text + "\n"
}
func createFromIssue(client *jira.Client, issueFrom *jira.Issue) {
// Story points: import from custom field
unknowns := tcontainer.NewMarshalMap()
unknowns["customfield_10002"] = issueFrom.Fields.Unknowns["customfield_10002"]
// Labels: original labels plus compent name
labels := issueFrom.Fields.Labels
labels = append(labels, issueFrom.Key) // add orign key
for _, c := range issueFrom.Fields.Components {
labels = append(labels, c.Name)
}
// IssueType mapping
issueType := issueFrom.Fields.Type.Name
if issueType == "Improvement" {
issueType = "New Feature"
}
if issueType == "Sub-task" {
issueType = "Task"
}
i := jira.Issue{
Fields: &jira.IssueFields{
Assignee: &jira.User{
Name: "lribas",
},
Description: issueFrom.Fields.Description,
Type: jira.IssueType{
Name: issueType,
},
Project: jira.Project{
Key: "DMOB",
},
Summary: issueFrom.Fields.Summary,
Unknowns: unknowns,
Labels: labels,
},
}
issue, resp, err := client.Issue.Create(&i)
if err != nil {
body, _ := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Printf(string(body))
}
panic(err)
}
fmt.Printf("CREATED:")
issue, _, _ = client.Issue.Get(issue.Key, nil)
printIssue(issue)
}