Skip to content

Instantly share code, notes, and snippets.

@mutkuensert
Last active March 22, 2024 16:09
Show Gist options
  • Save mutkuensert/e36ed256d43ebdb158d5e97ff4c764b6 to your computer and use it in GitHub Desktop.
Save mutkuensert/e36ed256d43ebdb158d5e97ff4c764b6 to your computer and use it in GitHub Desktop.
Change log methods
ext.getChangeLog = { lastCommitsCount = 10 ->
return formatGitLog(getGitLogUntilCommitNumber(lastCommitsCount))
}
ext.getReleaseChangeLog = {
def lastTag = getLastTag()
return formatGitLog(getGitLogUntilTag(lastTag))
}
private static String getGitLogUntilTag(String tag) {
return "git log $tag..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text
}
private static String getGitLogUntilCommitNumber(int commitNumber) {
return "git log HEAD~$commitNumber..HEAD --oneline --no-merges --pretty=format:\"%s\"".execute().text
}
private static String getLastTag() {
return "git describe --tags --abbrev=0".execute().text.trim()
}
private static String formatGitLog(String gitLog) {
def changeLog = ""
final plainLog = gitLog.trim().replaceAll('"', '')
plainLog.eachLine { line ->
changeLog += "• $line\n"
}
return changeLog
}
private static String formatToMarkdownLines(String text) {
def newText = ""
final trimmedText = text.trim()
final lastLineIndex = trimmedText.readLines().size() - 1
def counter = 0
trimmedText.eachLine { line ->
newText += "$line"
if (counter != lastLineIndex) {
newText += "\\\n"
}
counter++
}
return newText
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment