@@ -23,7 +23,7 @@ public SystemHooksApi(GitLabApi gitLabApi) {
23
23
*
24
24
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
25
25
*
26
- * @return a list of SystemHookEvent
26
+ * @return a list of SystemHook
27
27
* @throws GitLabApiException if any exception occurs
28
28
*/
29
29
public List <SystemHook > getSystemHooks () throws GitLabApiException {
@@ -38,7 +38,7 @@ public List<SystemHook> getSystemHooks() throws GitLabApiException {
38
38
*
39
39
* @param page the page to get
40
40
* @param perPage the number of deploy keys per page
41
- * @return the list of SystemHookEvent in the specified range
41
+ * @return the list of SystemHook in the specified range
42
42
* @throws GitLabApiException if any exception occurs
43
43
*/
44
44
public List <SystemHook > getSystemHooks (int page , int perPage ) throws GitLabApiException {
@@ -51,8 +51,8 @@ public List<SystemHook> getSystemHooks(int page, int perPage) throws GitLabApiEx
51
51
*
52
52
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
53
53
*
54
- * @param itemsPerPage the number of SystemHookEvent instances that will be fetched per page
55
- * @return a Pager of SystemHookEvent
54
+ * @param itemsPerPage the number of SystemHook instances that will be fetched per page
55
+ * @return a Pager of SystemHook
56
56
* @throws GitLabApiException if any exception occurs
57
57
*/
58
58
public Pager <SystemHook > getSystemHooks (int itemsPerPage ) throws GitLabApiException {
@@ -64,13 +64,27 @@ public Pager<SystemHook> getSystemHooks(int itemsPerPage) throws GitLabApiExcept
64
64
*
65
65
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
66
66
*
67
- * @return a Stream of SystemHookEvent
67
+ * @return a Stream of SystemHook
68
68
* @throws GitLabApiException if any exception occurs
69
69
*/
70
70
public Stream <SystemHook > getSystemHookStream () throws GitLabApiException {
71
71
return (getSystemHooks (getDefaultPerPage ()).stream ());
72
72
}
73
73
74
+ /**
75
+ * Get a list of all system hooks. This method requires admin access.
76
+ *
77
+ * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
78
+ *
79
+ * @param hookId the ID of the system hook.
80
+ * @return the SystemHook
81
+ * @throws GitLabApiException if any exception occurs
82
+ */
83
+ public SystemHook getSystemHook (Long hookId ) throws GitLabApiException {
84
+ Response response = get (Response .Status .OK , null , "hooks" , hookId );
85
+ return response .readEntity (SystemHook .class );
86
+ }
87
+
74
88
/**
75
89
* Add a new system hook. This method requires admin access.
76
90
*
@@ -81,7 +95,7 @@ public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
81
95
* @param pushEvents when true, the hook will fire on push events, optional
82
96
* @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
83
97
* @param enableSslVerification do SSL verification when triggering the hook, optional
84
- * @return an SystemHookEvent instance with info on the added system hook
98
+ * @return an SystemHook instance with info on the added system hook
85
99
* @throws GitLabApiException if any exception occurs
86
100
*/
87
101
public SystemHook addSystemHook (
@@ -104,7 +118,7 @@ public SystemHook addSystemHook(
104
118
* @param url the hook URL, required
105
119
* @param token secret token to validate received payloads, optional
106
120
* @param systemHook the systemHook to create
107
- * @return an SystemHookEvent instance with info on the added system hook
121
+ * @return an SystemHook instance with info on the added system hook
108
122
* @throws GitLabApiException if any exception occurs
109
123
*/
110
124
public SystemHook addSystemHook (String url , String token , SystemHook systemHook ) throws GitLabApiException {
@@ -116,6 +130,8 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
116
130
GitLabApiForm formData = new GitLabApiForm ()
117
131
.withParam ("url" , url , true )
118
132
.withParam ("token" , token )
133
+ .withParam ("name" , systemHook .getName ())
134
+ .withParam ("description" , systemHook .getDescription ())
119
135
.withParam ("push_events" , systemHook .getPushEvents ())
120
136
.withParam ("tag_push_events" , systemHook .getTagPushEvents ())
121
137
.withParam ("merge_requests_events" , systemHook .getMergeRequestsEvents ())
@@ -125,6 +141,36 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
125
141
return (response .readEntity (SystemHook .class ));
126
142
}
127
143
144
+ /**
145
+ * Add a new system hook. This method requires admin access.
146
+ *
147
+ * <pre><code>GitLab Endpoint: PUT /hooks/:hook_id</code></pre>
148
+ *
149
+ * @param systemHook the systemHook to update
150
+ * @param token secret token to validate received payloads, optional
151
+ * @return an SystemHook instance with info on the added system hook
152
+ * @throws GitLabApiException if any exception occurs
153
+ */
154
+ public SystemHook updateSystemHook (SystemHook systemHook , String token ) throws GitLabApiException {
155
+
156
+ if (systemHook .getId () == null ) {
157
+ throw new RuntimeException ("systemHook id cannot be null" );
158
+ }
159
+
160
+ GitLabApiForm formData = new GitLabApiForm ()
161
+ .withParam ("url" , systemHook .getUrl ())
162
+ .withParam ("token" , token )
163
+ .withParam ("name" , systemHook .getName ())
164
+ .withParam ("description" , systemHook .getDescription ())
165
+ .withParam ("push_events" , systemHook .getPushEvents ())
166
+ .withParam ("tag_push_events" , systemHook .getTagPushEvents ())
167
+ .withParam ("merge_requests_events" , systemHook .getMergeRequestsEvents ())
168
+ .withParam ("repository_update_events" , systemHook .getRepositoryUpdateEvents ())
169
+ .withParam ("enable_ssl_verification" , systemHook .getEnableSslVerification ());
170
+ Response response = putWithFormData (Response .Status .OK , formData , "hooks" , systemHook .getId ());
171
+ return (response .readEntity (SystemHook .class ));
172
+ }
173
+
128
174
/**
129
175
* Deletes a system hook. This method requires admin access.
130
176
*
@@ -166,7 +212,7 @@ public void deleteSystemHook(Long hookId) throws GitLabApiException {
166
212
*
167
213
* <pre><code>GitLab Endpoint: GET /hooks/:hook_id</code></pre>
168
214
*
169
- * @param hook the SystemHookEvent instance to test
215
+ * @param hook the SystemHook instance to test
170
216
* @throws GitLabApiException if any exception occurs
171
217
*/
172
218
public void testSystemHook (SystemHook hook ) throws GitLabApiException {
@@ -194,4 +240,32 @@ public void testSystemHook(Long hookId) throws GitLabApiException {
194
240
195
241
get (Response .Status .OK , null , "hooks" , hookId );
196
242
}
243
+
244
+ /**
245
+ * Add a new URL variable.
246
+ *
247
+ * <pre><code>GitLab Endpoint: PUT /hooks/:hook_id/url_variables/:key</code></pre>
248
+ *
249
+ * @param hookId the ID of the system hook
250
+ * @param key Key of the URL variable
251
+ * @param value Value of the URL variable.
252
+ * @throws GitLabApiException if any exception occurs
253
+ */
254
+ public void addSystemHookUrlVariable (Long hookId , String key , String value ) throws GitLabApiException {
255
+ GitLabApiForm formData = new GitLabApiForm ().withParam ("value" , value , true );
256
+ put (Response .Status .CREATED , formData .asMap (), "hooks" , hookId , "url_variables" , key );
257
+ }
258
+
259
+ /**
260
+ * Delete a URL variable.
261
+ *
262
+ * <pre><code>GitLab Endpoint: DELETE /hooks/:hook_id/url_variables/:key</code></pre>
263
+ *
264
+ * @param hookId the ID of the system hook
265
+ * @param key Key of the URL variable
266
+ * @throws GitLabApiException if any exception occurs
267
+ */
268
+ public void deleteSystemHookUrlVariable (Long hookId , String key ) throws GitLabApiException {
269
+ delete (Response .Status .NO_CONTENT , null , "hooks" , hookId , "url_variables" , key );
270
+ }
197
271
}
0 commit comments