Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix job and applicationsettings #1169

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading