Skip to content

Commit 66de6d1

Browse files
tristanlinstimols
authored andcommitted
Add missing fields to GitlabPipeline (timols#352)
1 parent 87a4a46 commit 66de6d1

File tree

3 files changed

+373
-12
lines changed

3 files changed

+373
-12
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package org.gitlab.api.jackson;
2+
3+
import com.fasterxml.jackson.core.JsonParseException;
4+
import com.fasterxml.jackson.core.JsonParser;
5+
import com.fasterxml.jackson.core.JsonToken;
6+
import com.fasterxml.jackson.databind.DeserializationContext;
7+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
8+
9+
import java.io.IOException;
10+
import java.time.Instant;
11+
import java.time.format.DateTimeFormatter;
12+
import java.time.format.DateTimeFormatterBuilder;
13+
import java.time.format.DateTimeParseException;
14+
import java.time.format.FormatStyle;
15+
import java.util.Locale;
16+
import java.util.Objects;
17+
import java.util.stream.Stream;
18+
19+
/**
20+
* A spezialized {@link Instant} deserializer that can parse different formats.
21+
*/
22+
public class InstantDeserializer extends StdDeserializer<Instant> {
23+
24+
private static final DateTimeFormatter LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR = new DateTimeFormatterBuilder()
25+
.parseCaseInsensitive()
26+
.append(DateTimeFormatter.ISO_LOCAL_DATE)
27+
.appendLiteral(' ')
28+
.append(DateTimeFormatter.ISO_LOCAL_TIME)
29+
.toFormatter(Locale.getDefault(Locale.Category.FORMAT));
30+
31+
public InstantDeserializer() {
32+
super(Instant.class);
33+
}
34+
35+
@Override
36+
public Instant deserialize(JsonParser parser, DeserializationContext context) throws IOException {
37+
if (JsonToken.VALUE_NULL.equals(parser.getCurrentToken())) {
38+
return null;
39+
}
40+
41+
final String text = parser.getText();
42+
43+
if (null == text || text.trim().isEmpty()) {
44+
return null;
45+
}
46+
47+
return getFormatters()
48+
.map(formatter -> {
49+
try {
50+
return formatter.parse(text, Instant::from);
51+
} catch (DateTimeParseException e) {
52+
return null;
53+
}
54+
})
55+
.filter(Objects::nonNull)
56+
.findFirst()
57+
.orElseThrow(() -> new JsonParseException("Unable to parse instant \"" + text + "\"", parser.getCurrentLocation()));
58+
}
59+
60+
private static Stream<DateTimeFormatter> getFormatters() {
61+
return Stream.of(
62+
// English (Standard) Formats
63+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.LONG).withLocale(Locale.ENGLISH),
64+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.LONG).withLocale(Locale.ENGLISH),
65+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.LONG).withLocale(Locale.ENGLISH),
66+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
67+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
68+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.MEDIUM).withLocale(Locale.ENGLISH),
69+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG, FormatStyle.SHORT).withLocale(Locale.ENGLISH),
70+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT).withLocale(Locale.ENGLISH),
71+
DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT).withLocale(Locale.ENGLISH),
72+
73+
// ISO Formats
74+
LOCAL_DATE_TIME_FORMATTER_WITH_SPACE_SEPARATOR,
75+
DateTimeFormatter.ISO_LOCAL_DATE_TIME,
76+
DateTimeFormatter.ISO_DATE_TIME
77+
);
78+
}
79+
80+
}
Lines changed: 260 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,70 @@
11
package org.gitlab.api.models;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
5+
import org.gitlab.api.jackson.InstantDeserializer;
6+
7+
import java.time.Instant;
48

