diff --git a/src/main/java/org/gitlab4j/api/SystemHooksApi.java b/src/main/java/org/gitlab4j/api/SystemHooksApi.java index cf5215bb17835ef2a34ec1d2323950e78a2c987f..7a1b6a6cf541c0789e19b840a63a529463d62e87 100644 --- a/src/main/java/org/gitlab4j/api/SystemHooksApi.java +++ b/src/main/java/org/gitlab4j/api/SystemHooksApi.java @@ -80,12 +80,32 @@ public class SystemHooksApi extends AbstractApi { * @param token secret token to validate received payloads, optional * @param pushEvents when true, the hook will fire on push events, optional * @param tagPushEvents when true, the hook will fire on new tags being pushed, optional - * @param enablSsslVerification do SSL verification when triggering the hook, optional + * @param enableSslVerification do SSL verification when triggering the hook, optional * @return an SystemHookEvent instance with info on the added system hook * @throws GitLabApiException if any exception occurs */ public SystemHook addSystemHook(String url, String token, Boolean pushEvents, - Boolean tagPushEvents, Boolean enablSsslVerification) throws GitLabApiException { + Boolean tagPushEvents, Boolean enableSslVerification) throws GitLabApiException { + + SystemHook systemHook = new SystemHook().withPushEvents(pushEvents) + .withTagPushEvents(tagPushEvents) + .withEnableSslVerification(enableSslVerification); + + return addSystemHook(url, token, systemHook); + } + + /** + * Add a new system hook. This method requires admin access. + * + *
GitLab Endpoint: POST /hooks
+ *
+ * @param url the hook URL, required
+ * @param token secret token to validate received payloads, optional
+ * @param systemHook the systemHook to create
+ * @return an SystemHookEvent instance with info on the added system hook
+ * @throws GitLabApiException if any exception occurs
+ */
+ public SystemHook addSystemHook(String url, String token, SystemHook systemHook) throws GitLabApiException {
if (url == null) {
throw new RuntimeException("url cannot be null");
@@ -94,9 +114,11 @@ public class SystemHooksApi extends AbstractApi {
GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true)
.withParam("token", token)
- .withParam("push_events", pushEvents)
- .withParam("tag_push_events", tagPushEvents)
- .withParam("enable_ssl_verification", enablSsslVerification);
+ .withParam("push_events", systemHook.getPushEvents())
+ .withParam("tag_push_events", systemHook.getTagPushEvents())
+ .withParam("merge_requests_events", systemHook.getMergeRequestsEvents())
+ .withParam("repository_update_events", systemHook.getRepositoryUpdateEvents())
+ .withParam("enable_ssl_verification", systemHook.getEnableSslVerification());
Response response = post(Response.Status.CREATED, formData, "hooks");
return (response.readEntity(SystemHook.class));
}
diff --git a/src/main/java/org/gitlab4j/api/models/SystemHook.java b/src/main/java/org/gitlab4j/api/models/SystemHook.java
index 81277a08889e9f45cdc6883fd9bc95b235560895..a83aa7eb938343cd2a0bfefce7da83c69e13889c 100644
--- a/src/main/java/org/gitlab4j/api/models/SystemHook.java
+++ b/src/main/java/org/gitlab4j/api/models/SystemHook.java
@@ -13,6 +13,7 @@ public class SystemHook {
private Boolean tagPushEvents;
private Boolean enableSslVerification;
private Boolean repositoryUpdateEvents;
+ private Boolean mergeRequestsEvents;
public Integer getId() {
return id;
@@ -70,6 +71,14 @@ public class SystemHook {
return repositoryUpdateEvents;
}
+ public void setMergeRequestsEvents(Boolean mergeRequestsEvents) {
+ this.mergeRequestsEvents = mergeRequestsEvents;
+ }
+
+ public Boolean getMergeRequestsEvents() {
+ return mergeRequestsEvents;
+ }
+
public SystemHook withId(Integer id) {
this.id = id;
return (this);
@@ -105,6 +114,11 @@ public class SystemHook {
return (this);
}
+ public SystemHook withMergeRequestsEvents(Boolean mergeRequestsEvents) {
+ this.mergeRequestsEvents = mergeRequestsEvents;
+ return (this);
+ }
+
@Override
public String toString() {
return (JacksonJson.toJsonString(this));
diff --git a/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java b/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java
index 6cfec9304fdbbaae3762a7ed698f30c9e7bfa713..f837291ba1c9af0fb8c3b418c9029a18030ea7ec 100644
--- a/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java
+++ b/src/test/java/org/gitlab4j/api/TestSystemHooksApi.java
@@ -63,13 +63,33 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
assertEquals(TEST_HOOK_URL, hook.getUrl());
assertTrue(hook.getPushEvents());
assertFalse(hook.getTagPushEvents());
+ assertFalse(hook.getMergeRequestsEvents());
+ assertFalse(hook.getRepositoryUpdateEvents());
assertTrue(hook.getEnableSslVerification());
-
+
+ gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
+
+ hook.withPushEvents(false)
+ .withTagPushEvents(true)
+ .withMergeRequestsEvents(true)
+ .withRepositoryUpdateEvents(true)
+ .withEnableSslVerification(false);
+
+ SystemHook updatedHook = gitLabApi.getSystemHooksApi().addSystemHook(TEST_HOOK_URL, TEST_SECRET_TOKEN, hook);
+ assertNotNull(updatedHook);
+ assertEquals(TEST_HOOK_URL, updatedHook.getUrl());
+ assertFalse(hook.getPushEvents());
+ assertTrue(hook.getTagPushEvents());
+ assertTrue(hook.getMergeRequestsEvents());
+ assertTrue(hook.getRepositoryUpdateEvents());
+ assertFalse(hook.getEnableSslVerification());
+
gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
+
}
@Test
- public void testGerSystemHooks() throws GitLabApiException {
+ public void testGetSystemHooks() throws GitLabApiException {
SystemHook hook = gitLabApi.getSystemHooksApi().addSystemHook(TEST_HOOK_URL, TEST_SECRET_TOKEN, true, false, true);
assertNotNull(hook);
@@ -77,7 +97,7 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
List