Skip to content

Commit

Permalink
fix: Improved change log
Browse files Browse the repository at this point in the history
  • Loading branch information
jmongard committed Sep 13, 2023
1 parent 12409bc commit 499f3ae
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 23 deletions.
14 changes: 7 additions & 7 deletions src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import git.semver.plugin.gradle.ChangeLogFormatter

open class SemverSettings {

var defaultPreRelease: String = "SNAPSHOT"
var releasePattern: String = "\\Arelease(?:\\(\\w+\\))?:"
var patchPattern: String = "\\Afix(?:\\([^()]+\\))?:"
var minorPattern: String = "\\Afeat(?:\\([^()]+\\))?:"
var majorPattern: String = "\\A\\w+(?:\\([^()]+\\))?!:|^BREAKING[ -]CHANGE:"
var defaultPreRelease = "SNAPSHOT"
var releasePattern = "\\Arelease(?:\\(\\w+\\))?:"
var patchPattern = "\\Afix(?:\\([^()]+\\))?:"
var minorPattern = "\\Afeat(?:\\([^()]+\\))?:"
var majorPattern = "\\A\\w+(?:\\([^()]+\\))?!:|^BREAKING[ -]CHANGE:"

var changeLogPattern: String = "\\A(?<Type>\\w+)(?:\\((?<Scope>[^()]+)\\))?:(?<Message>(?:.|\n)*)"
var changeLogTexts: Map<String, String> = mutableMapOf(
var changeLogPattern = "\\A(?<Type>\\w+)(?:\\((?<Scope>[^()]+)\\))?:(?<Message>(?:.|\n)*)"
var changeLogTexts = mutableMapOf(
ChangeLogFormatter.OTHER_TYPE to "## Other Changes \uD83D\uDCA1",
ChangeLogFormatter.MISSING_TYPE to "## Other Changes \uD83D\uDCA1",
ChangeLogFormatter.BREAKING_CHANGE to "## Breaking Changes \uD83D\uDEE0",
Expand Down
46 changes: 30 additions & 16 deletions src/test/kotlin/git/semver/plugin/gradle/ChangeLogFormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlin.test.assertNotNull

class ChangeLogFormatterTest {
@Test fun format_log_empty() {

val settings = SemverSettings()

val actual = ChangeLogFormatter(settings).formatLog(listOf())
Expand All @@ -20,24 +19,11 @@ class ChangeLogFormatterTest {
}

@Test fun format_log_with_breaking_changes() {

val settings = SemverSettings()
val changeLog = listOf(
"fix(#1): Bugfix 1",
"fix(#1): Bugfix 1",
"fix(deps): Bugfix broken deps",
"feat(#2): A feature",
"fix(#5)!: A breaking change",
"build(deps): A build change",
"release: 1.2.3-alpha",
"test: Added some tests",
"ci: A CI change",
"xyz: Some other change",
"An uncategorized change"
)
val changeLog = createChangeLog()

val actual = ChangeLogFormatter(settings).formatLog(changeLog)
println(actual)

assertThat(actual)
.startsWith("# What's Changed")
.containsOnlyOnce("Bugfix 1")
Expand All @@ -53,5 +39,33 @@ class ChangeLogFormatterTest {
.contains("- xyz: Some other change")
.contains("- An uncategorized change")
.doesNotContain("1.2.3")
println(actual)
}

@Test fun format_log_with_cleared_settings() {
val settings = SemverSettings()
settings.changeLogTexts.clear();
val changeLog = createChangeLog()

val actual = ChangeLogFormatter(settings).formatLog(changeLog)

assertThat(actual).isEmpty()
}

private fun createChangeLog(): List<String> {
val changeLog = listOf(
"fix(#1): Bugfix 1",
"fix(#1): Bugfix 1",
"fix(deps): Bugfix broken deps",
"feat(#2): A feature",
"fix(#5)!: A breaking change",
"build(deps): A build change",
"release: 1.2.3-alpha",
"test: Added some tests",
"ci: A CI change",
"xyz: Some other change",
"An uncategorized change"
)
return changeLog
}
}

0 comments on commit 499f3ae

Please sign in to comment.