1
2
3
4
5
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13
14
15
16 func (s *OrganizationsService) ListHooks(ctx context.Context, org string, opts *ListOptions) ([]*Hook, *Response, error) {
17 u := fmt.Sprintf("orgs/%v/hooks", org)
18 u, err := addOptions(u, opts)
19 if err != nil {
20 return nil, nil, err
21 }
22
23 req, err := s.client.NewRequest("GET", u, nil)
24 if err != nil {
25 return nil, nil, err
26 }
27
28 var hooks []*Hook
29 resp, err := s.client.Do(ctx, req, &hooks)
30 if err != nil {
31 return nil, resp, err
32 }
33
34 return hooks, resp, nil
35 }
36
37
38
39
40 func (s *OrganizationsService) GetHook(ctx context.Context, org string, id int64) (*Hook, *Response, error) {
41 u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
42 req, err := s.client.NewRequest("GET", u, nil)
43 if err != nil {
44 return nil, nil, err
45 }
46 hook := new(Hook)
47 resp, err := s.client.Do(ctx, req, hook)
48 return hook, resp, err
49 }
50
51
52
53
54
55
56
57
58 func (s *OrganizationsService) CreateHook(ctx context.Context, org string, hook *Hook) (*Hook, *Response, error) {
59 u := fmt.Sprintf("orgs/%v/hooks", org)
60
61 hookReq := &createHookRequest{
62 Name: "web",
63 Events: hook.Events,
64 Active: hook.Active,
65 Config: hook.Config,
66 }
67
68 req, err := s.client.NewRequest("POST", u, hookReq)
69 if err != nil {
70 return nil, nil, err
71 }
72
73 h := new(Hook)
74 resp, err := s.client.Do(ctx, req, h)
75 if err != nil {
76 return nil, resp, err
77 }
78
79 return h, resp, nil
80 }
81
82
83
84
85 func (s *OrganizationsService) EditHook(ctx context.Context, org string, id int64, hook *Hook) (*Hook, *Response, error) {
86 u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
87 req, err := s.client.NewRequest("PATCH", u, hook)
88 if err != nil {
89 return nil, nil, err
90 }
91 h := new(Hook)
92 resp, err := s.client.Do(ctx, req, h)
93 return h, resp, err
94 }
95
96
97
98
99 func (s *OrganizationsService) PingHook(ctx context.Context, org string, id int64) (*Response, error) {
100 u := fmt.Sprintf("orgs/%v/hooks/%d/pings", org, id)
101 req, err := s.client.NewRequest("POST", u, nil)
102 if err != nil {
103 return nil, err
104 }
105 return s.client.Do(ctx, req, nil)
106 }
107
108
109
110
111 func (s *OrganizationsService) DeleteHook(ctx context.Context, org string, id int64) (*Response, error) {
112 u := fmt.Sprintf("orgs/%v/hooks/%d", org, id)
113 req, err := s.client.NewRequest("DELETE", u, nil)
114 if err != nil {
115 return nil, err
116 }
117 return s.client.Do(ctx, req, nil)
118 }
119
View as plain text