From 3d35957108b1ec3a1121be669260be61acf652b8 Mon Sep 17 00:00:00 2001 From: 45gfg9 Date: Mon, 25 May 2020 14:16:00 +0800 Subject: [PATCH] WHY THEY ALLOW NULL NAMES EXISTENCE --- build.gradle | 6 +++--- src/main/java/net/im45/bot/watcher/Parser.java | 6 +++++- src/main/java/net/im45/bot/watcher/Request.java | 3 ++- src/main/java/net/im45/bot/watcher/Util.java | 10 +++++----- src/main/resources/plugin.yml | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 9b36411..ec28b81 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'net.im45.bot' -version = '0.2.5' +version = '0.2.6' repositories { maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' } @@ -22,10 +22,10 @@ dependencies { } compileKotlin { - kotlinOptions.jvmTarget = '11' + kotlinOptions.jvmTarget = JavaVersion.VERSION_11 } compileTestKotlin { - kotlinOptions.jvmTarget = '11' + kotlinOptions.jvmTarget = JavaVersion.VERSION_11 } sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11 diff --git a/src/main/java/net/im45/bot/watcher/Parser.java b/src/main/java/net/im45/bot/watcher/Parser.java index 65ca870..dd09440 100644 --- a/src/main/java/net/im45/bot/watcher/Parser.java +++ b/src/main/java/net/im45/bot/watcher/Parser.java @@ -87,7 +87,11 @@ public static Optional parseRelease(JsonElement jsonElement) throws Rep // or GitHub changed the format throw new RuntimeException(e); } - latest.authorName = author.get("name").getAsString(); + + latest.authorName = Optional.of(author.get("name")) + .filter(JsonElement::isJsonPrimitive) + .map(JsonElement::getAsString) + .orElse("null"); latest.authorLogin = author.get("login").getAsString(); latest.assets = new ArrayList<>(assetsCount); assets.forEach(e -> { diff --git a/src/main/java/net/im45/bot/watcher/Request.java b/src/main/java/net/im45/bot/watcher/Request.java index 5bb03c1..ade9ee9 100644 --- a/src/main/java/net/im45/bot/watcher/Request.java +++ b/src/main/java/net/im45/bot/watcher/Request.java @@ -295,7 +295,8 @@ public void run() { if (Parser.hasErrors(jsonElement)) { err.accept("Error received from upstream"); JsonArray jsonArray = Parser.getErrors(jsonElement); - debug.accept(jsonArray.toString()); + err.accept(jsonArray.toString()); +// debug.accept(jsonElement.toString()); } if (!Parser.hasData(jsonElement)) { err.accept("Error! Received data doesn't have a \"data\" object"); diff --git a/src/main/java/net/im45/bot/watcher/Util.java b/src/main/java/net/im45/bot/watcher/Util.java index f650f06..90af356 100644 --- a/src/main/java/net/im45/bot/watcher/Util.java +++ b/src/main/java/net/im45/bot/watcher/Util.java @@ -69,7 +69,7 @@ public static Map>> filterNew( // update current ver.put(r, Pair.of(release.tagName, p.second)); if (!p.first.equals("?")) { - // not first time... + // not first time, notice 'em map.put(r, Pair.of(release, p.second)); } } @@ -84,7 +84,7 @@ public static Map>> filterNew( /** * Converts number of bytes to corresponding representations. *

- * That is, {@code 3530} becomes {@code 3.53}KB and some such. + * That is, {@code 3530} becomes {@code 3.53KB} and some such. * * @param bytes number of bytes * @throws IllegalArgumentException if given number is negative @@ -117,14 +117,14 @@ public static Path getResource(Class clazz, String resource) throws URISyntax case "file": return Paths.get(uri); case "jar": - return FileSystems.newFileSystem(uri, Collections.emptyMap()).getPath(resource); + return FileSystems.newFileSystem(uri, Map.of()).getPath(resource); default: throw new IllegalStateException("Unknown scheme: " + scheme); } } /** - * Converts a RepoId to a legal identifier. + * Converts a {@code RepoId} to a legal identifier. * * @param repoId A {@link RepoId} object * @return The corresponding identifier @@ -133,7 +133,7 @@ public static Path getResource(Class clazz, String resource) throws URISyntax public static String toLegalId(RepoId repoId) { // No starting with numbers and no special characters. return repoId.toString() - .replaceAll("^(\\d)", "_$1") + .replaceFirst("^(\\d)", "_$1") .replaceAll("[-/.]", "_"); } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9e37277..e253508 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: "release-watcher" author: "45gfg9" -version: "0.2.5" +version: "0.2.6" main: "net.im45.bot.watcher.Watcher" info: "" depends: []