Skip to content

Commit

Permalink
refactor: Changelog cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jmongard committed Oct 10, 2023
1 parent d5da731 commit bfdf151
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
30 changes: 24 additions & 6 deletions src/main/kotlin/git/semver/plugin/changelog/ChangeLogBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open class ChangeLogBuilder(
) : DocumentBuilder() {

fun formatChanges(block: ChangeLogTextFormatter.() -> Unit) {
for (commitInfo in commitInfos()) {
for (commitInfo in remainingCommitInfos()) {
val formatter = ChangeLogTextFormatter(commitInfo)
formatter.block()
append(formatter.build())
Expand All @@ -18,7 +18,7 @@ open class ChangeLogBuilder(
}

fun skip() {
for (commitInfo in commitInfos()) {
for (commitInfo in remainingCommitInfos()) {
context.flagCommit(commitInfo)
}
}
Expand Down Expand Up @@ -52,7 +52,7 @@ open class ChangeLogBuilder(
key: String?,
block: ChangeLogBuilder.() -> Unit
) {
val filteredCommits = commitInfos().filter(filter)
val filteredCommits = remainingCommitInfos().filter(filter)
if (filteredCommits.isNotEmpty()) {
val builder = ChangeLogBuilder(key, filteredCommits, context)
builder.block()
Expand All @@ -71,15 +71,15 @@ open class ChangeLogBuilder(
}

fun groupBy(keySelector: (ChangeLogFormat.CommitInfo) -> String?, block: ChangeLogBuilder.() -> Unit) {
processGroups(commitInfos().mapNotNull { keyMapper(keySelector, it) }
processGroups(remainingCommitInfos().mapNotNull { keyMapper(keySelector, it) }
.groupBy({ it.first }, { it.second }), block)
}

fun groupBySorted(
keySelector: (ChangeLogFormat.CommitInfo) -> String?,
block: ChangeLogBuilder.() -> Unit
) {
processGroups(commitInfos().mapNotNull { keyMapper(keySelector, it) }
processGroups(remainingCommitInfos().mapNotNull { keyMapper(keySelector, it) }
.groupByTo(TreeMap(), { it.first }, { it.second }), block)
}

Expand All @@ -102,7 +102,7 @@ open class ChangeLogBuilder(
}
//</editor-fold>

fun commitInfos() = commitInfos.filter { !context.isCommitFlagged(it) }
fun remainingCommitInfos() = commitInfos.filter { !context.isCommitFlagged(it) }
}

class ChangeLogTextFormatter(
Expand All @@ -124,4 +124,22 @@ class ChangeLogTextFormatter(
commitInfo().commits.joinToString(" ", "", " ") { format.format(it.sha.take(len)) }

fun commitInfo() = commitInfo
}

open class DocumentBuilder {
private val out = StringBuilder()

fun build(): String {
return out.toString()
}

fun append(t: String?): DocumentBuilder {
out.append(t)
return this
}

fun appendLine(t: String? = ""): DocumentBuilder {
out.appendLine(t)
return this
}
}
19 changes: 0 additions & 19 deletions src/main/kotlin/git/semver/plugin/changelog/DocumentBuilder.kt

This file was deleted.

0 comments on commit bfdf151

Please sign in to comment.