Skip to content

Commit 6941314

Browse files
committed
Fix #649 : Add missing properties to SystemHook
1 parent 0286422 commit 6941314

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

src/main/java/org/gitlab4j/api/SystemHooksApi.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,32 @@ public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
8080
* @param token secret token to validate received payloads, optional
8181
* @param pushEvents when true, the hook will fire on push events, optional
8282
* @param tagPushEvents when true, the hook will fire on new tags being pushed, optional
83-
* @param enablSsslVerification do SSL verification when triggering the hook, optional
83+
* @param enableSslVerification do SSL verification when triggering the hook, optional
8484
* @return an SystemHookEvent instance with info on the added system hook
8585
* @throws GitLabApiException if any exception occurs
8686
*/
8787
public SystemHook addSystemHook(String url, String token, Boolean pushEvents,
88-
Boolean tagPushEvents, Boolean enablSsslVerification) throws GitLabApiException {
88+
Boolean tagPushEvents, Boolean enableSslVerification) throws GitLabApiException {
89+
90+
SystemHook systemHook = new SystemHook().withPushEvents(pushEvents)
91+
.withTagPushEvents(tagPushEvents)
92+
.withEnableSslVerification(enableSslVerification);
93+
94+
return addSystemHook(url, token, systemHook);
95+
}
96+
97+
/**
98+
* Add a new system hook. This method requires admin access.
99+
*
100+
* <pre><code>GitLab Endpoint: POST /hooks</code></pre>
101+
*
102+
* @param url the hook URL, required
103+
* @param token secret token to validate received payloads, optional
104+
* @param systemHook the systemHook to create
105+
* @return an SystemHookEvent instance with info on the added system hook
106+
* @throws GitLabApiException if any exception occurs
107+
*/
108+
public SystemHook addSystemHook(String url, String token, SystemHook systemHook) throws GitLabApiException {
89109

90110
if (url == null) {
91111
throw new RuntimeException("url cannot be null");
@@ -94,9 +114,11 @@ public SystemHook addSystemHook(String url, String token, Boolean pushEvents,
94114
GitLabApiForm formData = new GitLabApiForm()
95115
.withParam("url", url, true)
96116
.withParam("token", token)
97-
.withParam("push_events", pushEvents)
98-
.withParam("tag_push_events", tagPushEvents)
99-
.withParam("enable_ssl_verification", enablSsslVerification);
117+
.withParam("push_events", systemHook.getPushEvents())
118+
.withParam("tag_push_events", systemHook.getTagPushEvents())
119+
.withParam("merge_requests_events", systemHook.getMergeRequestsEvents())
120+
.withParam("repository_update_events", systemHook.getRepositoryUpdateEvents())
121+
.withParam("enable_ssl_verification", systemHook.getEnableSslVerification());
100122
Response response = post(Response.Status.CREATED, formData, "hooks");
101123
return (response.readEntity(SystemHook.class));
102124
}

src/main/java/org/gitlab4j/api/models/SystemHook.java

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SystemHook {
1313
private Boolean tagPushEvents;
1414
private Boolean enableSslVerification;
1515
private Boolean repositoryUpdateEvents;
16+
private Boolean mergeRequestsEvents;
1617

1718
public Integer getId() {
1819
return id;
@@ -70,6 +71,14 @@ public Boolean getRepositoryUpdateEvents() {
7071
return repositoryUpdateEvents;
7172
}
7273

74+
public void setMergeRequestsEvents(Boolean mergeRequestsEvents) {
75+
this.mergeRequestsEvents = mergeRequestsEvents;
76+
}
77+
78+
public Boolean getMergeRequestsEvents() {
79+
return mergeRequestsEvents;
80+
}
81+
7382
public SystemHook withId(Integer id) {
7483
this.id = id;
7584
return (this);
@@ -105,6 +114,11 @@ public SystemHook withRepositoryUpdateEvents(Boolean repositoryUpdateEvents) {
105114
return (this);
106115
}
107116

117+
public SystemHook withMergeRequestsEvents(Boolean mergeRequestsEvents) {
118+
this.mergeRequestsEvents = mergeRequestsEvents;
119+
return (this);
120+
}
121+
108122
@Override
109123
public String toString() {
110124
return (JacksonJson.toJsonString(this));

src/test/java/org/gitlab4j/api/TestSystemHooksApi.java

+23-3
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,41 @@ public void testAddSystemHook() throws GitLabApiException {
6363
assertEquals(TEST_HOOK_URL, hook.getUrl());
6464
assertTrue(hook.getPushEvents());
6565
assertFalse(hook.getTagPushEvents());
66+
assertFalse(hook.getMergeRequestsEvents());
67+
assertFalse(hook.getRepositoryUpdateEvents());
6668
assertTrue(hook.getEnableSslVerification());
67-
69+
70+
gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
71+
72+
hook.withPushEvents(false)
73+
.withTagPushEvents(true)
74+
.withMergeRequestsEvents(true)
75+
.withRepositoryUpdateEvents(true)
76+
.withEnableSslVerification(false);
77+
78+
SystemHook updatedHook = gitLabApi.getSystemHooksApi().addSystemHook(TEST_HOOK_URL, TEST_SECRET_TOKEN, hook);
79+
assertNotNull(updatedHook);
80+
assertEquals(TEST_HOOK_URL, updatedHook.getUrl());
81+
assertFalse(hook.getPushEvents());
82+
assertTrue(hook.getTagPushEvents());
83+
assertTrue(hook.getMergeRequestsEvents());
84+
assertTrue(hook.getRepositoryUpdateEvents());
85+
assertFalse(hook.getEnableSslVerification());
86+
6887
gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
88+
6989
}
7090

7191
@Test
72-
public void testGerSystemHooks() throws GitLabApiException {
92+
public void testGetSystemHooks() throws GitLabApiException {
7393

7494
SystemHook hook = gitLabApi.getSystemHooksApi().addSystemHook(TEST_HOOK_URL, TEST_SECRET_TOKEN, true, false, true);
7595
assertNotNull(hook);
7696

7797
List<SystemHook> hooks = gitLabApi.getSystemHooksApi().getSystemHooks();
7898
assertNotNull(hooks);
7999
assertFalse(hooks.isEmpty());
80-
100+
81101
gitLabApi.getSystemHooksApi().deleteSystemHook(hook);
82102
}
83103
}

0 commit comments

Comments
 (0)