@@ -23,7 +23,7 @@ public SystemHooksApi(GitLabApi gitLabApi) {
2323 *
2424 * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
2525 *
26- * @return a list of SystemHookEvent
26+ * @return a list of SystemHook
2727 * @throws GitLabApiException if any exception occurs
2828 */
2929 public List <SystemHook > getSystemHooks () throws GitLabApiException {
@@ -38,7 +38,7 @@ public List<SystemHook> getSystemHooks() throws GitLabApiException {
3838 *
3939 * @param page the page to get
4040 * @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
4242 * @throws GitLabApiException if any exception occurs
4343 */
4444 public List <SystemHook > getSystemHooks (int page , int perPage ) throws GitLabApiException {
@@ -51,8 +51,8 @@ public List<SystemHook> getSystemHooks(int page, int perPage) throws GitLabApiEx
5151 *
5252 * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
5353 *
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
5656 * @throws GitLabApiException if any exception occurs
5757 */
5858 public Pager <SystemHook > getSystemHooks (int itemsPerPage ) throws GitLabApiException {
@@ -64,13 +64,27 @@ public Pager<SystemHook> getSystemHooks(int itemsPerPage) throws GitLabApiExcept
6464 *
6565 * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
6666 *
67- * @return a Stream of SystemHookEvent
67+ * @return a Stream of SystemHook
6868 * @throws GitLabApiException if any exception occurs
6969 */
7070 public Stream <SystemHook > getSystemHookStream () throws GitLabApiException {
7171 return (getSystemHooks (getDefaultPerPage ()).stream ());
7272 }
7373
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+
7488 /**
7589 * Add a new system hook. This method requires admin access.
7690 *
@@ -81,7 +95,7 @@ public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
8195 * @param pushEvents when true, the hook will fire on push events, optional
8296 * @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
8397 * @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
8599 * @throws GitLabApiException if any exception occurs
86100 */
87101 public SystemHook addSystemHook (
@@ -104,7 +118,7 @@ public SystemHook addSystemHook(
104118 * @param url the hook URL, required
105119 * @param token secret token to validate received payloads, optional
106120 * @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
108122 * @throws GitLabApiException if any exception occurs
109123 */
110124 public SystemHook addSystemHook (String url , String token , SystemHook systemHook ) throws GitLabApiException {
@@ -116,6 +130,8 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
116130 GitLabApiForm formData = new GitLabApiForm ()
117131 .withParam ("url" , url , true )
118132 .withParam ("token" , token )
133+ .withParam ("name" , systemHook .getName ())
134+ .withParam ("description" , systemHook .getDescription ())
119135 .withParam ("push_events" , systemHook .getPushEvents ())
120136 .withParam ("tag_push_events" , systemHook .getTagPushEvents ())
121137 .withParam ("merge_requests_events" , systemHook .getMergeRequestsEvents ())
@@ -125,6 +141,36 @@ public SystemHook addSystemHook(String url, String token, SystemHook systemHook)
125141 return (response .readEntity (SystemHook .class ));
126142 }
127143
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+
128174 /**
129175 * Deletes a system hook. This method requires admin access.
130176 *
@@ -166,7 +212,7 @@ public void deleteSystemHook(Long hookId) throws GitLabApiException {
166212 *
167213 * <pre><code>GitLab Endpoint: GET /hooks/:hook_id</code></pre>
168214 *
169- * @param hook the SystemHookEvent instance to test
215+ * @param hook the SystemHook instance to test
170216 * @throws GitLabApiException if any exception occurs
171217 */
172218 public void testSystemHook (SystemHook hook ) throws GitLabApiException {
@@ -194,4 +240,32 @@ public void testSystemHook(Long hookId) throws GitLabApiException {
194240
195241 get (Response .Status .OK , null , "hooks" , hookId );
196242 }
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+ }
197271}
0 commit comments