-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Piotr Adamczyk
committed
Aug 19, 2020
1 parent
7d214bf
commit 7974e9f
Showing
10 changed files
with
162 additions
and
62 deletions.
There are no files selected for viewing
17 changes: 5 additions & 12 deletions
17
flank-scripts/src/main/kotlin/flank/scripts/ci/releasenotes/AppendReleaseNotes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
package flank.scripts.ci.releasenotes | ||
|
||
import flank.scripts.utils.markdownH2 | ||
import java.io.File | ||
|
||
fun File.appendReleaseNotes(messages: List<String>, releaseTag: String) { | ||
fun File.appendReleaseNotes(releaseNotesWithType: ReleaseNotesWithType, releaseTag: String) { | ||
appendToReleaseNotes( | ||
messages = messages, | ||
releaseNotesWithType = releaseNotesWithType, | ||
releaseTag = releaseTag | ||
) | ||
} | ||
|
||
private fun File.appendToReleaseNotes(messages: List<String>, releaseTag: String) { | ||
val currentFileLines = readLines() | ||
val newLines = mutableListOf<String>().apply { | ||
add(releaseTag.markdownH2()) | ||
addAll(messages) | ||
add("") | ||
} | ||
|
||
writeText((newLines + currentFileLines).joinToString(System.lineSeparator()).withNewLineAtTheEnd()) | ||
private fun File.appendToReleaseNotes(releaseNotesWithType: ReleaseNotesWithType, releaseTag: String) { | ||
writeText(releaseNotesWithType.asString(releaseTag).withNewLineAtTheEnd() + | ||
readLines().joinToString(System.lineSeparator()).withNewLineAtTheEnd()) | ||
} | ||
|
||
private fun String.withNewLineAtTheEnd() = plus(System.lineSeparator()) |
20 changes: 10 additions & 10 deletions
20
flank-scripts/src/main/kotlin/flank/scripts/ci/releasenotes/ConventionalCommitFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package flank.scripts.ci.releasenotes | ||
|
||
import flank.scripts.utils.markdownBold | ||
|
||
fun String.mapPrTitle() = when { | ||
startsWith("feat") -> replaceFirst("feat", "New feature".markdownBold()) | ||
startsWith("fix") -> replaceFirst("fix", "Fix".markdownBold()) | ||
startsWith("docs") -> replaceFirst("docs", "Documentation".markdownBold()) | ||
startsWith("refactor") -> replaceFirst("refactor", "Refactor".markdownBold()) | ||
startsWith("ci") -> replaceFirst("ci", "CI changes".markdownBold()) | ||
startsWith("test") -> replaceFirst("test", "Tests update".markdownBold()) | ||
startsWith("perf") -> replaceFirst("perf", "Performance upgrade".markdownBold()) | ||
fun String.mapPrTitleWithType() = when { | ||
startsWith("feat") -> "Features" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("fix") -> "Bug Fixes" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("docs") -> "Documentation" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("refactor") -> "Refactor" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("ci") -> "CI Changes" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("test") -> "Tests update" to skipConventionalCommitPrefix().capitalize() | ||
startsWith("perf") -> "Performance upgrade" to skipConventionalCommitPrefix().capitalize() | ||
else -> null // we do not accept other prefix to have update in release notes | ||
} | ||
|
||
private fun String.skipConventionalCommitPrefix() = substring(indexOf(':') + 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
flank-scripts/src/main/kotlin/flank/scripts/ci/releasenotes/ReleaseNotesWithType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package flank.scripts.ci.releasenotes | ||
|
||
import flank.scripts.utils.markdownH2 | ||
import flank.scripts.utils.markdownH3 | ||
import java.lang.StringBuilder | ||
|
||
typealias ReleaseNotesWithType = Map<String, List<String>> | ||
|
||
fun ReleaseNotesWithType.asString(headerTag: String) = | ||
StringBuilder(headerTag.markdownH2()) | ||
.appendln() | ||
.apply { | ||
this@asString.forEach { (type, messages) -> | ||
appendln(type.markdownH3()) | ||
messages.forEach { appendln(it) } | ||
} | ||
} | ||
.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
flank-scripts/src/test/kotlin/flank/scripts/ci/releasenotes/ReleaseNotesWithTypeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package flank.scripts.ci.releasenotes | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class ReleaseNotesWithTypeTest { | ||
|
||
@Test | ||
fun `Should properly format release notes with type`() { | ||
// given | ||
val testTag = "TAG" | ||
val expected = """ | ||
## TAG | ||
### Features | ||
- [#1](https://github.com/Flank/flank/pull/1) Tests1 ([test_of](https://github.com/test_of)) | ||
- [#2](https://github.com/Flank/flank/pull/2) Tests2 ([test_of](https://github.com/test_of)) | ||
- [#3](https://github.com/Flank/flank/pull/3) Tests3 ([test_of](https://github.com/test_of)) | ||
### Bug fixes | ||
- [#11](https://github.com/Flank/flank/pull/11) Tests11 ([test_of](https://github.com/test_of)) | ||
- [#12](https://github.com/Flank/flank/pull/12) Tests12 ([test_of](https://github.com/test_of)) | ||
- [#13](https://github.com/Flank/flank/pull/13) Tests13 ([test_of](https://github.com/test_of)) | ||
### Documentation | ||
- [#21](https://github.com/Flank/flank/pull/21) Tests21 ([test_of](https://github.com/test_of)) | ||
- [#22](https://github.com/Flank/flank/pull/22) Tests22 ([test_of](https://github.com/test_of)) | ||
- [#23](https://github.com/Flank/flank/pull/23) Tests33 ([test_of](https://github.com/test_of)) | ||
""".trimIndent() | ||
val releaseNotesWithType = mapOf( | ||
"Features" to listOf( | ||
"- [#1](https://github.com/Flank/flank/pull/1) Tests1 ([test_of](https://github.com/test_of))", | ||
"- [#2](https://github.com/Flank/flank/pull/2) Tests2 ([test_of](https://github.com/test_of))", | ||
"- [#3](https://github.com/Flank/flank/pull/3) Tests3 ([test_of](https://github.com/test_of))" | ||
), | ||
"Bug fixes" to listOf( | ||
"- [#11](https://github.com/Flank/flank/pull/11) Tests11 ([test_of](https://github.com/test_of))", | ||
"- [#12](https://github.com/Flank/flank/pull/12) Tests12 ([test_of](https://github.com/test_of))", | ||
"- [#13](https://github.com/Flank/flank/pull/13) Tests13 ([test_of](https://github.com/test_of))" | ||
), | ||
"Documentation" to listOf( | ||
"- [#21](https://github.com/Flank/flank/pull/21) Tests21 ([test_of](https://github.com/test_of))", | ||
"- [#22](https://github.com/Flank/flank/pull/22) Tests22 ([test_of](https://github.com/test_of))", | ||
"- [#23](https://github.com/Flank/flank/pull/23) Tests33 ([test_of](https://github.com/test_of))" | ||
) | ||
) | ||
|
||
// when | ||
val actual = releaseNotesWithType.asString(testTag) | ||
|
||
// then | ||
assertEquals(expected, actual) | ||
} | ||
} |