59
public class GitlabPipeline {
610
public static final String URL = "/pipelines";
711

8-
912
@JsonProperty("id")
1013
private Integer id;
1114

12-
@JsonProperty("ref")
13-
private String ref;
14-
1515
@JsonProperty("sha")
1616
private String sha;
1717

18+
@JsonProperty("ref")
19+
private String ref;
20+
1821
@JsonProperty("status")
1922
private String status;
2023

24+
@JsonProperty("web_url")
25+
private String webUrl;
26+
27+
@JsonProperty("before_sha")
28+
private String beforeSha;
29+
30+
@JsonProperty("tag")
31+
private boolean tag;
32+
33+
@JsonProperty("yaml_errors")
34+
private String yamlErrors;
35+
36+
@JsonProperty("user")
37+
private GitlabUser user;
38+
39+
@JsonProperty("created_at")
40+
@JsonDeserialize(using = InstantDeserializer.class)
41+
private Instant createdAt;
42+
43+
@JsonProperty("updated_at")
44+
@JsonDeserialize(using = InstantDeserializer.class)
45+
private Instant updatedAt;
46+
47+
@JsonProperty("started_at")
48+
@JsonDeserialize(using = InstantDeserializer.class)
49+
private Instant startedAt;
50+
51+
@JsonProperty("finished_at")
52+
@JsonDeserialize(using = InstantDeserializer.class)
53+
private Instant finishedAt;
54+
55+
@JsonProperty("committed_at")
56+
@JsonDeserialize(using = InstantDeserializer.class)
57+
private Instant committedAt;
58+
59+
@JsonProperty("duration")
60+
private int duration;
61+
62+
@JsonProperty("coverage")
63+
private String coverage;
64+
65+
@JsonProperty("detailed_status")
66+
private DetailedStatus detailedStatus;
67+
2168
public Integer getId() {
2269
return id;
2370
}
@@ -26,14 +73,6 @@ public void setId(Integer id) {
2673
this.id = id;
2774
}
2875

29-
public String getRef() {
30-
return ref;
31-
}
32-
33-
public void setRef(String ref) {
34-
this.ref = ref;
35-
}
36-
3776
public String getSha() {
3877
return sha;
3978
}
@@ -42,11 +81,220 @@ public void setSha(String sha) {
4281
this.sha = sha;
4382
}
4483

84+
public String getRef() {
85+
return ref;
86+
}
87+
88+
public void setRef(String ref) {
89+
this.ref = ref;
90+
}
91+
4592
public String getStatus() {
4693
return status;
4794
}
4895

4996
public void setStatus(String status) {
5097
this.status = status;
5198
}
99+
100+
public String getWebUrl() {
101+
return webUrl;
102+
}
103+
104+
public void setWebUrl(String webUrl) {
105+
this.webUrl = webUrl;
106+
}
107+
108+
public String getBeforeSha() {
109+
return beforeSha;
110+
}
111+
112+
public void setBeforeSha(String beforeSha) {
113+
this.beforeSha = beforeSha;
114+
}
115+
116+
public boolean isTag() {
117+
return tag;
118+
}
119+
120+
public void setTag(boolean tag) {
121+
this.tag = tag;
122+
}
123+
124+
public String getYamlErrors() {
125+
return yamlErrors;
126+
}
127+
128+
public void setYamlErrors(String yamlErrors) {
129+
this.yamlErrors = yamlErrors;
130+
}
131+
132+
public GitlabUser getUser() {
133+
return user;
134+
}
135+
136+
public void setUser(GitlabUser user) {
137+
this.user = user;
138+
}
139+
140+
public Instant getCreatedAt() {
141+
return createdAt;
142+
}
143+
144+
public void setCreatedAt(Instant createdAt) {
145+
this.createdAt = createdAt;
146+
}
147+
148+
public Instant getUpdatedAt() {
149+
return updatedAt;
150+
}
151+
152+
public void setUpdatedAt(Instant updatedAt) {
153+
this.updatedAt = updatedAt;
154+
}
155+
156+
public Instant getStartedAt() {
157+
return startedAt;
158+
}
159+
160+
public void setStartedAt(Instant startedAt) {
161+
this.startedAt = startedAt;
162+
}
163+
164+
public Instant getFinishedAt() {
165+
return finishedAt;
166+
}
167+
168+
public void setFinishedAt(Instant finishedAt) {
169+
this.finishedAt = finishedAt;
170+
}
171+
172+
public Instant getCommittedAt() {
173+
return committedAt;
174+
}
175+
176+
public void setCommittedAt(Instant committedAt) {
177+
this.committedAt = committedAt;
178+
}
179+
180+
public int getDuration() {
181+
return duration;
182+
}
183+
184+
public void setDuration(int duration) {
185+
this.duration = duration;
186+
}
187+
188+
public String getCoverage() {
189+
return coverage;
190+
}
191+
192+
public void setCoverage(String coverage) {
193+
this.coverage = coverage;
194+
}
195+
196+
public DetailedStatus getDetailedStatus() {
197+
return detailedStatus;
198+
}
199+
200+
public void setDetailedStatus(DetailedStatus detailedStatus) {
201+
this.detailedStatus = detailedStatus;
202+
}
203+
204+
public static class DetailedStatus {
205+
206+
private String icon;
207+
208+
private String text;
209+
210+
private String label;
211+
212+
private String group;
213+
214+
private String tooltip;
215+
216+
@JsonProperty("has_details")
217+
private String hasDetails;
218+
219+
@JsonProperty("details_path")
220+
private String detailsPath;
221+
222+
private String illustration;
223+
224+
private String favicon;
225+
226+
public String getIcon() {
227+
return icon;
228+
}
229+
230+
public void setIcon(String icon) {
231+
this.icon = icon;
232+
}
233+
234+
public String getText() {
235+
return text;
236+
}
237+
238+
public void setText(String text) {
239+
this.text = text;
240+
}
241+
242+
public String getLabel() {
243+
return label;
244+
}
245+
246+
public void setLabel(String label) {
247+
this.label = label;
248+
}
249+
250+
public String getGroup() {
251+
return group;
252+
}
253+
254+
public void setGroup(String group) {
255+
this.group = group;
256+
}
257+
258+
public String getTooltip() {
259+
return tooltip;
260+
}
261+
262+
public void setTooltip(String tooltip) {
263+
this.tooltip = tooltip;
264+
}
265+
266+
public String getHasDetails() {
267+
return hasDetails;
268+
}
269+
270+
public void setHasDetails(String hasDetails) {
271+
this.hasDetails = hasDetails;
272+
}
273+
274+
public String getDetailsPath() {
275+
return detailsPath;
276+
}
277+
278+
public void setDetailsPath(String detailsPath) {
279+
this.detailsPath = detailsPath;
280+
}
281+
282+
public String getIllustration() {
283+
return illustration;
284+
}
285+
286+
public void setIllustration(String illustration) {
287+
this.illustration = illustration;
288+
}
289+
290+
public String getFavicon() {
291+
return favicon;
292+
}
293+
294+
public void setFavicon(String favicon) {
295+
this.favicon = favicon;
296+
}
297+
298+
}
299+
52300
}

0 commit comments

Comments
 (0)