-
Notifications
You must be signed in to change notification settings - Fork 39
/
bulk.go
66 lines (56 loc) · 1.85 KB
/
bulk.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
package sentry
import (
"fmt"
"net/url"
)
// IssueBulkRequest is what should be used when bulk mutate issue
type IssueBulkRequest struct {
Status *Status `json:"status,omitempty"`
IgnoreDuration *int `json:"ignoreDuration,omitempty"`
IsPublic *bool `json:"isPublic,omitempty"`
Merge *bool `json:"merge,omitempty"`
HasSeen *bool `json:"hasSeen,omitempty"`
IsBookmarked *bool `json:"isBookmarked,omitempty"`
}
// IssueBulkResponse is what is returned when your mutation is done
type IssueBulkResponse struct {
Status *Status `json:"status,omitempty"`
IsPublic *bool `json:"isPublic,omitempty"`
StatusDetails *map[string]string `json:"statusDetails,omitempty"`
}
// issueMutateArgs
type issueMutateArgs struct {
ID *[]string
Status *Status
}
func (i *issueMutateArgs) ToQueryString() string {
query := url.Values{}
if i.ID != nil {
for _, id := range *i.ID {
query.Add("id", id)
}
}
if i.Status != nil {
query.Add("status", string(*i.Status))
}
return query.Encode()
}
// BulkMutateIssues takes a list of ids and optional status to filter through
func (c *Client) BulkMutateIssues(o Organization, p Project, req IssueBulkRequest, issues *[]string, status *Status) (IssueBulkResponse, error) {
var issueBulkResponse IssueBulkResponse
mutatequery := &issueMutateArgs{
ID: issues,
Status: status,
}
err := c.doWithQuery("PUT", fmt.Sprintf("projects/%s/%s/issues", *o.Slug, *p.Slug),
&issueBulkResponse, req, mutatequery)
return issueBulkResponse, err
}
// BulkDeleteIssues takes a list of IDs and will delete them
func (c *Client) BulkDeleteIssues(o Organization, p Project, issues []string) error {
mutateQuery := &issueMutateArgs{
ID: &issues,
}
return c.doWithQuery("DELETE", fmt.Sprintf("projects/%s/%s/issues", *o.Slug, *p.Slug),
nil, nil, mutateQuery)
}