Skip to content

Commit ba5ad9d

Browse files
committed
feat: create group webhook #1173
1 parent 6e5e2e6 commit ba5ad9d

File tree

4 files changed

+490
-18
lines changed

4 files changed

+490
-18
lines changed

Diff for: src/main/java/org/gitlab4j/api/GroupApi.java

+16-18
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,8 @@
1616
import javax.ws.rs.core.Response;
1717

1818
import org.gitlab4j.api.GitLabApi.ApiVersion;
19-
import org.gitlab4j.api.models.AccessLevel;
20-
import org.gitlab4j.api.models.AccessRequest;
21-
import org.gitlab4j.api.models.AuditEvent;
22-
import org.gitlab4j.api.models.Badge;
23-
import org.gitlab4j.api.models.CustomAttribute;
24-
import org.gitlab4j.api.models.Group;
25-
import org.gitlab4j.api.models.GroupAccessToken;
26-
import org.gitlab4j.api.models.GroupFilter;
27-
import org.gitlab4j.api.models.GroupParams;
28-
import org.gitlab4j.api.models.GroupProjectsFilter;
19+
import org.gitlab4j.api.models.*;
2920
import org.gitlab4j.api.models.ImpersonationToken.Scope;
30-
import org.gitlab4j.api.models.Iteration;
31-
import org.gitlab4j.api.models.IterationFilter;
32-
import org.gitlab4j.api.models.LdapGroupLink;
33-
import org.gitlab4j.api.models.Member;
34-
import org.gitlab4j.api.models.Project;
35-
import org.gitlab4j.api.models.SamlGroupLink;
36-
import org.gitlab4j.api.models.Variable;
37-
import org.gitlab4j.api.models.Visibility;
3821
import org.gitlab4j.api.utils.ISO8601;
3922

