Refactor version fetch api
This commit is contained in:
@@ -32,7 +32,7 @@ index 08745a35b1ce8cc56d970472088de3cd17b9e43a..02bf179039196aeeb94c7392c28c214c
|
|||||||
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
|
metrics.addCustomChart(new Metrics.DrilldownPie("java_version", () -> {
|
||||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||||
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
||||||
index 30815c8970b1f1c88a3c7bb5fd36efd915f1687d..5ab805cb39d45fe9a2607dadb79ee520199fab8f 100644
|
index 30815c8970b1f1c88a3c7bb5fd36efd915f1687d..9eb39592791ef9790e24f622bb78157492dcb47b 100644
|
||||||
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
--- a/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
||||||
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
+++ b/src/main/java/com/destroystokyo/paper/PaperVersionFetcher.java
|
||||||
@@ -40,8 +40,8 @@ public class PaperVersionFetcher implements VersionFetcher {
|
@@ -40,8 +40,8 @@ public class PaperVersionFetcher implements VersionFetcher {
|
||||||
@@ -64,6 +64,39 @@ index 30815c8970b1f1c88a3c7bb5fd36efd915f1687d..5ab805cb39d45fe9a2607dadb79ee520
|
|||||||
distance = fetchDistanceFromSiteApi(buildNumber.getAsInt());
|
distance = fetchDistanceFromSiteApi(buildNumber.getAsInt());
|
||||||
} else {
|
} else {
|
||||||
final Optional<String> gitBranch = PaperVersionFetcher.BUILD_INFO.gitBranch();
|
final Optional<String> gitBranch = PaperVersionFetcher.BUILD_INFO.gitBranch();
|
||||||
|
@@ -226,7 +226,7 @@ public class PaperVersionFetcher implements VersionFetcher {
|
||||||
|
// Contributed by Techcable <Techcable@outlook.com> in GH-65
|
||||||
|
private static int fetchDistanceFromGitHub(final String branch, final String hash) {
|
||||||
|
try {
|
||||||
|
- final HttpURLConnection connection = (HttpURLConnection) URI.create("https://api.github.com/repos/%s/compare/%s...%s".formatted(PaperVersionFetcher.REPOSITORY, branch, hash)).toURL().openConnection();
|
||||||
|
+ final HttpURLConnection connection = (HttpURLConnection) URI.create("https://codeberg.org/api/v1/repos/%s/compare/%s...%s".formatted(PaperVersionFetcher.REPOSITORY, hash, branch)).toURL().openConnection(); // Shiroha - Rebrand to Shiroha
|
||||||
|
connection.setConnectTimeout(5000);
|
||||||
|
connection.setReadTimeout(5000);
|
||||||
|
connection.setRequestProperty("User-Agent", PaperVersionFetcher.USER_AGENT);
|
||||||
|
@@ -234,14 +234,16 @@ public class PaperVersionFetcher implements VersionFetcher {
|
||||||
|
if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return DISTANCE_UNKNOWN; // Unknown commit
|
||||||
|
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
|
||||||
|
final JsonObject obj = GSON.fromJson(reader, JsonObject.class);
|
||||||
|
- final String status = obj.get("status").getAsString();
|
||||||
|
- return switch (status) {
|
||||||
|
- case "identical" -> 0;
|
||||||
|
- case "behind" -> obj.get("behind_by").getAsInt();
|
||||||
|
- default -> DISTANCE_ERROR;
|
||||||
|
- };
|
||||||
|
+ // Shiroha start - Rebrand to Shiroha
|
||||||
|
+ if (obj == null || !obj.has("commits") || !obj.get("commits").isJsonArray()) {
|
||||||
|
+ LOGGER.error("Unexpected response shape from Codeberg's compare API");
|
||||||
|
+ return DISTANCE_ERROR;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return obj.getAsJsonArray("commits").size();
|
||||||
|
+ // Shiroha end
|
||||||
|
} catch (final JsonSyntaxException | NumberFormatException e) {
|
||||||
|
- LOGGER.error("Error parsing json from GitHub's API", e);
|
||||||
|
+ LOGGER.error("Error parsing json from Codeberg's API", e); // Shiroha - Rebrand to Shiroha
|
||||||
|
return DISTANCE_ERROR;
|
||||||
|
}
|
||||||
|
} catch (final IOException e) {
|
||||||
diff --git a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java b/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java
|
diff --git a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java b/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java
|
||||||
index 10a0be7a4db1a51579d113d279af7a9effe7f438..3d53b8f7a49c80d37b02fe72d11779b851700705 100644
|
index 10a0be7a4db1a51579d113d279af7a9effe7f438..3d53b8f7a49c80d37b02fe72d11779b851700705 100644
|
||||||
--- a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java
|
--- a/src/main/java/io/papermc/paper/ServerBuildInfoImpl.java
|
||||||
|
|||||||
Reference in New Issue
Block a user