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

Change buildnumber webreq from CI Jenkins to download API #281

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions src/main/java/org/geysermc/discordbot/listeners/DumpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,31 @@ private void parseDump(@NotNull MessageReceivedEvent event, String cleanURL, Str
gitData.append("Ahead by ").append(compare.getAheadBy()).append(" commit").append(compare.getAheadBy() == 1 ? "" : "s").append("\n");
}

if (compare != null && compare.getBehindBy() != 0) {
String compareUrl = gitUrl + "/compare/" + gitInfo.getString("git.commit.id.abbrev") + "..." + gitInfo.getString("git.branch");
gitData.append("Behind by [").append(compare.getBehindBy()).append(" commit").append(compare.getBehindBy() == 1 ? "" : "s").append("](").append(compareUrl).append(")\n");
boolean compareByBuildNumber = false;
if (!isFork && gitInfo.has("git.build.number")) {
try {
// Attempt to see how far behind they are not based on commits but CI builds
RestClient.RestResponse<JSONObject> restResponse = RestClient.getJsonObject("https://download.geysermc.org/v2/projects/geyser/versions/latest/builds/latest");
JSONObject response = restResponse.body();

int latestBuildNum = response.getInt("build");
int buildNum = Integer.parseInt(gitInfo.getString("git.build.number"));
int buildNumDiff = latestBuildNum - buildNum;
if (buildNumDiff > 0) {
compareByBuildNumber = true;
String compareUrl = gitUrl + "/compare/" + gitInfo.getString("git.commit.id.abbrev") + "..." + gitInfo.getString("git.branch");
gitData.append("Behind by [").append(buildNumDiff).append(" Run build").append(buildNumDiff == 1 ? "" : "s").append("](").append(compareUrl).append(")\n");

}
} catch (NumberFormatException ignored) {
}
}

if (!compareByBuildNumber) {
if (compare != null && compare.getBehindBy() != 0) {
String compareUrl = gitUrl + "/compare/" + gitInfo.getString("git.commit.id.abbrev") + "..." + gitInfo.getString("git.branch");
gitData.append("Behind by [").append(compare.getBehindBy()).append(" commit").append(compare.getBehindBy() == 1 ? "" : "s").append("](").append(compareUrl).append(")\n");
}
}

String versionString = "Unknown";
Expand Down