11import io.papermc.hangarpublishplugin.model.Platforms
22import org.apache.tools.ant.filters.ReplaceTokens
3- import java.io.ByteArrayOutputStream
43
54plugins {
65 id(" maven-publish" )
@@ -87,7 +86,7 @@ tasks {
8786 id = property(" hangar.project" ) as String?
8887 version = project.version as String
8988 channel = " Release"
90- changelog = generateChangelog ()
89+ changelog = parseGitHubChangelog ()
9190
9291 platforms {
9392 register(Platforms .PAPER ) {
@@ -104,7 +103,7 @@ tasks {
104103 uploadFile = shadowJar.get()
105104 gameVersions = mapVersions(" modrinth.versions" )
106105 loaders = arrayListOf (" bukkit" , " spigot" , " paper" , " folia" , " purpur" )
107- changelog = generateChangelog ()
106+ changelog = parseGitHubChangelog ()
108107
109108 syncBodyFrom = file(" README.md" ).readText()
110109 modrinth.get().dependsOn(modrinthSyncBody)
@@ -115,25 +114,22 @@ fun mapVersions(propertyName: String): Provider<List<String>> = provider {
115114 return @provider (property(propertyName) as String ).split(" ," ).map { it.trim() }
116115}
117116
118- fun generateChangelog (): Provider <String > = provider {
119- val tags = providers.exec {
120- commandLine(" git" , " tag" , " --sort" , " version:refname" )
121- }.standardOutput.asText.get().trim().split(" \n " )
122-
123- val tagsRange = if (tags.size > 1 ) {
124- " ${tags[tags.size - 2 ]} ...${tags[tags.size - 1 ]} "
125- } else if (tags.isNotEmpty()) tags[0 ] else " HEAD~1...HEAD"
126-
127- val repoUrl = property(" github.url" ) as String?
128- val changelog = ByteArrayOutputStream ().apply {
129- write(" ### Commits:\n " .toByteArray())
130-
131- write(providers.exec {
132- commandLine(" git" , " log" , tagsRange, " --pretty=format:- [%h]($repoUrl /commit/%H) %s" , " --reverse" )
133- }.standardOutput.asBytes.get())
134-
135- write(" \n\n Compare Changes: [$tagsRange ]($repoUrl /compare/$tagsRange )" .toByteArray())
136- }.toString(Charsets .UTF_8 .name())
137-
138- return @provider changelog
117+ fun parseGitHubChangelog (): Provider <String > = provider {
118+ val changelog = System .getenv(" GITHUB_CHANGELOG" )
119+ ? : return @provider " (No changelog provided)"
120+
121+ val userRegex = Regex (" (?<!\\ w)@([A-Za-z0-9-]+)" )
122+ val pullRegex = Regex (" https://github\\ .com/[\\ w-]+/[\\ w-]+/pull/(\\ d+)" )
123+ val compareRegex = Regex (" https://github\\ .com/[\\ w-]+/[\\ w-]+/compare/([\\ w\\ .]+)" )
124+
125+ changelog.replace(userRegex) {
126+ val user = it.groupValues[1 ]
127+ " [@$user ](https://github.com/$user )"
128+ }.replace(pullRegex) {
129+ val pr = it.groupValues[1 ]
130+ " [#$pr ](${it.value} )"
131+ }.replace(compareRegex) {
132+ val range = it.groupValues[1 ]
133+ " [$range ](${it.value} )"
134+ }
139135}
0 commit comments