Skip to content

Commit 94db1a7

Browse files
committed
Needed to support actual Job Hook event (docs at GitLab are wrong) (#357).
1 parent 9757a7e commit 94db1a7

File tree

3 files changed

+337
-0
lines changed

3 files changed

+337
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package org.gitlab4j.api.webhook;
2+
3+
import java.util.Date;
4+
5+
import org.gitlab4j.api.utils.JacksonJson;
6+
7+
public class BuildCommit {
8+
9+
private Integer id;
10+
private String sha;
11+
private String message;
12+
private String authorName;
13+
private String authorEmail;
14+
private String authorUrl;
15+
private String status;
16+
private Float duration;
17+
private Date startedAt;
18+
private Date finishedAt;
19+
20+
public Integer getId() {
21+
return id;
22+
}
23+
24+
public void setId(Integer id) {
25+
this.id = id;
26+
}
27+
28+
public String getSha() {
29+
return sha;
30+
}
31+
32+
public void setSha(String sha) {
33+
this.sha = sha;
34+
}
35+
36+
public String getMessage() {
37+
return message;
38+
}
39+
40+
public void setMessage(String message) {
41+
this.message = message;
42+
}
43+
44+
public String getAuthorName() {
45+
return authorName;
46+
}
47+
48+
public void setAuthorName(String authorName) {
49+
this.authorName = authorName;
50+
}
51+
52+
public String getAuthorEmail() {
53+
return authorEmail;
54+
}
55+
56+
public void setAuthorEmail(String authorEmail) {
57+
this.authorEmail = authorEmail;
58+
}
59+
60+
public String getAuthorUrl() {
61+
return authorUrl;
62+
}
63+
64+
public void setAuthorUrl(String authorUrl) {
65+
this.authorUrl = authorUrl;
66+
}
67+
68+
public String getStatus() {
69+
return status;
70+
}
71+
72+
public void setStatus(String status) {
73+
this.status = status;
74+
}
75+
76+
public Float getDuration() {
77+
return duration;
78+
}
79+
80+
public void setDuration(Float duration) {
81+
this.duration = duration;
82+
}
83+
84+
public Date getStartedAt() {
85+
return startedAt;
86+
}
87+
88+
public void setStartedAt(Date startedAt) {
89+
this.startedAt = startedAt;
90+
}
91+
92+
public Date getFinishedAt() {
93+
return finishedAt;
94+
}
95+
96+
public void setFinishedAt(Date finishedAt) {
97+
this.finishedAt = finishedAt;
98+
}
99+
100+
@Override
101+
public String toString() {
102+
return (JacksonJson.toJsonString(this));
103+
}
104+
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
package org.gitlab4j.api.webhook;
2+
3+
import java.util.Date;
4+
5+
import org.gitlab4j.api.models.User;
6+
import org.gitlab4j.api.utils.JacksonJson;
7+
8+
/**
9+
* The documentation at: <a href="https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#job-events">
10+
* Job Events</a> is incorrect, this class represents the actual content of the Job Hook event.
11+
*/
12+
public class BuildEvent extends AbstractEvent {
13+
14+
public static final String JOB_HOOK_X_GITLAB_EVENT = "Job Hook";
15+
public static final String OBJECT_KIND = "build";
16+
17+
private String ref;
18+
private Boolean tag;
19+
private String beforeSha;
20+
private String sha;
21+
private Integer buildId;
22+
private String buildName;
23+
private String buildStage;
24+
private String buildStatus;
25+
private Date buildStarted_at;
26+
private Date buildFinished_at;
27+
private Float buildDuration;
28+
private Boolean buildAllowFailure;
29+
private String buildFailureReason;
30+
private Integer projectId;
31+
private String projectName;
32+
private User user;
33+
private BuildCommit commit;
34+
private EventRepository repository;
35+
36+
public String getObjectKind() {
37+
return (OBJECT_KIND);
38+
}
39+
40+
public void setObjectKind(String objectKind) {
41+
if (!OBJECT_KIND.equals(objectKind))
42+
throw new RuntimeException("Invalid object_kind (" + objectKind + "), must be '" + OBJECT_KIND + "'");
43+
}
44+
45+
public String getRef() {
46+
return ref;
47+
}
48+
49+
public void setRef(String ref) {
50+
this.ref = ref;
51+
}
52+
53+
public Boolean getTag() {
54+
return tag;
55+
}
56+
57+
public void setTag(Boolean tag) {
58+
this.tag = tag;
59+
}
60+
61+
public String getBeforeSha() {
62+
return beforeSha;
63+
}
64+
65+
public void setBeforeSha(String beforeSha) {
66+
this.beforeSha = beforeSha;
67+
}
68+
69+
public String getSha() {
70+
return sha;
71+
}
72+
73+
public void setSha(String sha) {
74+
this.sha = sha;
75+
}
76+
77+
public Integer getBuildId() {
78+
return buildId;
79+
}
80+
81+
public void setBuildId(Integer buildId) {
82+
this.buildId = buildId;
83+
}
84+
85+
public String getBuildName() {
86+
return buildName;
87+
}
88+
89+
public void setBuildName(String buildName) {
90+
this.buildName = buildName;
91+
}
92+
93+
public String getBuildStage() {
94+
return buildStage;
95+
}
96+
97+
public void setBuildStage(String buildStage) {
98+
this.buildStage = buildStage;
99+
}
100+
101+
public String getBuildStatus() {
102+
return buildStatus;
103+
}
104+
105+
public void setBuildStatus(String buildStatus) {
106+
this.buildStatus = buildStatus;
107+
}
108+
109+
public Date getBuildStarted_at() {
110+
return buildStarted_at;
111+
}
112+
113+
public void setBuildStarted_at(Date buildStarted_at) {
114+
this.buildStarted_at = buildStarted_at;
115+
}
116+
117+
public Date getBuildFinished_at() {
118+
return buildFinished_at;
119+
}
120+
121+
public void setBuildFinished_at(Date buildFinished_at) {
122+
this.buildFinished_at = buildFinished_at;
123+
}
124+
125+
public Float getBuildDuration() {
126+
return buildDuration;
127+
}
128+
129+
public void setBuildDuration(Float buildDuration) {
130+
this.buildDuration = buildDuration;
131+
}
132+
133+
public Boolean getBuildAllowFailure() {
134+
return buildAllowFailure;
135+
}
136+
137+
public void setBuildAllowFailure(Boolean buildAllowFailure) {
138+
this.buildAllowFailure = buildAllowFailure;
139+
}
140+
141+
public String getBuildFailureReason() {
142+
return buildFailureReason;
143+
}
144+
145+
public void setBuildFailureReason(String buildFailureReason) {
146+
this.buildFailureReason = buildFailureReason;
147+
}
148+
149+
public Integer getProjectId() {
150+
return projectId;
151+
}
152+
153+
public void setProjectId(Integer projectId) {
154+
this.projectId = projectId;
155+
}
156+
157+
public String getProjectName() {
158+
return projectName;
159+
}
160+
161+
public void setProjectName(String projectName) {
162+
this.projectName = projectName;
163+
}
164+
165+
public User getUser() {
166+
return user;
167+
}
168+
169+
public void setUser(User user) {
170+
this.user = user;
171+
}
172+
173+
public BuildCommit getCommit() {
174+
return commit;
175+
}
176+
177+
public void setCommit(BuildCommit commit) {
178+
this.commit = commit;
179+
}
180+
181+
public EventRepository getRepository() {
182+
return repository;
183+
}
184+
185+
public void setRepository(EventRepository repository) {
186+
this.repository = repository;
187+
}
188+
189+
@Override
190+
public String toString() {
191+
return (JacksonJson.toJsonString(this));
192+
}
193+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"object_kind": "build",
3+
"ref": "master",
4+
"tag": false,
5+
"before_sha": "8a49a94f1a7cd64985074cb11b1a42a7ab2d9b46",
6+
"sha": "a890bee24574603c522c756b9346649fbec4c812",
7+
"build_id": 214655258,
8+
"build_name": "build1",
9+
"build_stage": "build",
10+
"build_status": "running",
11+
"build_started_at": "2019-05-17T18:09:21Z",
12+
"build_duration": 0.05880817,
13+
"build_allow_failure": false,
14+
"build_failure_reason": "unknown_failure",
15+
"project_id": 3115610,
16+
"project_name": "GitLab4J / test-project",
17+
"user": {
18+
"id": 20493,
19+
"name": "GitLab4J Tester",
20+
"email": "gitlab4j@gitlab4j.org"
21+
},
22+
"commit": {
23+
"id": 61897408,
24+
"sha": "a890bee24574603c522c756b9346649fbec4c812",
25+
"message": "Add new file",
26+
"author_name": "GitLab4J Tester",
27+
"author_email": "gitlab4j@gitlab4j.org",
28+
"author_url": "https://gitlab.com/gitlab4j",
29+
"status": "pending"
30+
},
31+
"repository": {
32+
"name": "test-project",
33+
"url": "git@gitlab.com:gitlab4j/test-project.git",
34+
"description": "This is a test project to be used for testing the GitLab4J-API",
35+
"homepage": "https://gitlab.com/gitlab4j/test-project",
36+
"git_http_url": "https://gitlab.com/gitlab4j/test-project.git",
37+
"git_ssh_url": "git@gitlab.com:gitlab4j/test-project.git",
38+
"visibility_level": 20
39+
}
40+
}

0 commit comments

Comments
 (0)