From 4277775b27902ead29e6e10a7ffe643b005f58c6 Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Thu, 26 Dec 2024 13:25:02 +0100 Subject: [PATCH] build: add a function to extract the changelog from git commits --- build.gradle.kts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 89e43d75..9f6c044d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -133,6 +133,7 @@ modrinth { System.getenv("MODRINTH_VERSION_TYPE") ?: "release" } + changelog.set(getChangeLog()) uploadFile.set(tasks.shadowJar.get().archiveFile) gameVersions.addAll("1.19.4", "1.20.6", "1.21", "1.21.1", "1.21.2", "1.21.3", "1.21.4") loaders.addAll("paper", "purpur", "velocity") @@ -140,6 +141,26 @@ modrinth { syncBodyFrom = rootProject.file("README.md").readText() } +fun getChangeLog(): String { + val currentBranch = grgit.branch.current().name + val remoteBranch = "origin/$currentBranch" + + val lastRemoteCommit = grgit.log { + range(remoteBranch, currentBranch) + }.lastOrNull()?.id ?: return "No se encontraron cambios desde el remoto." + + val changeLog = grgit.log { + range(lastRemoteCommit, currentBranch) + } + + return if (changeLog.isNotEmpty()) { + changeLog.joinToString("\n") { commit -> + "- ${commit.shortMessage} (${commit.id})" + } + } else { + "No changes found." + } +} tasks.modrinth { dependsOn(tasks.shadowJar) dependsOn(tasks.modrinthSyncBody)