Skip to content

Commit

Permalink
Fix job and applicationsettings (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjkersten authored Oct 13, 2024
1 parent 06f78e1 commit 11b6bb2
Show file tree
Hide file tree
Showing 5 changed files with 1,193 additions and 42 deletions.
29 changes: 20 additions & 9 deletions src/main/java/org/gitlab4j/api/models/ApplicationSettings.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package org.gitlab4j.api.models;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.gitlab4j.api.GitLabApiException;
Expand Down Expand Up @@ -93,7 +98,7 @@ public Object addSetting(String setting, Object value) throws GitLabApiException
public Object addSetting(Setting setting, Object value) throws GitLabApiException {

if (value instanceof JsonNode) {
value = jsonNodeToValue((JsonNode)value);
value = jsonNodeToValue((JsonNode)value, setting);
}

setting.validate(value);
Expand All @@ -113,7 +118,7 @@ public void clearSettings() {
settings.clear();
}

private Object jsonNodeToValue(JsonNode node) {
private Object jsonNodeToValue(JsonNode node, Setting setting) {

Object value = node;
if (node instanceof NullNode) {
Expand All @@ -129,14 +134,20 @@ private Object jsonNodeToValue(JsonNode node) {
} else if (node instanceof DoubleNode) {
value = (float)((DoubleNode)node).asDouble();
} else if (node instanceof ArrayNode) {

int numItems = node.size();
String[] values = new String[numItems];
for (int i = 0; i < numItems; i++) {
values[i] = node.path(i).asText();
if (node.isEmpty()) {
value = setting.emptyArrayValue();
} else {
List<Object> values = new ArrayList<>(node.size());
node.forEach(element -> values.add(jsonNodeToValue(element, setting)));
Class<?> type = values.get(0).getClass();
value = Array.newInstance(type, values.size());
for (int i = 0; i < values.size(); i++) {
Array.set(value, i, type.cast(values.get(i)));
}
}

value = values;
} else if (node instanceof ObjectNode) {
ObjectMapper mapper = new ObjectMapper();
value = mapper.convertValue(node, HashMap.class);
}

return (value);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/gitlab4j/api/models/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Job implements Serializable {
private String webUrl;
private String stage;
private JobStatus status;
private String failureReason;
private String when;
private Boolean manual;
private Boolean allowFailure;
Expand Down Expand Up @@ -164,6 +165,14 @@ public void setStatus(JobStatus status) {
this.status = status;
}

public String getFailureReason() {
return this.failureReason;
}

public void setFailureReason(String failureReason) {
this.failureReason = failureReason;
}

public String getCoverage() {
return coverage;
}
Expand Down
Loading

0 comments on commit 11b6bb2

Please sign in to comment.