/
issue.go
158 lines (145 loc) · 3.81 KB
/
issue.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 api
import (
"fmt"
"github.com/pkg/errors"
)
type IdAndType struct {
Id string
Type string
}
type Data struct {
Data IdAndType
}
type V1IssueResponse struct {
Attributes struct {
FindingKey string `json:"finding-key"`
IssueKey string `json:"issue-key"`
SubTool string `json:"sub-tool"`
//Severity type?
}
Id string
Type string
Relationships struct {
Path Data
ToolDomainService Data `json:"tool-domain-service-data"`
IssueType Data `json:"issue-type"`
Tool Data
LatestObservedOnRun Data `json:"latest-observed-on-run"`
Transitions struct {
Data []IdAndType
}
RelatedTaxa struct {
Data []interface{} // TODO type ?
} `json:"related-taxa"`
RelatedIndicators struct {
Data []interface{} // TODO type ?
} `json:"related-indicators"`
IssueKind interface{} `json:"issue-kind"` // TODO type?
Severity interface{} // TODO type?
}
Links struct {
Self struct {
HRef string
}
}
}
type V1IssueIncluded struct {
Id string
Type string
Attributes map[string]interface{}
}
type GetV1IssuesResponse struct {
Data []V1IssueResponse
Included []V1IssueIncluded
Meta struct {
Total int
Offset int
Limit int
Complete bool
RunCount int `json:"run-count"`
}
}
func (client *Client) GetV1Issues(projectId string, branchId string, runId string, offset int, limit int) (*GetV1IssuesResponse, error) {
if branchId != "" && runId != "" {
return nil, errors.New("only one of branchId and runId may be specified (both were non-empty)")
}
if branchId == "" && runId == "" {
return nil, errors.New("one of branchId and runId may be specified (both were empty)")
}
result := &GetV1IssuesResponse{}
params := map[string]interface{}{
"project-id": projectId,
"page[offset]": fmt.Sprintf("%d", offset),
"page[limit]": fmt.Sprintf("%d", limit),
}
if branchId != "" {
params["branch-id"] = branchId
}
if runId != "" {
params["run-id[]"] = []string{runId}
}
_, err := client.GetJson(params, result, "api/query/v1/issues")
return result, err
}
type GetV0RollUpCountsResponse struct {
Data []struct {
Id string
Type string
Relationships map[string]struct {
Data *struct {
Id string
Type string
}
}
Attributes struct {
Value int
}
}
Included []struct {
Id string
Type string
Attributes map[string]interface{} // TODO type?
}
Meta struct {
Offset int
Limit int
Total int
Complete bool
GroupBy string `json:"group-by"`
RunCount int `json:"run-count"`
}
}
func (client *Client) GetV0RollUpCounts(projectId string, branchId string, limit int) (*GetV0RollUpCountsResponse, error) {
result := &GetV0RollUpCountsResponse{}
params := map[string]interface{}{
"project-id": projectId,
"branch-id": branchId,
"page[limit]": fmt.Sprintf("%d", limit),
}
_, err := client.GetJson(params, result, "api/query/v0/roll-up-counts")
return result, err
}
type GetV1IssueResponse struct {
Data V1IssueResponse
Included []V1IssueIncluded
}
func (client *Client) GetV1Issue(projectId string, branchId string, issueId string) (*GetV1IssueResponse, error) {
result := &GetV1IssueResponse{}
params := map[string]interface{}{
"project-id": projectId,
"branch-id": branchId,
}
_, err := client.GetJson(params, result, "api/query/v1/issues/%s", issueId)
return result, err
}
// TODO:
// /v1/roll-up-counts
// /v1/counts/status
func (client *Client) QueryV0DiscoveryFilterKeysIssuetoolidValues() (string, error) {
// example:
// https://local.dev.polaris.synopsys.com/api/query/v0/discovery/filter-keys/issue.tool.id/values?page%5Blimit%5D=50
params := map[string]interface{}{
"page[limit]": "50",
}
return client.GetJson(params, nil, "api/query/v0/discovery/filter-keys/issue.tool.id/values")
}