-
Notifications
You must be signed in to change notification settings - Fork 39
/
issue.go
202 lines (177 loc) · 7.46 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
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
package sentry
import (
"fmt"
"net/url"
"strconv"
"time"
)
const (
// Resolved helps mark a issue or others as resolved
Resolved Status = "resolved"
// Unresolved helps mark a issue or others as unresolved
Unresolved Status = "unresolved"
// Ignored helps mark a issue or others as ignored
Ignored Status = "ignored"
)
// Hash is returned via the issue_id/hashes
type Hash struct {
ID string `json:"id,omitempty"`
}
// Status is used to make consts for statuses
type Status string
// IssueStats is the stats of a issue
type IssueStats struct {
TwentyFourHour *[]Stat `json:"24h,omitempty"`
FourteenDays *[]Stat `json:"14d,omitempty"`
ThirtyDays *[]Stat `json:"30d,omitempty"`
}
// IssueTagValue represents a tags value
type IssueTagValue struct {
Count *int64 `json:"count,omitempty"`
FirstSeen *time.Time `json:"firstSeen,omitempty"`
ID *string `json:"iD,omitempty"`
Key *string `json:"key,omitempty"`
LastSeen *time.Time `json:"lastSeen,omitempty"`
Name *string `json:"name,omitempty"`
Value *string `json:"value,omitempty"`
}
// IssueTag is a tag used in a sentry issue
type IssueTag struct {
UniqueValues int `json:"uniqueValues,omitempty"`
ID string `json:"id,omitempty"`
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
TopValues []IssueTagValue `json:"topValues,omitempty"`
}
// Avatar is used for a users avatar
type Avatar struct {
AvatarType *string `json:"avatarType,omitempty"`
AvatarUUID *string `json:"avatarUuid,omitempty"`
}
// InternalUser is a user on sentry and not a external customer
type InternalUser struct {
AvatarURL *string `json:"avatarUrl,omitempty"`
DateJoined *time.Time `json:"dateJoined,omitempty"`
Email *string `json:"email,omitempty"`
Has2FA *bool `json:"has2fa,omitempty"`
ID *string `json:"iD,omitempty"`
IsActive *bool `json:"isActive,omitempty"`
IsManaged *bool `json:"isManaged,omitempty"`
LastLogin *time.Time `json:"lastLogin,omitempty"`
Name *string `json:"name,omitempty"`
Username *string `json:"username,omitempty"`
}
// Activity is what current activity has happend on a issue
type Activity struct {
Data *map[string]interface{} `json:"data,omitempty"`
DateCreated *time.Time `json:"dateCreated,omitempty"`
ID *string `json:"id,omitempty"`
Type *string `json:"type,omitempty"`
User *InternalUser `json:"user,omitempty"`
}
// Issue returns a issue found in sentry
type Issue struct {
Annotations *[]string `json:"annotations,omitempty"`
AssignedTo *InternalUser `json:"assignedTo,omitempty"`
Activity *[]Activity `json:"activity,omitempty"`
Count *string `json:"count,omitempty"`
Culprit *string `json:"culprit,omitempty"`
FirstSeen *time.Time `json:"firstSeen,omitempty"`
HasSeen *bool `json:"hasSeen,omitempty"`
ID *string `json:"id,omitempty"`
IsBookmarked *bool `json:"isBookmarked,omitempty"`
IsPublic *bool `json:"isPublic,omitempty"`
IsSubscribed *bool `json:"isSubscribed,omitempty"`
LastSeen *time.Time `json:"lastSeen,omitempty"`
Level *string `json:"level,omitempty"`
Logger *string `json:"logger,omitempty"`
Metadata *map[string]interface{} `json:"metadata,omitempty"`
NumComments *int `json:"numComments,omitempty"`
Permalink *string `json:"permalink,omitempty"`
Project *Project `json:"project,omitempty"`
ShareID *string `json:"shareId,omitempty"`
ShortID *string `json:"shortId,omitempty"`
Stats *IssueStats `json:"stats,omitempty"`
Status *Status `json:"status,omitempty"`
StatusDetails *map[string]interface{} `json:"statusDetails,omitempty"`
SubscriptionDetails *map[string]string `json:"subscriptionDetails,omitempty"`
Tags *[]IssueTag `json:"tags,omitempty"`
Title *string `json:"title,omitempty"`
Type *string `json:"type,omitempty"`
UserCount *int `json:"userCount,omitempty"`
UserReportCount *int `json:"userReportCount,omitempty"`
}
type issueQuery struct {
StatsPeriod *string
ShortIDLookup *bool
Query *string
}
func (i *issueQuery) ToQueryString() string {
query := url.Values{}
if i.StatsPeriod != nil {
query.Add("statsPeriod", *i.StatsPeriod)
}
if i.ShortIDLookup != nil {
query.Add("shortIdLookup", strconv.FormatBool(*i.ShortIDLookup))
}
if i.Query != nil {
query.Add("query", *i.Query)
}
return query.Encode()
}
// GetIssues will fetch all issues for organization and project
func (c *Client) GetIssues(o Organization, p Project, StatsPeriod *string, ShortIDLookup *bool, query *string) ([]Issue, *Link, error) {
var issues []Issue
issueFilter := &issueQuery{
StatsPeriod: StatsPeriod,
ShortIDLookup: ShortIDLookup,
Query: query,
}
link, err := c.doWithPaginationQuery(
"GET", fmt.Sprintf("projects/%s/%s/issues", *o.Slug, *p.Slug), &issues, nil, issueFilter)
return issues, link, err
}
// GetIssue will fetch a issue by its ID as a string
func (c *Client) GetIssue(id string) (Issue, error) {
var issue Issue
err := c.do("GET", fmt.Sprintf("issues/%s", id), &issue, nil)
return issue, err
}
// GetIssueHashes will fetch all hashes for a issue
func (c *Client) GetIssueHashes(i Issue) ([]Hash, *Link, error) {
var hashes []Hash
link, err := c.doWithPagination("GET", fmt.Sprintf("issues/%s/hashes", *i.ID), &hashes, nil)
return hashes, link, err
}
// GetIssueTags will fetch all tags for a issue
func (c *Client) GetIssueTags(i Issue) ([]IssueTag, *Link, error) {
var tags []IssueTag
link, err := c.doWithPagination("GET", fmt.Sprintf("issues/%s/tags", *i.ID), &tags, nil)
return tags, link, err
}
// GetIssueTag will fetch a tag used in a issue. Eg; environment, release, server
func (c *Client) GetIssueTag(i Issue, tagname string) (IssueTag, error) {
var tag IssueTag
err := c.do("GET", fmt.Sprintf("issues/%s/tags/%s", *i.ID, tagname), &tag, nil)
return tag, err
}
// GetIssueTagValues will fetch all values for a issues tag
func (c *Client) GetIssueTagValues(i Issue, tag IssueTag) ([]IssueTagValue, *Link, error) {
var values []IssueTagValue
link, err := c.doWithPagination("GET", fmt.Sprintf("issues/%s/tags/%s/values", *i.ID, tag.Key), &values, nil)
return values, link, err
}
// GetIssueEvents will fetch all events for a issue
func (c *Client) GetIssueEvents(i Issue) ([]Event, *Link, error) {
var events []Event
link, err := c.doWithPagination("GET", fmt.Sprintf("issues/%s/events", *i.ID), &events, nil)
return events, link, err
}
// UpdateIssue will update status, assign to, hasseen, isbookmarked and issubscribed
func (c *Client) UpdateIssue(i Issue) error {
return c.do("PUT", fmt.Sprintf("issues/%s", *i.ID), &i, &i)
}
// DeleteIssue will delete an issue
func (c *Client) DeleteIssue(i Issue) error {
return c.do("DELETE", fmt.Sprintf("issues/%s", *i.ID), nil, nil)
}