Skip to content

Commit

Permalink
add tests and make it work with extra info & no set author as well
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Dec 8, 2024
1 parent ad500c3 commit 5c1da37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ object SkyHanniChangelogBuilder {
private val gson by lazy { GsonBuilder().setPrettyPrinting().create() }

private val categoryPattern = "## Changelog (?<category>.+)".toPattern()
private val changePattern = "\\+ (?<text>.+)\\s+-\\s+(?<author>.+)".toPattern()
private val changePattern = "\\+ (?<text>.+?) - (?<author>.+)".toPattern()
private val changePatternNoAuthor = "\\+ (?<text>.+)".toPattern()
private val extraInfoPattern = " {4}\\* (?<text>.+)".toPattern()
private val prTitlePattern = "(?<prefix>.+): (?<title>.+)".toPattern()
Expand Down Expand Up @@ -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))
Expand All @@ -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) {
Expand All @@ -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))
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/kotlin/SkyHanniChangelogBuilderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 5c1da37

Please sign in to comment.