Skip to content

Commit a1db62c

Browse files
committed
fix: added job failure reason; allow setting empty int array application settings
1 parent db1a758 commit a1db62c

File tree

5 files changed

+208
-40
lines changed

5 files changed

+208
-40
lines changed

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.gitlab4j.api.models;
22

33
import java.io.Serializable;
4+
import java.lang.reflect.Array;
5+
import java.util.ArrayList;
46
import java.util.Date;
57
import java.util.HashMap;
8+
import java.util.List;
69
import java.util.Map;
710

811
import org.gitlab4j.api.GitLabApiException;
@@ -93,7 +96,7 @@ public Object addSetting(String setting, Object value) throws GitLabApiException
9396
public Object addSetting(Setting setting, Object value) throws GitLabApiException {
9497

9598
if (value instanceof JsonNode) {
96-
value = jsonNodeToValue((JsonNode)value);
99+
value = jsonNodeToValue((JsonNode)value, setting);
97100
}
98101

99102
setting.validate(value);
@@ -113,7 +116,7 @@ public void clearSettings() {
113116
settings.clear();
114117
}
115118

116-
private Object jsonNodeToValue(JsonNode node) {
119+
private Object jsonNodeToValue(JsonNode node, Setting setting) {
117120

118121
Object value = node;
119122
if (node instanceof NullNode) {
@@ -129,14 +132,17 @@ private Object jsonNodeToValue(JsonNode node) {
129132
} else if (node instanceof DoubleNode) {
130133
value = (float)((DoubleNode)node).asDouble();
131134
} else if (node instanceof ArrayNode) {
132-
133-
int numItems = node.size();
134-
String[] values = new String[numItems];
135-
for (int i = 0; i < numItems; i++) {
136-
values[i] = node.path(i).asText();
135+
if (node.isEmpty()) {
136+
value = setting.emptyArrayValue();
137+
} else {
138+
List<Object> values = new ArrayList<>(node.size());
139+
node.forEach(element -> values.add(jsonNodeToValue(element, setting)));
140+
Class<?> type = values.get(0).getClass();
141+
value = Array.newInstance(type, values.size());
142+
for (int i = 0; i < values.size(); i++) {
143+
Array.set(value, i, type.cast(values.get(i)));
144+
}
137145
}
138-
139-
value = values;
140146
}
141147

142148
return (value);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class Job implements Serializable {
2828
private String webUrl;
2929
private String stage;
3030
private JobStatus status;
31+
private String failureReason;
3132
private String when;
3233
private Boolean manual;
3334
private Boolean allowFailure;
@@ -164,6 +165,14 @@ public void setStatus(JobStatus status) {
164165
this.status = status;
165166
}
166167

168+
public String getFailureReason() {
169+
return this.failureReason;
170+
}
171+
172+
public void setFailureReason(String failureReason) {
173+
this.failureReason = failureReason;
174+
}
175+
167176
public String getCoverage() {
168177
return coverage;
169178
}

0 commit comments

Comments
 (0)