diff --git a/tools/deployment/build.gradle.kts b/tools/deployment/build.gradle.kts index 673a8939..2cee9ca4 100644 --- a/tools/deployment/build.gradle.kts +++ b/tools/deployment/build.gradle.kts @@ -21,6 +21,7 @@ repositories { dependencies { compileOnly("com.google.code.gson:gson:2.11.0") + implementation("com.squareup.okhttp3:okhttp:4.12.0") implementation("org.jetbrains:annotations:26.0.2") implementation("de.oliver.FancyAnalytics:java-sdk:0.0.2") diff --git a/tools/deployment/src/main/java/de/oliver/deployment/Configuration.java b/tools/deployment/src/main/java/de/oliver/deployment/Configuration.java index 58c63e3b..8a89b0d7 100644 --- a/tools/deployment/src/main/java/de/oliver/deployment/Configuration.java +++ b/tools/deployment/src/main/java/de/oliver/deployment/Configuration.java @@ -5,6 +5,7 @@ import com.google.gson.annotations.SerializedName; public record Configuration( @SerializedName("project_id") String projectID, @SerializedName("plugin_jar_path") String pluginJarPath, + @SerializedName("changelog_path") String changeLogPath, String version, @SerializedName("supported_versions") String[] supportedVersions, String channel, diff --git a/tools/deployment/src/main/java/de/oliver/deployment/modrinth/CreateVersionRequest.java b/tools/deployment/src/main/java/de/oliver/deployment/modrinth/CreateVersionRequest.java new file mode 100644 index 00000000..66a2b021 --- /dev/null +++ b/tools/deployment/src/main/java/de/oliver/deployment/modrinth/CreateVersionRequest.java @@ -0,0 +1,17 @@ +package de.oliver.deployment.modrinth; + +import com.google.gson.annotations.SerializedName; + +public record CreateVersionRequest( + String name, + @SerializedName("version_number") String versionName, + String changelog, + @SerializedName("game_versions") String[] gameVersions, + @SerializedName("version_type") String versionType, + String[] loaders, + boolean featured, + @SerializedName("project_id") String projectId, + @SerializedName("file_parts") String[] fileParts, + @SerializedName("primary_file") String primaryFile +) { +} diff --git a/tools/deployment/src/main/java/de/oliver/deployment/modrinth/ModrinthService.java b/tools/deployment/src/main/java/de/oliver/deployment/modrinth/ModrinthService.java new file mode 100644 index 00000000..a97ca253 --- /dev/null +++ b/tools/deployment/src/main/java/de/oliver/deployment/modrinth/ModrinthService.java @@ -0,0 +1,56 @@ +package de.oliver.deployment.modrinth; + +import com.google.gson.Gson; +import de.oliver.deployment.Configuration; +import okhttp3.*; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class ModrinthService { + private static final String BASE_URL = "https://api.modrinth.com/v2/version"; + private final OkHttpClient client = new OkHttpClient(); + private final String apiKey; + + public ModrinthService(String apiKey) { + this.apiKey = apiKey; + } + + public void deployPlugin(Configuration config) throws IOException { + String changelog = Files.readString(Path.of(config.changeLogPath())); + + CreateVersionRequest req = new CreateVersionRequest( + config.version(), + config.version(), + changelog, + config.supportedVersions(), + config.channel(), + config.loaders(), + config.featured(), + config.projectID(), + new String[]{"plugin"}, + "plugin" + ); + + File pluginFile = new File(config.pluginJarPath()); + + RequestBody body = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("data", new Gson().toJson(req)) + .addFormDataPart("plugin", pluginFile.getName(), + RequestBody.create(pluginFile, MediaType.parse("application/java-archive"))) + .build(); + + Request request = new Request.Builder() + .url(BASE_URL) + .addHeader("Authorization", apiKey) + .post(body) + .build(); + + try (Response response = client.newCall(request).execute()) { + System.out.println("Response: " + response.code() + " - " + response.body().string()); + } + } +} \ No newline at end of file