Skip to content

Commit 72669db

Browse files
Add support for release and deployment events in webhooks
1 parent db8f925 commit 72669db

File tree

10 files changed

+460
-99
lines changed

10 files changed

+460
-99
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,6 +2064,8 @@ public ProjectHook addHook(Object projectIdOrPath, String url, ProjectHook enabl
20642064
.withParam("wiki_events", enabledHooks.getWikiPageEvents(), false)
20652065
.withParam("enable_ssl_verification", enableSslVerification, false)
20662066
.withParam("repository_update_events", enabledHooks.getRepositoryUpdateEvents(), false)
2067+
.withParam("releases_events", enabledHooks.getReleasesEvents(), false)
2068+
.withParam("deployment_events", enabledHooks.getDeploymentEvents(), false)
20672069
.withParam("token", secretToken, false);
20682070
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "hooks");
20692071
return (response.readEntity(ProjectHook.class));
@@ -2133,16 +2135,22 @@ public void deleteHook(ProjectHook hook) throws GitLabApiException {
21332135
public ProjectHook modifyHook(ProjectHook hook) throws GitLabApiException {
21342136

21352137
GitLabApiForm formData = new GitLabApiForm()
2136-
.withParam("url", hook.getUrl(), true)
2137-
.withParam("push_events", hook.getPushEvents(), false)
2138-
.withParam("issues_events", hook.getIssuesEvents(), false)
2139-
.withParam("merge_requests_events", hook.getMergeRequestsEvents(), false)
2140-
.withParam("tag_push_events", hook.getTagPushEvents(), false)
2141-
.withParam("note_events", hook.getNoteEvents(), false)
2142-
.withParam("job_events", hook.getJobEvents(), false)
2143-
.withParam("pipeline_events", hook.getPipelineEvents(), false)
2144-
.withParam("wiki_events", hook.getWikiPageEvents(), false)
2145-
.withParam("enable_ssl_verification", hook.getEnableSslVerification(), false)
2138+
.withParam("url", hook.getUrl(), true)
2139+
.withParam("push_events", hook.getPushEvents(), false)
2140+
.withParam("push_events_branch_filter", hook.getPushEventsBranchFilter(), false)
2141+
.withParam("issues_events", hook.getIssuesEvents(), false)
2142+
.withParam("confidential_issues_events", hook.getConfidentialIssuesEvents(), false)
2143+
.withParam("merge_requests_events", hook.getMergeRequestsEvents(), false)
2144+
.withParam("tag_push_events", hook.getTagPushEvents(), false)
2145+
.withParam("note_events", hook.getNoteEvents(), false)
2146+
.withParam("confidential_note_events", hook.getConfidentialNoteEvents(), false)
2147+
.withParam("job_events", hook.getJobEvents(), false)
2148+
.withParam("pipeline_events", hook.getPipelineEvents(), false)
2149+
.withParam("wiki_events", hook.getWikiPageEvents(), false)
2150+
.withParam("enable_ssl_verification", hook.getEnableSslVerification(), false)
2151+
.withParam("repository_update_events", hook.getRepositoryUpdateEvents(), false)
2152+
.withParam("releases_events", hook.getReleasesEvents(), false)
2153+
.withParam("deployment_events", hook.getDeploymentEvents(), false)
21462154
.withParam("token", hook.getToken(), false);
21472155

21482156
Response response = put(Response.Status.OK, formData.asMap(), "projects", hook.getProjectId(), "hooks", hook.getId());

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

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11

22
package org.gitlab4j.api.models;
33

4-
import java.util.Date;
5-
64
import org.gitlab4j.api.utils.JacksonJson;
75

6+
import java.util.Date;
7+
88
public class ProjectHook {
99

1010
private Boolean buildEvents;
1111
private Date createdAt;
1212
private Boolean enableSslVerification;
1313
private Integer id;
1414
private Boolean issuesEvents;
15+
private Boolean deploymentEvents;
16+
private Boolean releasesEvents;
1517
private Boolean mergeRequestsEvents;
1618
private Boolean noteEvents;
1719
private Boolean jobEvents;
@@ -83,7 +85,7 @@ public Boolean getNoteEvents() {
8385
public void setNoteEvents(Boolean noteEvents) {
8486
this.noteEvents = noteEvents;
8587
}
86-
88+
8789
public Boolean getJobEvents() {
8890
return jobEvents;
8991
}
@@ -123,7 +125,7 @@ public Boolean getTagPushEvents() {
123125
public void setTagPushEvents(Boolean tagPushEvents) {
124126
this.tagPushEvents = tagPushEvents;
125127
}
126-
128+
127129
public String getToken() {
128130
return token;
129131
}
@@ -179,7 +181,23 @@ public String getPushEventsBranchFilter() {
179181
public void setPushEventsBranchFilter(String pushEventsBranchFilter) {
180182
this.pushEventsBranchFilter = pushEventsBranchFilter;
181183
}
182-
184+
185+
public Boolean getDeploymentEvents() {
186+
return deploymentEvents;
187+
}
188+
189+
public void setDeploymentEvents(Boolean deploymentEvents) {
190+
this.deploymentEvents = deploymentEvents;
191+
}
192+
193+
public Boolean getReleasesEvents() {
194+
return releasesEvents;
195+
}
196+
197+
public void setReleasesEvents(Boolean releasesEvents) {
198+
this.releasesEvents = releasesEvents;
199+
}
200+
183201
public ProjectHook withIssuesEvents(Boolean issuesEvents) {
184202
this.issuesEvents = issuesEvents;
185203
return (this);
@@ -194,7 +212,7 @@ public ProjectHook withNoteEvents(Boolean noteEvents) {
194212
this.noteEvents = noteEvents;
195213
return (this);
196214
}
197-
215+
198216
public ProjectHook withJobEvents(Boolean jobEvents) {
199217
this.jobEvents = jobEvents;
200218
return (this);
@@ -240,8 +258,18 @@ public ProjectHook withPushEventsBranchFilter(String pushEventsBranchFilter) {
240258
return (this);
241259
}
242260

261+
public ProjectHook withDeploymentEvents(Boolean deploymentEvents) {
262+
this.deploymentEvents = deploymentEvents;
263+
return (this);
264+
}
265+
266+
public ProjectHook withReleasesEvents(Boolean releasesEvents) {
267+
this.releasesEvents = ProjectHook.this.releasesEvents;
268+
return (this);
269+
}
270+
243271
@Override
244272
public String toString() {
245273
return (JacksonJson.toJsonString(this));
246274
}
247-
}
275+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package org.gitlab4j.api.webhook;
2+
3+
import org.gitlab4j.api.models.User;
4+
import org.gitlab4j.api.utils.JacksonJson;
5+
6+
public class DeploymentEvent extends AbstractEvent {
7+
8+
public static final String JOB_HOOK_X_GITLAB_EVENT = "Deployment Hook";
9+
public static final String OBJECT_KIND = "deployment";
10+
11+
private String status;
12+
private String statusChanged_at;
13+
private Integer deployableId;
14+
private String deployableUrl;
15+
private String environment;
16+
private EventProject project;
17+
private String shortSha;
18+
private User user;
19+
private String userUrl;
20+
private String commitUrl;
21+
private String commitTitle;
22+
23+
public String getObjectKind() {
24+
return (OBJECT_KIND);
25+
}
26+
27+
public void setObjectKind(String objectKind) {
28+
if (!OBJECT_KIND.equals(objectKind))
29+
throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'");
30+
}
31+
32+
public String getStatus() {
33+
return status;
34+
}
35+
36+
public void setStatus(String status) {
37+
this.status = status;
38+
}
39+
40+
public String getStatusChanged_at() {
41+
return statusChanged_at;
42+
}
43+
44+
public void setStatusChanged_at(String statusChanged_at) {
45+
this.statusChanged_at = statusChanged_at;
46+
}
47+
48+
public Integer getDeployableId() {
49+
return deployableId;
50+
}
51+
52+
public void setDeployableId(Integer deployableId) {
53+
this.deployableId = deployableId;
54+
}
55+
56+
public String getDeployableUrl() {
57+
return deployableUrl;
58+
}
59+
60+
public void setDeployableUrl(String deployableUrl) {
61+
this.deployableUrl = deployableUrl;
62+
}
63+
64+
public String getEnvironment() {
65+
return environment;
66+
}
67+
68+
public void setEnvironment(String environment) {
69+
this.environment = environment;
70+
}
71+
72+
public EventProject getProject() {
73+
return project;
74+
}
75+
76+
public void setProject(EventProject project) {
77+
this.project = project;
78+
}
79+
80+
public String getShortSha() {
81+
return shortSha;
82+
}
83+
84+
public void setShortSha(String shortSha) {
85+
this.shortSha = shortSha;
86+
}
87+
88+
public User getUser() {
89+
return user;
90+
}
91+
92+
public void setUser(User user) {
93+
this.user = user;
94+
}
95+
96+
public String getUserUrl() {
97+
return userUrl;
98+
}
99+
100+
public void setUserUrl(String userUrl) {
101+
this.userUrl = userUrl;
102+
}
103+
104+
public String getCommitUrl() {
105+
return commitUrl;
106+
}
107+
108+
public void setCommitUrl(String commitUrl) {
109+
this.commitUrl = commitUrl;
110+
}
111+
112+
public String getCommitTitle() {
113+
return commitTitle;
114+
}
115+
116+
public void setCommitTitle(String commitTitle) {
117+
this.commitTitle = commitTitle;
118+
}
119+
120+
@Override
121+
public String toString() {
122+
return (JacksonJson.toJsonString(this));
123+
}
124+
}

src/main/java/org/gitlab4j/api/webhook/Event.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
@JsonSubTypes.Type(value = PipelineEvent.class, name = PipelineEvent.OBJECT_KIND),
1818
@JsonSubTypes.Type(value = PushEvent.class, name = PushEvent.OBJECT_KIND),
1919
@JsonSubTypes.Type(value = TagPushEvent.class, name = TagPushEvent.OBJECT_KIND),
20-
@JsonSubTypes.Type(value = WikiPageEvent.class, name = WikiPageEvent.OBJECT_KIND)
20+
@JsonSubTypes.Type(value = WikiPageEvent.class, name = WikiPageEvent.OBJECT_KIND),
21+
@JsonSubTypes.Type(value = DeploymentEvent.class, name = DeploymentEvent.OBJECT_KIND),
22+
@JsonSubTypes.Type(value = ReleaseEvent.class, name = ReleaseEvent.OBJECT_KIND)
2123
})
2224
public interface Event {
2325
String getObjectKind();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.gitlab4j.api.webhook;
2+
3+
import org.gitlab4j.api.utils.JacksonJson;
4+
5+
import java.util.List;
6+
7+
public class EventReleaseAssets {
8+
9+
private Integer count;
10+
private List<EventReleaseLink> links;
11+
private List<EventReleaseSource> sources;
12+
13+
public Integer getCount() {
14+
return count;
15+
}
16+
17+
public void setCount(Integer count) {
18+
this.count = count;
19+
}
20+
21+
public List<EventReleaseLink> getLinks() {
22+
return links;
23+
}
24+
25+
public void setLinks(List<EventReleaseLink> links) {
26+
this.links = links;
27+
}
28+
29+
public List<EventReleaseSource> getSources() {
30+
return sources;
31+
}
32+
33+
public void setSources(List<EventReleaseSource> sources) {
34+
this.sources = sources;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return (JacksonJson.toJsonString(this));
40+
}
41+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.gitlab4j.api.webhook;
2+
3+
import org.gitlab4j.api.utils.JacksonJson;
4+
5+
public class EventReleaseLink {
6+
private Integer id;
7+
private Boolean external;
8+
private String linkType;
9+
private String name;
10+
private String url;
11+
12+
public Integer getId() {
13+
return id;
14+
}
15+
16+
public void setId(final Integer id) {
17+
this.id = id;
18+
}
19+
20+
public Boolean getExternal() {
21+
return external;
22+
}
23+
24+
public void setExternal(final Boolean external) {
25+
this.external = external;
26+
}
27+
28+
public String getLinkType() {
29+
return linkType;
30+
}
31+
32+
public void setLinkType(final String linkType) {
33+
this.linkType = linkType;
34+
}
35+
36+
public String getName() {
37+
return name;
38+
}
39+
40+
public void setName(final String name) {
41+
this.name = name;
42+
}
43+
44+
public String getUrl() {
45+
return url;
46+
}
47+
48+
public void setUrl(final String url) {
49+
this.url = url;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return (JacksonJson.toJsonString(this));
55+
}
56+
}

0 commit comments

Comments
 (0)