Skip to content

Commit

Permalink
fix: supporting mono repos (#80)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
morten-andersen authored May 24, 2023
1 parent c63d3bd commit cfe5305
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ plugins {
kotlin("multiplatform") version "1.8.21"
kotlin("plugin.serialization") version "1.8.21"
id("io.kotest.multiplatform") version "5.6.2"
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
id("org.jlleitschuh.gradle.ktlint") version "11.3.2"
}

group = "com.monta.gradle.changelog"
version = "1.6.0"
version = "1.6.1"

repositories {
// Use Maven Central for resolving dependencies.
Expand Down Expand Up @@ -44,11 +44,11 @@ kotlin {
// Date Time Support
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
// Serialization
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
// Atomic
implementation("org.jetbrains.kotlinx:atomicfu:0.20.2")
// Http Client
val ktorVersion = "2.2.4"
val ktorVersion = "2.3.0"
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-curl:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
Expand All @@ -57,7 +57,7 @@ kotlin {
}
val commonTest by getting {
dependencies {
val kotestVersion = "5.6.1"
val kotestVersion = "5.6.2"
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("io.kotest:kotest-framework-engine:$kotestVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,12 @@ class GenerateChangeLogCommand : CliktCommand() {
slackToken,
buildSet {
slackChannel?.let { add(it) }
slackChannels?.let { addAll(it) }
slackChannels?.let { list ->
val trimmed = list.filter {
it.isNotEmpty()
}
addAll(trimmed)
}
}
)
}
Expand Down
15 changes: 10 additions & 5 deletions src/commonMain/kotlin/com.monta.changelog/git/GitService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.monta.changelog.git

import com.monta.changelog.git.sorter.Tag
import com.monta.changelog.git.sorter.TagSorter
import com.monta.changelog.model.Commit
import com.monta.changelog.util.DebugLogger
Expand Down Expand Up @@ -35,11 +36,15 @@ class GitService(
tags = gitCommandUtil.getTags()
.mapNotNull { tag ->
when (tagPattern) {
null -> tag
null -> Tag(tag)
else -> {
// there is a tag pattern, extract group 1
val match = tagPattern.matchEntire(tag)
if (match != null) match.groups[1]?.value else null
if (match != null) {
match.groups[1]?.value?.let { Tag(it, tag) }
} else {
null
}
}
}
}
Expand All @@ -57,7 +62,7 @@ class GitService(
}

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

else -> {
val latestTag = tags[0]
val previousTag = tags[1]
val latestTag = tags[0].fullTag
val previousTag = tags[1].fullTag
DebugLogger.info("returning commits between tag $latestTag and $previousTag")
return CommitInfo(
tagName = latestTag.getTagValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import kotlinx.datetime.LocalDateTime

class DateVerSorter : TagSorter {

override fun sort(tags: List<String>): List<String> {
override fun sort(tags: List<Tag>): List<Tag> {
return tags.mapNotNull { tag ->
val shortTag = tag.shortTag
// Try to convert to a date
val localDateTime = tag.getTagValue().toDate()
val localDateTime = shortTag.getTagValue().toDate()
// Skip if we don't have a valid date
if (localDateTime == null) {
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.monta.changelog.git.getTagValue

class SemVerSorter : TagSorter {

override fun sort(tags: List<String>): List<String> {
override fun sort(tags: List<Tag>): List<Tag> {
return tags.mapNotNull { tag ->
val shortTag = tag.shortTag
// Get the last part of the tag so stuff like releases/tag/2023-02-28-14-39 can still be valid
var tagValue = tag.getTagValue()
var tagValue = shortTag.getTagValue()
// Remove the V portion if it's there (Not required for sorting)
tagValue = tagValue.replace("v", "")
// We check it's a valid tag by seeing it contains three dots (there is 100% a better way to do this)
if (tag.count { it == '.' } >= 2) {
if (shortTag.count { it == '.' } >= 2) {
tagValue to tag
} else {
null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.monta.changelog.git.sorter

interface TagSorter {
fun sort(tags: List<String>): List<String>
fun sort(tags: List<Tag>): List<Tag>
}

data class Tag(
/**
* Short tag is what will be sorted by - this might be just the date or version part of a tag
*/
val shortTag: String,
val fullTag: String = shortTag,
)

0 comments on commit cfe5305

Please sign in to comment.