Skip to content

Commit 0ee8032

Browse files
committed
webhooks using @JsonProperty and Format annotations
1 parent 610650c commit 0ee8032

31 files changed

+725
-16
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
package org.gitlab4j.api.webhook;
22

33
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
45

56
public abstract class AbstractEvent implements Event {
67
private static final long serialVersionUID = 1L;
78

9+
@JsonProperty("event_type")
810
private String eventType;
11+
12+
@JsonProperty("request_url")
913
private String requestUrl;
14+
15+
@JsonProperty("request_query_string")
1016
private String requestQueryString;
17+
18+
@JsonProperty("secret_token")
1119
private String secretToken;
1220

1321
public String getEventType() {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,62 @@
33
import java.util.List;
44

55
import com.fasterxml.jackson.annotation.JsonIgnore;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
67

78
public abstract class AbstractPushEvent {
89

10+
@JsonProperty("event_name")
911
private String eventName;
1012

13+
@JsonProperty("after")
1114
private String after;
15+
16+
@JsonProperty("before")
1217
private String before;
18+
19+
@JsonProperty("ref")
1320
private String ref;
21+
22+
@JsonProperty("checkout_sha")
1423
private String checkoutSha;
1524

25+
@JsonProperty("user_id")
1626
private Long userId;
27+
28+
@JsonProperty("user_name")
1729
private String userName;
30+
31+
@JsonProperty("user_username")
1832
private String userUsername;
33+
34+
@JsonProperty("user_email")
1935
private String userEmail;
36+
37+
@JsonProperty("user_avatar")
2038
private String userAvatar;
2139

40+
@JsonProperty("project_id")
2241
private Long projectId;
42+
43+
@JsonProperty("project")
2344
private EventProject project;
45+
46+
@JsonProperty("repository")
2447
private EventRepository repository;
48+
49+
@JsonProperty("commits")
2550
private List<EventCommit> commits;
51+
52+
@JsonProperty("total_commits_count")
2653
private Integer totalCommitsCount;
2754

55+
@JsonProperty("request_url")
2856
private String requestUrl;
57+
58+
@JsonProperty("request_query_string")
2959
private String requestQueryString;
60+
61+
@JsonProperty("request_secret_token")
3062
private String requestSecretToken;
3163

3264
public String getEventName() {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,41 @@
44

55
import org.gitlab4j.api.utils.JacksonJson;
66

7+
import com.fasterxml.jackson.annotation.JsonFormat;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
710
public class BuildCommit {
811

12+
@JsonProperty("id")
913
private Long id;
14+
15+
@JsonProperty("sha")
1016
private String sha;
17+
18+
@JsonProperty("message")
1119
private String message;
20+
21+
@JsonProperty("author_name")
1222
private String authorName;
23+
24+
@JsonProperty("author_email")
1325
private String authorEmail;
26+
27+
@JsonProperty("author_url")
1428
private String authorUrl;
29+
30+
@JsonProperty("status")
1531
private String status;
32+
33+
@JsonProperty("duration")
1634
private Float duration;
35+
36+
@JsonProperty("started_at")
37+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
1738
private Date startedAt;
39+
40+
@JsonProperty("finished_at")
41+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
1842
private Date finishedAt;
1943

2044
public Long getId() {

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import org.gitlab4j.api.utils.JacksonJson;
66

7+
import com.fasterxml.jackson.annotation.JsonFormat;
8+
import com.fasterxml.jackson.annotation.JsonProperty;
9+
710
/**
811
* The documentation at: <a href="https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#job-events">
912
* Job Events</a> is incorrect, this class represents the actual content of the Job Hook event.
@@ -14,27 +17,66 @@ public class BuildEvent extends AbstractEvent {
1417
public static final String JOB_HOOK_X_GITLAB_EVENT = "Job Hook";
1518
public static final String OBJECT_KIND = "build";
1619

20+
@JsonProperty("ref")
1721
private String ref;
22+
23+
@JsonProperty("tag")
1824
private Boolean tag;
25+
26+
@JsonProperty("before_sha")
1927
private String beforeSha;
28+
29+
@JsonProperty("sha")
2030
private String sha;
31+
32+
@JsonProperty("build_id")
2133
private Long buildId;
34+
35+
@JsonProperty("build_name")
2236
private String buildName;
37+
38+
@JsonProperty("build_stage")
2339
private String buildStage;
40+
41+
@JsonProperty("build_status")
2442
private String buildStatus;
43+
44+
@JsonProperty("build_started_at")
45+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
2546
private Date buildStartedAt;
47+
48+
@JsonProperty("build_finished_at")
49+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss z")
2650
private Date buildFinishedAt;
51+
52+
@JsonProperty("build_duration")
2753
private Float buildDuration;
2854

55+
@JsonProperty("build_queued_duration")
2956
private Float buildQueuedDuration;
57+
58+
@JsonProperty("build_allow_failure")
3059
private Boolean buildAllowFailure;
60+
61+
@JsonProperty("build_failure_reason")
3162
private String buildFailureReason;
63+
64+
@JsonProperty("project_id")
3265
private Long projectId;
3366

67+
@JsonProperty("pipeline_id")
3468
private Long pipelineId;
69+
70+
@JsonProperty("project_name")
3571
private String projectName;
72+
73+
@JsonProperty("user")
3674
private EventUser user;
75+
76+
@JsonProperty("commit")
3777
private BuildCommit commit;
78+
79+
@JsonProperty("repository")
3880
private EventRepository repository;
3981

4082
@Override

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,47 @@
22

33
import org.gitlab4j.api.utils.JacksonJson;
44

5+
import com.fasterxml.jackson.annotation.JsonFormat;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
58
public class DeploymentEvent extends AbstractEvent {
69
private static final long serialVersionUID = 1L;
710

811
public static final String X_GITLAB_EVENT = "Deployment Hook";
912
public static final String OBJECT_KIND = "deployment";
1013

14+
@JsonProperty("status")
1115
private String status;
16+
17+
@JsonProperty("status_changed_at")
18+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss Z")
1219
private String statusChangedAt;
20+
21+
@JsonProperty("deployable_id")
1322
private Long deployableId;
23+
24+
@JsonProperty("deployable_url")
1425
private String deployableUrl;
26+
27+
@JsonProperty("environment")
1528
private String environment;
29+
30+
@JsonProperty("project")
1631
private EventProject project;
32+
33+
@JsonProperty("short_sha")
1734
private String shortSha;
35+
36+
@JsonProperty("user")
1837
private EventUser user;
38+
39+
@JsonProperty("user_url")
1940
private String userUrl;
41+
42+
@JsonProperty("commit_url")
2043
private String commitUrl;
44+
45+
@JsonProperty("commit_title")
2146
private String commitTitle;
2247

2348
@Override

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,44 @@
1010

1111
import com.fasterxml.jackson.annotation.JsonAnyGetter;
1212
import com.fasterxml.jackson.annotation.JsonAnySetter;
13+
import com.fasterxml.jackson.annotation.JsonProperty;
1314

1415
public abstract class EventChanges {
1516

17+
@JsonProperty("author_id")
1618
private ChangeContainer<Long> authorId;
19+
20+
@JsonProperty("created_at")
1721
private ChangeContainer<Date> createdAt;
22+
23+
@JsonProperty("updated_at")
1824
private ChangeContainer<Date> updatedAt;
25+
26+
@JsonProperty("updated_by_id")
1927
private ChangeContainer<Long> updatedById;
28+
29+
@JsonProperty("title")
2030
private ChangeContainer<String> title;
31+
32+
@JsonProperty("description")
2133
private ChangeContainer<String> description;
34+
35+
@JsonProperty("state")
2236
private ChangeContainer<String> state;
37+
38+
@JsonProperty("milestone_id")
2339
private ChangeContainer<Long> milestoneId;
40+
41+
@JsonProperty("labels")
2442
private ChangeContainer<List<EventLabel>> labels;
43+
44+
@JsonProperty("assignees")
2545
private ChangeContainer<List<Assignee>> assignees;
46+
47+
@JsonProperty("total_time_spent")
2648
private ChangeContainer<Integer> totalTimeSpent;
49+
50+
@JsonProperty("other_properties")
2751
private Map<String, ChangeContainer<Object>> otherProperties = new LinkedHashMap<>();
2852

2953
public ChangeContainer<Long> getAuthorId() {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,34 @@
66
import org.gitlab4j.api.models.Author;
77
import org.gitlab4j.api.utils.JacksonJson;
88

9+
import com.fasterxml.jackson.annotation.JsonFormat;
10+
import com.fasterxml.jackson.annotation.JsonProperty;
11+
912
public class EventCommit {
1013

14+
@JsonProperty("id")
1115
private String id;
16+
17+
@JsonProperty("message")
1218
private String message;
19+
20+
@JsonProperty("timestamp")
21+
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
1322
private Date timestamp;
23+
24+
@JsonProperty("url")
1425
private String url;
26+
27+
@JsonProperty("author")
1528
private Author author;
29+
30+
@JsonProperty("added")
1631
private List<String> added;
32+
33+
@JsonProperty("modified")
1734
private List<String> modified;
35+
36+
@JsonProperty("removed")
1837
private List<String> removed;
1938

2039
public String getId() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
import org.gitlab4j.api.utils.JacksonJson;
44

5+
import com.fasterxml.jackson.annotation.JsonProperty;
6+
57
public class EventExternalStatusCheck {
68

9+
@JsonProperty("id")
710
private Long id;
11+
12+
@JsonProperty("name")
813
private String name;
14+
15+
@JsonProperty("external_url")
916
private String externalUrl;
1017

1118
public Long getId() {

0 commit comments

Comments
 (0)