mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
deployment: Add discord webhook notification
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyHolograms",
|
||||||
"project_id": "5QNgOj66",
|
"project_id": "5QNgOj66",
|
||||||
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG.md",
|
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyHolograms",
|
||||||
"project_id": "5QNgOj66",
|
"project_id": "5QNgOj66",
|
||||||
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancyholograms-v2/build/libs/FancyHolograms-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG-SNAPSHOT.md",
|
"changelog_path": "../../../../plugins/fancyholograms-v2/CHANGELOG-SNAPSHOT.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyHolograms",
|
||||||
"project_id": "5QNgOj66",
|
"project_id": "5QNgOj66",
|
||||||
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG.md",
|
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyHolograms",
|
||||||
"project_id": "5QNgOj66",
|
"project_id": "5QNgOj66",
|
||||||
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancyholograms/build/libs/FancyHolograms-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG-SNAPSHOT.md",
|
"changelog_path": "../../../../plugins/fancyholograms/CHANGELOG-SNAPSHOT.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyNpcs",
|
||||||
"project_id": "EeyAn23L",
|
"project_id": "EeyAn23L",
|
||||||
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG.md",
|
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyNpcs",
|
||||||
"project_id": "EeyAn23L",
|
"project_id": "EeyAn23L",
|
||||||
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
|
"plugin_jar_path": "../../../../plugins/fancynpcs/build/libs/FancyNpcs-%VERSION%.jar",
|
||||||
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG-SNAPSHOT.md",
|
"changelog_path": "../../../../plugins/fancynpcs/CHANGELOG-SNAPSHOT.md",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"project_name": "FancyHolograms",
|
||||||
"project_id": "fancyholograms",
|
"project_id": "fancyholograms",
|
||||||
"plugin_jar_path": "../../../plugins/fancyholograms/build/libs/FancyHolograms-*.jar",
|
"plugin_jar_path": "../../../plugins/fancyholograms/build/libs/FancyHolograms-*.jar",
|
||||||
"changelog_path": "../../../plugins/fancyholograms/CHANGELOG.md",
|
"changelog_path": "../../../plugins/fancyholograms/CHANGELOG.md",
|
||||||
|
|||||||
@@ -2,7 +2,12 @@ package de.oliver.deployment;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public record Configuration(
|
public record Configuration(
|
||||||
|
@SerializedName("project_name") String projectName,
|
||||||
@SerializedName("project_id") String projectID,
|
@SerializedName("project_id") String projectID,
|
||||||
@SerializedName("plugin_jar_path") String pluginJarPath,
|
@SerializedName("plugin_jar_path") String pluginJarPath,
|
||||||
@SerializedName("changelog_path") String changeLogPath,
|
@SerializedName("changelog_path") String changeLogPath,
|
||||||
@@ -12,4 +17,13 @@ public record Configuration(
|
|||||||
@SerializedName("loaders") String[] loaders,
|
@SerializedName("loaders") String[] loaders,
|
||||||
boolean featured
|
boolean featured
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
public String readVersion() {
|
||||||
|
try {
|
||||||
|
return Files.readString(Path.of(versionPath));
|
||||||
|
} catch (IOException e) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package de.oliver.deployment;
|
package de.oliver.deployment;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import de.oliver.deployment.git.GitService;
|
||||||
import de.oliver.deployment.modrinth.ModrinthService;
|
import de.oliver.deployment.modrinth.ModrinthService;
|
||||||
|
import de.oliver.deployment.notification.DiscordWebhook;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
@@ -24,6 +27,28 @@ public class Main {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String discordWebhookUrl = System.getenv("DISCORD_WEBHOOK_URL");
|
||||||
|
if (discordWebhookUrl != null) {
|
||||||
|
DiscordWebhook.Data data = new DiscordWebhook.Data("Deployment completed", List.of(
|
||||||
|
new DiscordWebhook.Data.Embed(
|
||||||
|
"New version of "+configuration.projectName(),
|
||||||
|
"""
|
||||||
|
**Version:** %s
|
||||||
|
**Commit:** %s
|
||||||
|
**Download:** %s
|
||||||
|
""".formatted(
|
||||||
|
configuration.readVersion(),
|
||||||
|
GitService.getCommitHash(),
|
||||||
|
"https://modrinth.com/plugin/"+configuration.projectName()+"/versions/"+configuration.readVersion()),
|
||||||
|
0x00FF00
|
||||||
|
)
|
||||||
|
));
|
||||||
|
DiscordWebhook discordWebhook = new DiscordWebhook();
|
||||||
|
discordWebhook.sendWebhook(discordWebhookUrl, data);
|
||||||
|
} else {
|
||||||
|
System.out.println("Discord webhook URL not set. Skipping notification.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class ModrinthService {
|
|||||||
changelog = changelog.replaceAll("%COMMIT_HASH%", GitService.getCommitHash());
|
changelog = changelog.replaceAll("%COMMIT_HASH%", GitService.getCommitHash());
|
||||||
changelog = changelog.replaceAll("%COMMIT_MESSAGE%", GitService.getCommitMessage());
|
changelog = changelog.replaceAll("%COMMIT_MESSAGE%", GitService.getCommitMessage());
|
||||||
|
|
||||||
String version = Files.readString(Path.of(config.versionPath()));
|
String version = config.readVersion();
|
||||||
|
|
||||||
String pluginJarPath = config.pluginJarPath().replace("%VERSION%", version);
|
String pluginJarPath = config.pluginJarPath().replace("%VERSION%", version);
|
||||||
File pluginFile = new File(pluginJarPath);
|
File pluginFile = new File(pluginJarPath);
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package de.oliver.deployment.notification;
|
||||||
|
|
||||||
|
import de.oliver.fancyanalytics.sdk.utils.HttpRequest;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DiscordWebhook {
|
||||||
|
|
||||||
|
public void sendWebhook(String webhookUrl, Data data) {
|
||||||
|
HttpRequest request = new HttpRequest(webhookUrl)
|
||||||
|
.withMethod("POST")
|
||||||
|
.withHeader("Content-Type", "application/json")
|
||||||
|
.withBody(data);
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpResponse<String> resp = request.send();
|
||||||
|
if (resp.statusCode() != 204) {
|
||||||
|
System.out.println("Failed to send message with discord webhook: " + resp.body());
|
||||||
|
}
|
||||||
|
} catch (URISyntaxException | IOException | InterruptedException e) {
|
||||||
|
System.out.println("Failed to send webhook");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public record Data(String content, List<Embed> embeds) {
|
||||||
|
|
||||||
|
public record Embed(String title, String description, int color) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user