Skip to content

Commit

Permalink
[patch] adding config file support for tag options
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Sep 12, 2024
1 parent 6fb89a9 commit 3e069bb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.zegreatrob.tools.digger.core

import com.zegreatrob.tools.adapter.git.CommitRef

fun List<CommitRef>.alwaysLeftParent() = fold(emptyList<CommitRef>()) { acc, commit ->
if (acc.isEmpty()) {
acc + commit
} else if (commit.id == acc.last().parents.firstOrNull()) {
acc + commit
} else {
acc
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.zegreatrob.tools.tagger.cli

import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.core.context
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
Expand All @@ -13,6 +14,11 @@ import com.zegreatrob.tools.tagger.core.TaggerCore
import com.zegreatrob.tools.tagger.core.tag

class Tag : CliktCommand() {

init {
context { valueSources(ConfigFileSource(envvarReader)) }
}

private val dir by argument("git-repo")
private val releaseBranch by option().required()
private val version: String by option().required()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ data class TaggerConfig(
val patchRegex: String? = null,
val versionRegex: String? = null,
val noneRegex: String? = null,
val userName: String? = null,
val userEmail: String? = null,
val warningsAsErrors: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class CalculateVersionCommandConfigFileTest : CalculateVersionTestSpec {
}

override fun configureWithDefaults() {
val config = TaggerConfig(releaseBranch = "master")
arguments += projectDir.absolutePath
val config = TaggerConfig(releaseBranch = "master")
Json.encodeToStream(config, File(projectDir, ".tagger").outputStream())
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
@file:OptIn(ExperimentalSerializationApi::class)

package com.zegreatrob.tools.tagger.cli

import com.github.ajalt.clikt.testing.test
import com.zegreatrob.tools.tagger.TagTestSpec
import com.zegreatrob.tools.tagger.TestResult
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToStream
import org.junit.jupiter.api.io.TempDir
import java.io.File
import kotlin.test.BeforeTest

class TagCommandConfigFileTest : TagTestSpec {

@field:TempDir
override lateinit var projectDir: File

override val addFileNames: Set<String> = emptySet()
private lateinit var arguments: List<String>

@BeforeTest
fun setup() {
arguments = listOf("-q", "tag")
}

override fun configureWithDefaults() {
val config = TaggerConfig(releaseBranch = "master")
Json.encodeToStream(config, File(projectDir, ".tagger").outputStream())
arguments += projectDir.absolutePath
}

override fun configureWithOverrides(
releaseBranch: String?,
userName: String?,
userEmail: String?,
warningsAsErrors: Boolean?,
) {
var config = TaggerConfig()
releaseBranch?.let { config = config.copy(releaseBranch = releaseBranch) }
userName?.let { config = config.copy(userName = userName) }
userEmail?.let { config = config.copy(userEmail = userEmail) }
warningsAsErrors?.let { config = config.copy(warningsAsErrors = warningsAsErrors) }
Json.encodeToStream(config, File(projectDir, ".tagger").outputStream())

arguments += projectDir.absolutePath
}

override fun execute(version: String): TestResult {
arguments += "--version=$version"
val test = cli()
.test(arguments, envvars = mapOf("PWD" to projectDir.absolutePath))
return if (test.statusCode == 0) {
test
.output
.trim()
.let { TestResult.Success(it) }
} else {
TestResult.Failure(test.output.trim())
}
}
}

0 comments on commit 3e069bb

Please sign in to comment.