4023
/**
@@ -2440,4 +2423,19 @@ public GroupAccessToken rotateGroupAccessToken(Object groupIdOrPath, Long tokenI
24402423
public void revokeGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException {
24412424
delete(Response.Status.NO_CONTENT, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId);
24422425
}
2426+
2427+
/**
2428+
* Add a group hook
2429+
*
2430+
* <pre><code>GitLab Endpoint: POST /groups/:id/hooks</code></pre>
2431+
*
2432+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
2433+
* @param webHookParams webhook creation options
2434+
* @throws GitLabApiException if any exception occurs
2435+
*/
2436+
public Webhook addWebhook(Object groupIdOrPath, WebHookParams webHookParams) throws GitLabApiException {
2437+
Response response = post(
2438+
Response.Status.CREATED, webHookParams.getForm(), "groups", getGroupIdOrPath(groupIdOrPath), "hooks");
2439+
return (response.readEntity(Webhook.class));
2440+
}
24432441
}
+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.io.Serializable;
4+
5+
import org.gitlab4j.api.GitLabApiForm;
6+
7+
public class WebHookParams implements Serializable {
8+
private static final long serialVersionUID = 1L;
9+
10+
private String url;
11+
private String name;
12+
private String description;
13+
private Boolean pushEvents;
14+
private String pushEventsBranchFilter;
15+
private String branchFilterStrategy;
16+
private Boolean issuesEvents;
17+
private Boolean confidentialIssuesEvents;
18+
private Boolean mergeRequestsEvents;
19+
private Boolean tagPushEvents;
20+
private Boolean noteEvents;
21+
private Boolean confidentialNoteEvents;
22+
private Boolean jobEvents;
23+
private Boolean pipelineEvents;
24+
private Boolean wikiPageEvents;
25+
private Boolean deploymentEvents;
26+
private Boolean featureFlagEvents;
27+
private Boolean releasesEvents;
28+
private Boolean subgroupEvents;
29+
private Boolean memberEvents;
30+
private Boolean enableSslVerification;
31+
private String token;
32+
private Boolean resourceAccessTokenEvents;
33+
private String customWebhookTemplate;
34+
35+
public GitLabApiForm getForm() {
36+
37+
return new GitLabApiForm()
38+
.withParam("url", url, true)
39+
.withParam("name", name)
40+
.withParam("description", description)
41+
.withParam("push_events", pushEvents)
42+
.withParam("push_events_branch_filter", pushEventsBranchFilter)
43+
.withParam("branch_filter_strategy", branchFilterStrategy)
44+
.withParam("issues_events", issuesEvents)
45+
.withParam("confidential_issues_events", confidentialIssuesEvents)
46+
.withParam("merge_requests_events", mergeRequestsEvents)
47+
.withParam("tag_push_events", tagPushEvents)
48+
.withParam("note_events", noteEvents)
49+
.withParam("confidential_note_events", confidentialNoteEvents)
50+
.withParam("job_events", jobEvents)
51+
.withParam("pipeline_events", pipelineEvents)
52+
.withParam("wiki_page_events", wikiPageEvents)
53+
.withParam("deployment_events", deploymentEvents)
54+
.withParam("feature_flag_events", featureFlagEvents)
55+
.withParam("releases_events", releasesEvents)
56+
.withParam("subgroup_events", subgroupEvents)
57+
.withParam("member_events", memberEvents)
58+
.withParam("enable_ssl_verification", enableSslVerification)
59+
.withParam("token", token)
60+
.withParam("resource_access_token_events", resourceAccessTokenEvents)
61+
.withParam("custom_webhook_template", customWebhookTemplate);
62+
}
63+
64+
public WebHookParams setBranchFilterStrategy(String branchFilterStrategy) {
65+
this.branchFilterStrategy = branchFilterStrategy;
66+
return this;
67+
}
68+
69+
public WebHookParams setUrl(String url) {
70+
this.url = url;
71+
return this;
72+
}
73+
74+
public WebHookParams setName(String name) {
75+
this.name = name;
76+
return this;
77+
}
78+
79+
public WebHookParams setDescription(String description) {
80+
this.description = description;
81+
return this;
82+
}
83+
84+
public WebHookParams setPushEvents(Boolean pushEvents) {
85+
this.pushEvents = pushEvents;
86+
return this;
87+
}
88+
89+
public WebHookParams setPushEventsBranchFilter(String pushEventsBranchFilter) {
90+
this.pushEventsBranchFilter = pushEventsBranchFilter;
91+
return this;
92+
}
93+
94+
public WebHookParams setIssuesEvents(Boolean issuesEvents) {
95+
this.issuesEvents = issuesEvents;
96+
return this;
97+
}
98+
99+
public WebHookParams setConfidentialIssuesEvents(Boolean confidentialIssuesEvents) {
100+
this.confidentialIssuesEvents = confidentialIssuesEvents;
101+
return this;
102+
}
103+
104+
public WebHookParams setMergeRequestsEvents(Boolean mergeRequestsEvents) {
105+
this.mergeRequestsEvents = mergeRequestsEvents;
106+
return this;
107+
}
108+
109+
public WebHookParams setTagPushEvents(Boolean tagPushEvents) {
110+
this.tagPushEvents = tagPushEvents;
111+
return this;
112+
}
113+
114+
public WebHookParams setNoteEvents(Boolean noteEvents) {
115+
this.noteEvents = noteEvents;
116+
return this;
117+
}
118+
119+
public WebHookParams setConfidentialNoteEvents(Boolean confidentialNoteEvents) {
120+
this.confidentialNoteEvents = confidentialNoteEvents;
121+
return this;
122+
}
123+
124+
public WebHookParams setJobEvents(Boolean jobEvents) {
125+
this.jobEvents = jobEvents;
126+
return this;
127+
}
128+
129+
public WebHookParams setPipelineEvents(Boolean pipelineEvents) {
130+
this.pipelineEvents = pipelineEvents;
131+
return this;
132+
}
133+
134+
public WebHookParams setWikiPageEvents(Boolean wikiPageEvents) {
135+
this.wikiPageEvents = wikiPageEvents;
136+
return this;
137+
}
138+
139+
public WebHookParams setDeploymentEvents(Boolean deploymentEvents) {
140+
this.deploymentEvents = deploymentEvents;
141+
return this;
142+
}
143+
144+
public WebHookParams setFeatureFlagEvents(Boolean featureFlagEvents) {
145+
this.featureFlagEvents = featureFlagEvents;
146+
return this;
147+
}
148+
149+
public WebHookParams setReleasesEvents(Boolean releasesEvents) {
150+
this.releasesEvents = releasesEvents;
151+
return this;
152+
}
153+
154+
public WebHookParams setSubgroupEvents(Boolean subgroupEvents) {
155+
this.subgroupEvents = subgroupEvents;
156+
return this;
157+
}
158+
159+
public WebHookParams setMemberEvents(Boolean memberEvents) {
160+
this.memberEvents = memberEvents;
161+
return this;
162+
}
163+
164+
public WebHookParams setEnableSslVerification(Boolean enableSslVerification) {
165+
this.enableSslVerification = enableSslVerification;
166+
return this;
167+
}
168+
169+
public WebHookParams setToken(String token) {
170+
this.token = token;
171+
return this;
172+
}
173+
174+
public WebHookParams setResourceAccessTokenEvents(Boolean resourceAccessTokenEvents) {
175+
this.resourceAccessTokenEvents = resourceAccessTokenEvents;
176+
return this;
177+
}
178+
179+
public WebHookParams setCustomWebhookTemplate(String customWebhookTemplate) {
180+
this.customWebhookTemplate = customWebhookTemplate;
181+
return this;
182+
}
183+
}

0 commit comments

Comments
 (0)