Skip to content

Commit cfe5305

Browse files
fix: supporting mono repos (#80)
* fix: Support mono repos * chore: Upgrade deps * fix: Filter out any empty slack channels. * this is needed because Option.split on the empty string gives one empty string.
1 parent c63d3bd commit cfe5305

File tree

6 files changed

+37
-17
lines changed

6 files changed

+37
-17
lines changed

build.gradle.kts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ plugins {
22
kotlin("multiplatform") version "1.8.21"
33
kotlin("plugin.serialization") version "1.8.21"
44
id("io.kotest.multiplatform") version "5.6.2"
5-
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
5+
id("org.jlleitschuh.gradle.ktlint") version "11.3.2"
66
}
77

88
group = "com.monta.gradle.changelog"
9-
version = "1.6.0"
9+
version = "1.6.1"
1010

1111
repositories {
1212
// Use Maven Central for resolving dependencies.
@@ -44,11 +44,11 @@ kotlin {
4444
// Date Time Support
4545
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
4646
// Serialization
47-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
47+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
4848
// Atomic
4949
implementation("org.jetbrains.kotlinx:atomicfu:0.20.2")
5050
// Http Client
51-
val ktorVersion = "2.2.4"
51+
val ktorVersion = "2.3.0"
5252
implementation("io.ktor:ktor-client-core:$ktorVersion")
5353
implementation("io.ktor:ktor-client-curl:$ktorVersion")
5454
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
@@ -57,7 +57,7 @@ kotlin {
5757
}
5858
val commonTest by getting {
5959
dependencies {
60-
val kotestVersion = "5.6.1"
60+
val kotestVersion = "5.6.2"
6161
implementation(kotlin("test-common"))
6262
implementation(kotlin("test-annotations-common"))
6363
implementation("io.kotest:kotest-framework-engine:$kotestVersion")

src/commonMain/kotlin/com.monta.changelog/GenerateChangeLogCommand.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ class GenerateChangeLogCommand : CliktCommand() {
153153
slackToken,
154154
buildSet {
155155
slackChannel?.let { add(it) }
156-
slackChannels?.let { addAll(it) }
156+
slackChannels?.let { list ->
157+
val trimmed = list.filter {
158+
it.isNotEmpty()
159+
}
160+
addAll(trimmed)
161+
}
157162
}
158163
)
159164
}

src/commonMain/kotlin/com.monta.changelog/git/GitService.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.monta.changelog.git
22

3+
import com.monta.changelog.git.sorter.Tag
34
import com.monta.changelog.git.sorter.TagSorter
45
import com.monta.changelog.model.Commit
56
import com.monta.changelog.util.DebugLogger
@@ -35,11 +36,15 @@ class GitService(
3536
tags = gitCommandUtil.getTags()
3637
.mapNotNull { tag ->
3738
when (tagPattern) {
38-
null -> tag
39+
null -> Tag(tag)
3940
else -> {
4041
// there is a tag pattern, extract group 1
4142
val match = tagPattern.matchEntire(tag)
42-
if (match != null) match.groups[1]?.value else null
43+
if (match != null) {
44+
match.groups[1]?.value?.let { Tag(it, tag) }
45+
} else {
46+
null
47+
}
4348
}
4449
}
4550
}
@@ -57,7 +62,7 @@ class GitService(
5762
}
5863

5964
1 -> {
60-
val latestTag = tags[0]
65+
val latestTag = tags[0].fullTag
6166
DebugLogger.info("only one tag found $latestTag; returning from latest commit to last tag")
6267
return CommitInfo(
6368
tagName = latestTag.getTagValue(),
@@ -66,8 +71,8 @@ class GitService(
6671
}
6772

6873
else -> {
69-
val latestTag = tags[0]
70-
val previousTag = tags[1]
74+
val latestTag = tags[0].fullTag
75+
val previousTag = tags[1].fullTag
7176
DebugLogger.info("returning commits between tag $latestTag and $previousTag")
7277
return CommitInfo(
7378
tagName = latestTag.getTagValue(),

src/commonMain/kotlin/com.monta.changelog/git/sorter/DateVerSorter.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import kotlinx.datetime.LocalDateTime
55

66
class DateVerSorter : TagSorter {
77

8-
override fun sort(tags: List<String>): List<String> {
8+
override fun sort(tags: List<Tag>): List<Tag> {
99
return tags.mapNotNull { tag ->
10+
val shortTag = tag.shortTag
1011
// Try to convert to a date
11-
val localDateTime = tag.getTagValue().toDate()
12+
val localDateTime = shortTag.getTagValue().toDate()
1213
// Skip if we don't have a valid date
1314
if (localDateTime == null) {
1415
null

src/commonMain/kotlin/com.monta.changelog/git/sorter/SemVerSorter.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import com.monta.changelog.git.getTagValue
44

55
class SemVerSorter : TagSorter {
66

7-
override fun sort(tags: List<String>): List<String> {
7+
override fun sort(tags: List<Tag>): List<Tag> {
88
return tags.mapNotNull { tag ->
9+
val shortTag = tag.shortTag
910
// Get the last part of the tag so stuff like releases/tag/2023-02-28-14-39 can still be valid
10-
var tagValue = tag.getTagValue()
11+
var tagValue = shortTag.getTagValue()
1112
// Remove the V portion if it's there (Not required for sorting)
1213
tagValue = tagValue.replace("v", "")
1314
// We check it's a valid tag by seeing it contains three dots (there is 100% a better way to do this)
14-
if (tag.count { it == '.' } >= 2) {
15+
if (shortTag.count { it == '.' } >= 2) {
1516
tagValue to tag
1617
} else {
1718
null
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package com.monta.changelog.git.sorter
22

33
interface TagSorter {
4-
fun sort(tags: List<String>): List<String>
4+
fun sort(tags: List<Tag>): List<Tag>
55
}
6+
7+
data class Tag(
8+
/**
9+
* Short tag is what will be sorted by - this might be just the date or version part of a tag
10+
*/
11+
val shortTag: String,
12+
val fullTag: String = shortTag,
13+
)

0 commit comments

Comments
 (0)