diff --git a/src/main/kotlin/at/hannibal2/changelog/SkyHanniChangelogBuilder.kt b/src/main/kotlin/at/hannibal2/changelog/SkyHanniChangelogBuilder.kt index 52f1df1..975a695 100644 --- a/src/main/kotlin/at/hannibal2/changelog/SkyHanniChangelogBuilder.kt +++ b/src/main/kotlin/at/hannibal2/changelog/SkyHanniChangelogBuilder.kt @@ -12,7 +12,7 @@ object SkyHanniChangelogBuilder { private val gson by lazy { GsonBuilder().setPrettyPrinting().create() } private val categoryPattern = "## Changelog (?.+)".toPattern() - private val changePattern = "\\+ (?.+)\\s+-\\s+(?.+)".toPattern() + private val changePattern = "\\+ (?.+?) - (?.+)".toPattern() private val changePatternNoAuthor = "\\+ (?.+)".toPattern() private val extraInfoPattern = " {4}\\* (?.+)".toPattern() private val prTitlePattern = "(?.+): (?.+)".toPattern() @@ -135,8 +135,8 @@ object SkyHanniChangelogBuilder { val category = currentCategory ?: continue changePattern.matchMatcher(line) { - val text = group("text") - val author = group("author") + val text = group("text").trim() + val author = group("author").trim() if (author == "your_name_here") { errors.add(ChangelogError("Author is not set", line)) @@ -151,7 +151,7 @@ object SkyHanniChangelogBuilder { continue@loop } changePatternNoAuthor.matchMatcher(line) { - val text = group("text") + val text = group("text").trim() errors.add(ChangelogError("Author is not set", line)) illegalStartPattern.matchMatcher(text) { @@ -167,7 +167,7 @@ object SkyHanniChangelogBuilder { errors.add(ChangelogError("Extra info without a change", line)) } val change = currentChange ?: continue@loop - val text = group("text") + val text = group("text").trim() if (text == "Extra info.") { errors.add(ChangelogError("Extra info is not filled out", line)) } diff --git a/src/test/kotlin/SkyHanniChangelogBuilderTest.kt b/src/test/kotlin/SkyHanniChangelogBuilderTest.kt index b44cf26..b001ff6 100644 --- a/src/test/kotlin/SkyHanniChangelogBuilderTest.kt +++ b/src/test/kotlin/SkyHanniChangelogBuilderTest.kt @@ -135,6 +135,23 @@ class SkyHanniChangelogBuilderTest { assertEquals("Unknown line after changes started being declared", errors[0].message) } + @Test + fun `test body with additional spaces`() { + val prBody = listOf( + "## Changelog New Features", + "+ Added new feature. - John Doe", + " * More info. ", + ) + val prLink = "https://example.com/pr/1" + + val (changes, errors) = SkyHanniChangelogBuilder.findChanges(prBody, prLink) + + println("changes: ${changes.map { it.text }}") + println("errors: ${errors.map { it.message }}") + + assertTrue(errors.isEmpty(), "Expected no errors") + } + @Test fun `test title with correct pull request title`() { val prTitle = "Feature + Fix: New feature"