forked from ktrysmt/go-bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhooks.go
66 lines (51 loc) · 1.57 KB
/
webhooks.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 bitbucket
import (
"encoding/json"
"os"
"github.com/k0kubun/pp"
)
type Webhooks struct {
c *Client
}
func (r *Webhooks) buildWebhooksBody(ro *WebhooksOptions) string {
body := map[string]interface{}{}
if ro.Description != "" {
body["description"] = ro.Description
}
if ro.Url != "" {
body["url"] = ro.Url
}
if ro.Active == true || ro.Active == false {
body["active"] = ro.Active
}
body["events"] = ro.Events
data, err := json.Marshal(body)
if err != nil {
pp.Println(err)
os.Exit(9)
}
return string(data)
}
func (r *Webhooks) Gets(ro *WebhooksOptions) (interface{}, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/hooks/", ro.Owner, ro.RepoSlug)
return r.c.execute("GET", urlStr, "")
}
func (r *Webhooks) Create(ro *WebhooksOptions) (interface{}, error) {
data := r.buildWebhooksBody(ro)
urlStr := r.c.requestUrl("/repositories/%s/%s/hooks", ro.Owner, ro.RepoSlug)
return r.c.execute("POST", urlStr, data)
}
func (r *Webhooks) Get(ro *WebhooksOptions) (interface{}, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/hooks/%s", ro.Owner, ro.RepoSlug, ro.Uuid)
return r.c.execute("GET", urlStr, "")
}
func (r *Webhooks) Update(ro *WebhooksOptions) (interface{}, error) {
data := r.buildWebhooksBody(ro)
urlStr := r.c.requestUrl("/repositories/%s/%s/hooks/%s", ro.Owner, ro.RepoSlug, ro.Uuid)
return r.c.execute("PUT", urlStr, data)
}
func (r *Webhooks) Delete(ro *WebhooksOptions) (interface{}, error) {
urlStr := r.c.requestUrl("/repositories/%s/%s/hooks/%s", ro.Owner, ro.RepoSlug, ro.Uuid)
return r.c.execute("DELETE", urlStr, "")
}
//