1- import java.io.ByteArrayOutputStream
2-
31plugins {
42 id(" com.modrinth.minotaur" )
53}
64
75// Helper methods
86fun executeGitCommand (vararg command : String ): String {
9- val byteOut = ByteArrayOutputStream ()
10- exec {
7+ return providers.exec {
118 commandLine = listOf (" git" , * command)
12- standardOutput = byteOut
13- }
14- return byteOut.toString(Charsets .UTF_8 .name()).trim()
9+ }.standardOutput.asText.get().trim()
1510}
1611
17- fun latestCommitMessage (): String {
18- val commits = executeGitCommand(" log" , " --since=24 hours ago" , " --pretty=format:- %s" )
19- return if (commits.isNotBlank()) {
20- " Recent changes (last 24 hours):\n $commits "
21- } else {
22- " No commits in the last 24 hours"
12+ fun latestCommitChangelog (): String {
13+ val shortHash = executeGitCommand(" log" , " -1" , " --pretty=format:%h" )
14+ val fullHash = executeGitCommand(" log" , " -1" , " --pretty=format:%H" )
15+ val author = executeGitCommand(" log" , " -1" , " --pretty=format:%an" )
16+ val date = executeGitCommand(" log" , " -1" , " --pretty=format:%ad" , " --date=short" )
17+ val subject = executeGitCommand(" log" , " -1" , " --pretty=format:%s" )
18+ val body = executeGitCommand(" log" , " -1" , " --pretty=format:%b" )
19+
20+ return buildString {
21+ appendLine(" ### Commit [`$shortHash `](https://github.com/SamB440/ForcePack/commit/$fullHash )" )
22+ appendLine()
23+ appendLine(" **$subject **" )
24+ if (body.isNotBlank()) {
25+ appendLine()
26+ appendLine(body.trim())
27+ }
28+ appendLine()
29+ append(" by $author on $date " )
2330 }
2431}
2532
@@ -28,8 +35,12 @@ fun getChangelogSinceLastRelease(): String {
2835 val latestTag = executeGitCommand(" describe" , " --tags" , " --abbrev=0" )
2936 val currentVersion = project.version.toString()
3037
31- // Get all commits between the latest tag and HEAD
32- val commits = executeGitCommand(" log" , " --pretty=format:- %s" , " $latestTag ..HEAD" )
38+ // Get all commits between the latest tag and HEAD, including short hash links
39+ val commits = executeGitCommand(
40+ " log" ,
41+ " --pretty=format:- %s ([`%h`](https://github.com/SamB440/ForcePack/commit/%H))" ,
42+ " $latestTag ..HEAD"
43+ )
3344 .lines()
3445 .filter { it.isNotBlank() }
3546 .joinToString(" \n " )
@@ -64,11 +75,11 @@ modrinth {
6475 val changelogContent: String = if (isRelease) {
6576 getChangelogSinceLastRelease()
6677 } else {
67- latestCommitMessage ()
78+ latestCommitChangelog ()
6879 }
6980 changelog.set(changelogContent)
7081 } catch (e: Exception ) {
7182 println (" Failed to generate changelog: ${e.message} . Was the repository cloned with tags?" )
7283 changelog.set(" Failed to generate changelog: ${e.message} " )
7384 }
74- }
85+ }
0 commit comments