Unverified Commit b442f13a authored by Gautier de Saint Martin Lacaze's avatar Gautier de Saint Martin Lacaze Committed by GitHub
Browse files

Merge pull request #719 from gitlab4j/issue-649

Fix #649 : Add missing properties to SystemHook
parents 02864229 69413145
......@@ -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.
*
* <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) {
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));
}
......
......@@ -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));
......
......@@ -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<SystemHook> hooks = gitLabApi.getSystemHooksApi().getSystemHooks();
assertNotNull(hooks);
assertFalse(hooks.isEmpty());
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