-
Notifications
You must be signed in to change notification settings - Fork 0
/
youTrackParser.go
205 lines (169 loc) · 9.56 KB
/
youTrackParser.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
196
197
198
199
200
201
202
203
204
205
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"sort"
"strings"
)
type ReportListItem struct {
Own bool `json:"own"`
Name string `json:"name"`
Id string `json:"id"`
Type string `json:"$type"`
}
type ReportLine struct {
Description string
IssueId string
TotalDuration struct {
Value int
}
Estimation struct {
Value int
}
}
type ReportGroupMeta struct {
LinkedUser struct {
VisibleName string
RingId string
}
}
type ReportGroupItem struct {
Lines []ReportLine
Meta ReportGroupMeta
Estimation struct {
Value int
}
}
type Report struct {
Data struct {
Groups []ReportGroupItem
}
Name string
}
type Sprint struct {
Archived bool
Id string
Name string
}
type BoardCell struct {
Issues []Issue
}
type Issue struct {
Id string `json:"id"`
Summary string `json:"summary"`
}
type Task struct {
Id string
IdReadable string
}
type TaskInfo struct {
Id string
IdReadable string
Summary string
}
func GetReportsList() []ReportListItem {
req, err := http.NewRequest("GET", url+"/api/reports?$top=-1&fields=$type,id,name,own", nil)
req.Header.Add("Authorization", token)
client := &http.Client{}
resp, err := client.Do(req)
checkError(err, "Ошибка при получении списка отчетов. Проверьте доступронсть " + url)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
checkError(err, "Error while reading the response bytes")
var reporstList []ReportListItem
json.Unmarshal(body, &reporstList)
return reporstList
}
func GetReport(id string) Report {
currentReportUrl := url + "/api/reports/" + id + "?$top=-1&fields=$type,aggregationPolicy($type,field($type,id,presentation)),attachedFields($type,field($type,aggregateable,id,presentation)),authors(fullName,id,login,ringId),bubbleWorkItems,data(duration(id,value),estimation(id,value),fieldNames,groups(duration(id,value),estimation(id,value),id,issueId,issueSummary,lines(comment,date,description,duration(id,value),estimation(id,value),fieldValues,groupName,id,issueId,issueSummary,name,totalDuration(id,value),typeDurations(duration(value),workType),userAvatarUrl,userId,userVisibleName),meta(linkedIssue(idReadable,summary),linkedUser(ringId,visibleName,postfix)),name,totalDuration(id,value),typeDurations(duration(value),workType)),totalDuration(id,value),typeDurations(duration(value),workType)),effectiveQuery,effectiveQueryUrl,grouping(id,field(id,presentation)),id,invalidationInterval,name,own,owner(id,login),pin(pinned),projects(id,name,ringId,shortName),query,range($type,from,range(id),to),sprint(id,name),status(calculationInProgress,error(id),errorMessage,isOutdated,lastCalculated,progress,wikifiedErrorMessage),updateableBy(id,name),visibleTo(id,name),wikifiedError,windowSize,workTypes(id,name)&line=issue&query=for:ringId"
req, err := http.NewRequest("GET", currentReportUrl, nil)
req.Header.Add("Authorization", token)
client := &http.Client{}
resp, err := client.Do(req)
checkError(err, "Ошибка при получении данных")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
checkError(err, "Error while reading the response bytes")
var report Report
json.Unmarshal(body, &report)
return report
}
func GetCurrentSprintID(date string) string {
sprintListUrl := url + "/api/agiles/114-4/sprints/?issuesQuery=&$top=-1&fields=archived,finish,goal,id,isDefault,name,report(id),start"
req, err := http.NewRequest("GET", sprintListUrl, nil)
req.Header.Add("Authorization", token)
client := &http.Client{}
resp, err := client.Do(req)
checkError(err, "Ошибка при получении данных")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
checkError(err, "Error while reading the response bytes")
var sprintList []Sprint
json.Unmarshal(body, &sprintList)
var sprintId string
for _, sprint := range sprintList {
if strings.HasPrefix(sprint.Name, date) {
sprintId = sprint.Id
break
}
}
return sprintId
}
func GetTaskIDList(spritnId string) []Issue {
currentUrl := url + "/api/agiles/114-4/sprints/" + spritnId + "?issuesQuery=%23%D1%8F%20&$top=-1&$topLinks=3&$topSwimlanes=10&fields=agile(hideOrphansSwimlane,id,name,orphansAtTheTop,status(valid,warnings,errors)),archived,board(columns(agileColumn(collapsed,color($type,id),fieldValues(canUpdate,column(id),id,isResolved,name,ordinal,presentation),id,isResolved,isVisible,ordinal,ordinal,parent($type,id),wipLimit($type,min,max)),collapsed,id,timeTrackingData(effectiveEstimation,estimation,hasExplicitSpentTime,spentTime)),id,name,notOnBoardCount,orphanRow($type,cells(column(collapsed,id),id,issues($type,id,summary),issuesCount,row(id),tooManyIssues),collapsed,id,issue($type,created,created,description,fields($type,hasStateMachine,id,isUpdatable,name,projectCustomField($type,bundle(id),canBeEmpty,emptyFieldText,field(fieldType(isMultiValue,valueType),id,localizedName,name,ordinal),id,isEstimation,isPublic,isSpentTime,ordinal,size),value($type,archived,avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,markdownText,minutes,name,presentation,ringId,text)),id,idReadable,isDraft,numberInProject,project($type,id,name,plugins(timeTrackingSettings(enabled,estimate(field(id,name),id),timeSpent(field(id,name),id)),vcsIntegrationSettings(processors(enabled,url,upsourceHubResourceKey,server(enabled,url)))),ringId,shortName),reporter($type,avatarUrl,email,fullName,id,isLocked,issueRelatedGroup(icon),login,name,online,profiles(general(trackOnlineStatus)),ringId),resolved,resolved,summary,updated,watchers(hasStar),wikifiedDescription),matchesQuery,name,timeTrackingData(effectiveEstimation,estimation,hasExplicitSpentTime,spentTime),value(presentation)),sortByQuery,sprint,timeTrackingData(effectiveEstimation,estimation,hasExplicitSpentTime,spentTime),trimmedSwimlanes($type,cells(column(collapsed,id),id,issues($type,id,summary),issuesCount,row(id),tooManyIssues),collapsed,id,issue($type,created,created,description,fields($type,hasStateMachine,id,isUpdatable,name,projectCustomField($type,bundle(id),canBeEmpty,emptyFieldText,field(fieldType(isMultiValue,valueType),id,localizedName,name,ordinal),id,isEstimation,isPublic,isSpentTime,ordinal,size),value($type,archived,avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,markdownText,minutes,name,presentation,ringId,text)),id,idReadable,isDraft,numberInProject,project($type,id,name,plugins(timeTrackingSettings(enabled,estimate(field(id,name),id),timeSpent(field(id,name),id)),vcsIntegrationSettings(processors(enabled,url,upsourceHubResourceKey,server(enabled,url)))),ringId,shortName),reporter($type,avatarUrl,email,fullName,id,isLocked,issueRelatedGroup(icon),login,name,online,profiles(general(trackOnlineStatus)),ringId),resolved,resolved,summary,updated,watchers(hasStar),wikifiedDescription),matchesQuery,name,timeTrackingData(effectiveEstimation,estimation,hasExplicitSpentTime,spentTime),value(presentation))),eventSourceTicket,finish,goal,id,isDefault,name,report(id),start"
req, err := http.NewRequest("GET", currentUrl, nil)
req.Header.Add("Authorization", token)
client := &http.Client{}
resp, err := client.Do(req)
checkError(err, "Ошибка при получении данных")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
checkError(err, "Error while reading the response bytes")
var tempObj struct {
Board struct {
OrphanRow struct {
Cells [] BoardCell
}
}
}
json.Unmarshal(body, &tempObj)
var list []Issue
for _, cell := range tempObj.Board.OrphanRow.Cells {
list = append(list, cell.Issues...)
}
return list
}
func GetTaskList(taskIds []Issue) []string {
temp := make([]struct{Id string `json:"id"`}, len(taskIds))
for idx, t := range taskIds {
temp[idx] = struct{Id string `json:"id"`}{Id: t.Id}
}
jsonData, err := json.Marshal(temp)
checkError(err, "Произошла ошибка")
currentUrl := url + "/api/issuesGetter?$top=-1&$topLinks=3&fields=attachments(id),fields($type,hasStateMachine,id,isUpdatable,name,projectCustomField($type,bundle(id),canBeEmpty,emptyFieldText,field(fieldType(isMultiValue,valueType),id,localizedName,name,ordinal),id,isEstimation,isPublic,isSpentTime,ordinal,size),value($type,archived,avatarUrl,buildLink,color(id),fullName,id,isResolved,localizedName,login,markdownText,minutes,name,presentation,ringId,text)),id,idReadable,isDraft,numberInProject,project($type,archived,id,name,plugins(timeTrackingSettings(enabled,estimate(field(id,name),id),timeSpent(field(id,name),id))),ringId,shortName),reporter($type,id,login,ringId),resolved,subtasks(id,issuesSize,unresolvedIssuesSize)"
req, err := http.NewRequest("POST", currentUrl, bytes.NewBuffer(jsonData))
req.Header.Add("Authorization", token)
req.Header.Add("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
checkError(err, "Ошибка при получении данных")
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
checkError(err, "Error while reading the response bytes")
var tasks []Task
json.Unmarshal(body, &tasks)
sort.SliceStable(tasks, func(i, j int) bool {
return strings.Compare(tasks[i].Id, tasks[j].Id) > 0
})
sort.SliceStable(taskIds, func(i, j int) bool {
return strings.Compare(taskIds[i].Id, taskIds[j].Id) > 0
})
taskInfoList := make([]string, len(tasks))
for idx, _ := range taskInfoList {
taskInfoList[idx] = fmt.Sprintf("%s: %s", tasks[idx].IdReadable, taskIds[idx].Summary)
}
return taskInfoList;
}