Unverified Commit 69413145 authored by Gautier de Saint Martin Lacaze's avatar Gautier de Saint Martin Lacaze
Browse files

Fix #649 : Add missing properties to SystemHook

parent 02864229
...@@ -80,12 +80,32 @@ public class SystemHooksApi extends AbstractApi { ...@@ -80,12 +80,32 @@ public class SystemHooksApi extends AbstractApi {
* @param token secret token to validate received payloads, optional * @param token secret token to validate received payloads, optional
* @param pushEvents when true, the hook will fire on push events, 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 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 * @return an SystemHookEvent instance with info on the added system hook
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public SystemHook addSystemHook(String url, String token, Boolean pushEvents, 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.
*
* <pre><code>GitLab Endpoint: POST /hooks</code></pre>
*
* @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) { if (url == null) {
throw new RuntimeException("url cannot be null"); throw new RuntimeException("url cannot be null");
...@@ -94,9 +114,11 @@ public class SystemHooksApi extends AbstractApi { ...@@ -94,9 +114,11 @@ public class SystemHooksApi extends AbstractApi {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("url", url, true) .withParam("url", url, true)
.withParam("token", token) .withParam("token", token)
.withParam("push_events", pushEvents) .withParam("push_events", systemHook.getPushEvents())
.withParam("tag_push_events", tagPushEvents) .withParam("tag_push_events", systemHook.getTagPushEvents())
.withParam("enable_ssl_verification", enablSsslVerification); .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"); Response response = post(Response.Status.CREATED, formData, "hooks");
return (response.readEntity(SystemHook.class)); return (response.readEntity(SystemHook.class));
} }
......
...@@ -13,6 +13,7 @@ public class SystemHook { ...@@ -13,6 +13,7 @@ public class SystemHook {
private Boolean tagPushEvents; private Boolean tagPushEvents;
private Boolean enableSslVerification; private Boolean enableSslVerification;
private Boolean repositoryUpdateEvents; private Boolean repositoryUpdateEvents;
private Boolean mergeRequestsEvents;
public Integer getId() { public Integer getId() {
return id; return id;
...@@ -70,6 +71,14 @@ public class SystemHook { ...@@ -70,6 +71,14 @@ public class SystemHook {
return repositoryUpdateEvents; return repositoryUpdateEvents;
} }
public void setMergeRequestsEvents(Boolean mergeRequestsEvents) {
this.mergeRequestsEvents = mergeRequestsEvents;
}
public Boolean getMergeRequestsEvents() {
return mergeRequestsEvents;
}
public SystemHook withId(Integer id) { public SystemHook withId(Integer id) {
this.id = id; this.id = id;
return (this); return (this);
...@@ -105,6 +114,11 @@ public class SystemHook { ...@@ -105,6 +114,11 @@ public class SystemHook {
return (this); return (this);
} }
public SystemHook withMergeRequestsEvents(Boolean mergeRequestsEvents) {
this.mergeRequestsEvents = mergeRequestsEvents;
return (this);
}
@Override @Override
public String toString() { public String toString() {
return (JacksonJson.toJsonString(this)); return (JacksonJson.toJsonString(this));
......
...@@ -63,13 +63,33 @@ public class TestSystemHooksApi extends AbstractIntegrationTest { ...@@ -63,13 +63,33 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
assertEquals(TEST_HOOK_URL, hook.getUrl()); assertEquals(TEST_HOOK_URL, hook.getUrl());
assertTrue(hook.getPushEvents()); assertTrue(hook.getPushEvents());
assertFalse(hook.getTagPushEvents()); assertFalse(hook.getTagPushEvents());
assertFalse(hook.getMergeRequestsEvents());
assertFalse(hook.getRepositoryUpdateEvents());
assertTrue(hook.getEnableSslVerification()); 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); gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
} }
@Test @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); SystemHook hook = gitLabApi.getSystemHooksApi().addSystemHook(TEST_HOOK_URL, TEST_SECRET_TOKEN, true, false, true);
assertNotNull(hook); assertNotNull(hook);
...@@ -77,7 +97,7 @@ public class TestSystemHooksApi extends AbstractIntegrationTest { ...@@ -77,7 +97,7 @@ public class TestSystemHooksApi extends AbstractIntegrationTest {
List<SystemHook> hooks = gitLabApi.getSystemHooksApi().getSystemHooks(); List<SystemHook> hooks = gitLabApi.getSystemHooksApi().getSystemHooks();
assertNotNull(hooks); assertNotNull(hooks);
assertFalse(hooks.isEmpty()); assertFalse(hooks.isEmpty());
gitLabApi.getSystemHooksApi().deleteSystemHook(hook); gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment