-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathwebhook.go
More file actions
144 lines (120 loc) · 4.77 KB
/
webhook.go
File metadata and controls
144 lines (120 loc) · 4.77 KB
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
package backlog
import (
"context"
"fmt"
)
// Webhook : -
type Webhook struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
HookURL *string `json:"hookUrl,omitempty"`
AllEvent *bool `json:"allEvent,omitempty"`
// revive:disable-next-line var-naming
ActivityTypeIds []int `json:"activityTypeIds,omitempty"`
CreatedUser *User `json:"createdUser,omitempty"`
Created *Timestamp `json:"created,omitempty"`
UpdatedUser *User `json:"updatedUser,omitempty"`
Updated *Timestamp `json:"updated,omitempty"`
}
// GetWebhook returns the list of webhooks
func (c *Client) GetWebhook(projectIDOrKey interface{}, webhookID int) (*Webhook, error) {
return c.GetWebhookContext(context.Background(), projectIDOrKey, webhookID)
}
// GetWebhookContext returns the list of webhooks with context
func (c *Client) GetWebhookContext(ctx context.Context, projectIDOrKey interface{}, webhookID int) (*Webhook, error) {
u := fmt.Sprintf("/api/v2/projects/%v/webhooks/%v", projectIDOrKey, webhookID)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
webhook := new(Webhook)
if err := c.Do(ctx, req, &webhook); err != nil {
return nil, err
}
return webhook, nil
}
// GetWebhooks returns the list of webhooks
func (c *Client) GetWebhooks(projectIDOrKey interface{}) ([]*Webhook, error) {
return c.GetWebhooksContext(context.Background(), projectIDOrKey)
}
// GetWebhooksContext returns the list of webhooks with context
func (c *Client) GetWebhooksContext(ctx context.Context, projectIDOrKey interface{}) ([]*Webhook, error) {
u := fmt.Sprintf("/api/v2/projects/%v/webhooks", projectIDOrKey)
req, err := c.NewRequest("GET", u, nil)
if err != nil {
return nil, err
}
webhooks := []*Webhook{}
if err := c.Do(ctx, req, &webhooks); err != nil {
return nil, err
}
return webhooks, nil
}
// CreateWebhook adds a webhook
func (c *Client) CreateWebhook(projectIDOrKey interface{}, webhook *CreateWebhookInput) (*Webhook, error) {
return c.CreateWebhookContext(context.Background(), projectIDOrKey, webhook)
}
// CreateWebhookContext adds a webhook with context
func (c *Client) CreateWebhookContext(ctx context.Context, projectIDOrKey interface{}, input *CreateWebhookInput) (*Webhook, error) {
u := fmt.Sprintf("/api/v2/projects/%v/webhooks", projectIDOrKey)
req, err := c.NewRequest("POST", u, input)
if err != nil {
return nil, err
}
webhook := new(Webhook)
if err := c.Do(ctx, req, &webhook); err != nil {
return nil, err
}
return webhook, nil
}
// UpdateWebhook updates a webhook
func (c *Client) UpdateWebhook(projectIDOrKey interface{}, webhookID int, input *UpdateWebhookInput) (*Webhook, error) {
return c.UpdateWebhookContext(context.Background(), projectIDOrKey, webhookID, input)
}
// UpdateWebhookContext updates a webhook with context
func (c *Client) UpdateWebhookContext(ctx context.Context, projectIDOrKey interface{}, webhookID int, input *UpdateWebhookInput) (*Webhook, error) {
u := fmt.Sprintf("/api/v2/projects/%v/webhooks/%v", projectIDOrKey, webhookID)
req, err := c.NewRequest("PATCH", u, input)
if err != nil {
return nil, err
}
webhook := new(Webhook)
if err := c.Do(ctx, req, &webhook); err != nil {
return nil, err
}
return webhook, nil
}
// DeleteWebhook deletes a webhook
func (c *Client) DeleteWebhook(projectIDOrKey interface{}, webhookID int) (*Webhook, error) {
return c.DeleteWebhookContext(context.Background(), projectIDOrKey, webhookID)
}
// DeleteWebhookContext updates a webhook with context
func (c *Client) DeleteWebhookContext(ctx context.Context, projectIDOrKey interface{}, webhookID int) (*Webhook, error) {
u := fmt.Sprintf("/api/v2/projects/%v/webhooks/%v", projectIDOrKey, webhookID)
req, err := c.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
webhook := new(Webhook)
if err := c.Do(ctx, req, &webhook); err != nil {
return nil, err
}
return webhook, nil
}
// CreateWebhookInput contains all the parameters necessary (including the optional ones) for a CreateWebhook() request.
type CreateWebhookInput struct {
Name *string `json:"name"`
Description *string `json:"description,omitempty"`
HookURL *string `json:"hookUrl"`
AllEvent *bool `json:"allEvent,omitempty"`
ActivityTypeIDs []int `json:"activityTypeIds,omitempty"`
}
// UpdateWebhookInput contains all the parameters necessary (including the optional ones) for a UpdateWebhook() request.
type UpdateWebhookInput struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
HookURL *string `json:"hookUrl,omitempty"`
AllEvent *bool `json:"allEvent,omitempty"`
ActivityTypeIDs []int `json:"activityTypeIds,omitempty"`
}