1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "time"
23 )
24
25
26
27
28
29 type SystemHooksService struct {
30 client *Client
31 }
32
33
34
35
36 type Hook struct {
37 ID int `json:"id"`
38 URL string `json:"url"`
39 CreatedAt *time.Time `json:"created_at"`
40 PushEvents bool `json:"push_events"`
41 TagPushEvents bool `json:"tag_push_events"`
42 MergeRequestsEvents bool `json:"merge_requests_events"`
43 RepositoryUpdateEvents bool `json:"repository_update_events"`
44 EnableSSLVerification bool `json:"enable_ssl_verification"`
45 }
46
47 func (h Hook) String() string {
48 return Stringify(h)
49 }
50
51
52
53
54
55 func (s *SystemHooksService) ListHooks(options ...RequestOptionFunc) ([]*Hook, *Response, error) {
56 req, err := s.client.NewRequest(http.MethodGet, "hooks", nil, options)
57 if err != nil {
58 return nil, nil, err
59 }
60
61 var h []*Hook
62 resp, err := s.client.Do(req, &h)
63 if err != nil {
64 return nil, resp, err
65 }
66
67 return h, resp, nil
68 }
69
70
71
72
73
74 func (s *SystemHooksService) GetHook(hook int, options ...RequestOptionFunc) (*Hook, *Response, error) {
75 u := fmt.Sprintf("hooks/%d", hook)
76
77 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
78 if err != nil {
79 return nil, nil, err
80 }
81
82 var h *Hook
83 resp, err := s.client.Do(req, &h)
84 if err != nil {
85 return nil, resp, err
86 }
87
88 return h, resp, nil
89 }
90
91
92
93
94
95 type AddHookOptions struct {
96 URL *string `url:"url,omitempty" json:"url,omitempty"`
97 Token *string `url:"token,omitempty" json:"token,omitempty"`
98 PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
99 TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
100 MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
101 RepositoryUpdateEvents *bool `url:"repository_update_events,omitempty" json:"repository_update_events,omitempty"`
102 EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
103 }
104
105
106
107
108
109 func (s *SystemHooksService) AddHook(opt *AddHookOptions, options ...RequestOptionFunc) (*Hook, *Response, error) {
110 req, err := s.client.NewRequest(http.MethodPost, "hooks", opt, options)
111 if err != nil {
112 return nil, nil, err
113 }
114
115 h := new(Hook)
116 resp, err := s.client.Do(req, h)
117 if err != nil {
118 return nil, resp, err
119 }
120
121 return h, resp, nil
122 }
123
124
125
126
127 type HookEvent struct {
128 EventName string `json:"event_name"`
129 Name string `json:"name"`
130 Path string `json:"path"`
131 ProjectID int `json:"project_id"`
132 OwnerName string `json:"owner_name"`
133 OwnerEmail string `json:"owner_email"`
134 }
135
136 func (h HookEvent) String() string {
137 return Stringify(h)
138 }
139
140
141
142
143
144 func (s *SystemHooksService) TestHook(hook int, options ...RequestOptionFunc) (*HookEvent, *Response, error) {
145 u := fmt.Sprintf("hooks/%d", hook)
146
147 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
148 if err != nil {
149 return nil, nil, err
150 }
151
152 h := new(HookEvent)
153 resp, err := s.client.Do(req, h)
154 if err != nil {
155 return nil, resp, err
156 }
157
158 return h, resp, nil
159 }
160
161
162
163
164
165
166
167 func (s *SystemHooksService) DeleteHook(hook int, options ...RequestOptionFunc) (*Response, error) {
168 u := fmt.Sprintf("hooks/%d", hook)
169
170 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
171 if err != nil {
172 return nil, err
173 }
174
175 return s.client.Do(req, nil)
176 }
177
View as plain text