-
Notifications
You must be signed in to change notification settings - Fork 2
/
webhook.go
75 lines (63 loc) · 2.39 KB
/
webhook.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
package buddy
import (
"net/http"
)
const (
WebhookEventPush = "PUSH"
WebhookEventExecutionStarted = "EXECUTION_STARTED"
WebhookEventExecutionSuccessful = "EXECUTION_SUCCESSFUL"
WebhookEventExecutionFailed = "EXECUTION_FAILED"
WebhookEventExecutionFinished = "EXECUTION_FINISHED"
)
type WebhookService struct {
client *Client
}
type Webhook struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Id int `json:"id"`
TargetUrl string `json:"target_url"`
SecretKey string `json:"secret_key"`
Projects []string `json:"projects"`
Events []string `json:"events"`
Requests []*WebhookRequest `json:"requests"`
}
type Webhooks struct {
Url string `json:"url"`
HtmlUrl string `json:"html_url"`
Webhooks []*Webhook `json:"webhooks"`
}
type WebhookRequest struct {
PostDate string `json:"post_date"`
ResponseStatus string `json:"response_status"`
Body string `json:"body"`
}
type WebhookOps struct {
Events *[]string `json:"events,omitempty"`
Projects *[]string `json:"projects,omitempty"`
TargetUrl *string `json:"target_url,omitempty"`
SecretKey *string `json:"secret_key,omitempty"`
}
func (s *WebhookService) Create(domain string, ops *WebhookOps) (*Webhook, *http.Response, error) {
var w *Webhook
resp, err := s.client.Create(s.client.NewUrlPath("/workspaces/%s/webhooks", domain), &ops, nil, &w)
return w, resp, err
}
func (s *WebhookService) Delete(domain string, webhookId int) (*http.Response, error) {
return s.client.Delete(s.client.NewUrlPath("/workspaces/%s/webhooks/%d", domain, webhookId), nil, nil)
}
func (s *WebhookService) Update(domain string, webhookId int, ops *WebhookOps) (*Webhook, *http.Response, error) {
var w *Webhook
resp, err := s.client.Patch(s.client.NewUrlPath("/workspaces/%s/webhooks/%d", domain, webhookId), &ops, nil, &w)
return w, resp, err
}
func (s *WebhookService) Get(domain string, webhookId int) (*Webhook, *http.Response, error) {
var w *Webhook
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/webhooks/%d", domain, webhookId), &w, nil)
return w, resp, err
}
func (s *WebhookService) GetList(domain string) (*Webhooks, *http.Response, error) {
var all *Webhooks
resp, err := s.client.Get(s.client.NewUrlPath("/workspaces/%s/webhooks", domain), &all, nil)
return all, resp, err
}