From 51c5f20ac3e437d3b5286e9b4841e1f5cf862c2d Mon Sep 17 00:00:00 2001 From: Erin Schnabel Date: Wed, 31 Jul 2024 21:14:26 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20java.lang.ClassCastException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/context/JsonAttribute.java | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/bot-github-core/src/main/java/org/commonhaus/automation/github/context/JsonAttribute.java b/bot-github-core/src/main/java/org/commonhaus/automation/github/context/JsonAttribute.java index ac815e4..f727fe1 100644 --- a/bot-github-core/src/main/java/org/commonhaus/automation/github/context/JsonAttribute.java +++ b/bot-github-core/src/main/java/org/commonhaus/automation/github/context/JsonAttribute.java @@ -316,22 +316,43 @@ public DataLabel labelFrom(JsonObject object) { } public List labelsFrom(JsonObject object) { - if (object == null) { - return null; - } - JsonObject field = jsonObjectFrom(object); + JsonValue field = valueFrom(object); if (field == null) { return null; } JsonArray list; if (field.getValueType() == ValueType.OBJECT) { - if (JsonAttribute.id.existsIn(field)) { - return List.of(new DataLabel(field)); + // "labels": { + // "nodes": [ + // { + // "id": "LA_kwDOL8tG0s8AAAABpSSN4Q", + // "name": "application/accepted" + // } + // ], + // "pageInfo": { + // "hasNextPage": false, + // "endCursor": "MQ" + // } + // } + JsonObject o = field.asJsonObject(); + if (JsonAttribute.id.existsIn(o)) { + return List.of(new DataLabel(o)); } - list = JsonAttribute.nodes.jsonArrayFrom(field); + list = JsonAttribute.nodes.jsonArrayFrom(o); } else { - list = jsonArrayFrom(field); + // "labels": [ + // { + // "id": 6605129827, + // "node_id": "LA_kwDOLDuJqs8AAAABibJIYw", + // "url": "https://api.github.com/repos/commonhaus-test/automation-test/labels/vote/open", + // "name": "vote/open", + // "color": "5319e7", + // "default": false, + // "description": "" + // } + // ], + list = field.asJsonArray(); } return list.stream() .map(JsonObject.class::cast) @@ -395,13 +416,17 @@ public GHAppInstallation appInstallationFrom(JsonObject object) { /** @return JsonObject with nodeName (or name()) from object */ public JsonObject jsonObjectFrom(JsonObject object) { + JsonValue value = valueFrom(object); + return value == null || value.getValueType() == ValueType.NULL ? null : (JsonObject) value; + } + + private JsonValue valueFrom(JsonObject object) { if (object == null) { return null; } - JsonValue value = alternateName + return alternateName ? object.getOrDefault(nodeName, object.get(name())) : object.get(nodeName); - return value == null || value.getValueType() == ValueType.NULL ? null : (JsonObject) value; } /**