From 298326dd43677121724e9589f390cb0279cb8708 Mon Sep 17 00:00:00 2001 From: Iain Cardnell Date: Mon, 6 Apr 2020 20:07:03 +1000 Subject: [PATCH] add info command and various small fixes feat: add info command to list all variables feat: add in Next, Tag and MessageFormat as formats fix: next command doesn't include prefix by default fix: error if configured config file doesn't exist docs: various doc fixes --- build.sbt | 7 +- docs/formats.md | 26 +++- docs/usage.md | 8 ++ src/main/resources/reference.conf | 4 +- .../scala/net/cardnell/mkver/AppConfig.scala | 121 ++++++++++-------- .../net/cardnell/mkver/CommandLineArgs.scala | 14 +- .../scala/net/cardnell/mkver/Formatter.scala | 16 ++- src/main/scala/net/cardnell/mkver/Main.scala | 42 ++++-- src/main/scala/net/cardnell/mkver/MkVer.scala | 8 +- .../net/cardnell/mkver/AppConfigSpec.scala | 16 ++- .../net/cardnell/mkver/EndToEndTests.scala | 10 +- .../net/cardnell/mkver/FormatterSpec.scala | 4 +- .../scala/net/cardnell/mkver/MainSpec.scala | 15 ++- 13 files changed, 189 insertions(+), 102 deletions(-) diff --git a/build.sbt b/build.sbt index 8c18532..0129d86 100644 --- a/build.sbt +++ b/build.sbt @@ -1,12 +1,13 @@ import Dependencies._ -ThisBuild / scalaVersion := "2.12.11" -ThisBuild / version := "0.1.0-SNAPSHOT" -ThisBuild / organization := "net.cardnell" +ThisBuild / scalaVersion := "2.12.11" +ThisBuild / version := "0.3.0" +ThisBuild / organization := "net.cardnell" lazy val root = (project in file(".")) .settings( name := "git-mkver", + scalacOptions += "-Ypartial-unification", libraryDependencies += "org.typelevel" %% "cats-core" % "2.0.0", libraryDependencies += "com.monovore" %% "decline" % "1.0.0", libraryDependencies += "com.github.pathikrit" %% "better-files" % "3.8.0", diff --git a/docs/formats.md b/docs/formats.md index 15183bb..0f37aeb 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -11,10 +11,25 @@ All replacements in format strings start with `{` and end with `}`. They are rec +## SemVer Formats + +The following built in formats conform to the SemVer spec. They cannot be overriden. + +| Format Token | Substitution | +| ------------- | ------------- | +| `Version` | `{x}.{y}.{z}` | +| `VersionPreRelease` | `{Version}-{PreRelease}` | +| `VersionBuildMetaData` | `{Version}+{BuildMetaData}` | +| `VersionPreReleaseBuildMetaData` | `{Version}-{PreRelease}+{BuildMetaData}` | + + ## Built-in Formats | Format Token | Substitution | | ------------- | ------------- | +| `Next` | Full Semantic Version | +| `Tag` | Full Semantic Version as a tag (includes the prefix) | +| `TagMessage` | Tag Message | | `x` | Version major number | | `z` | Version patch number | | `y` | Version minor number | @@ -22,8 +37,11 @@ All replacements in format strings start with `{` and end with `}`. They are rec | `sh` | Short Hash | | `hash` | Full Hash | | `dd` | Day | -| `mm` | MonthValue, | -| `yyyy` | Year, | +| `mm` | Month | +| `yyyy` | Year | | `bn` | Build No from build system | -| `tag` | Full tag | -| `pr` | Tag prefix | \ No newline at end of file +| `tag?` | `true` if this branch is allowed to be tagged; `false` otherwise | +| `pr` | Tag prefix | +| `env.XXXX` | Environment Variables | + +### Environment Variables diff --git a/docs/usage.md b/docs/usage.md index 321e0bb..d73b752 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -33,3 +33,11 @@ pre-defined. ```bash $ git mkver patch ``` + +## Info + +If you want to see all variables or configuration you can use the `info` command: + +```bash +$ git mkver info +``` \ No newline at end of file diff --git a/src/main/resources/reference.conf b/src/main/resources/reference.conf index d585954..fe7eeb1 100644 --- a/src/main/resources/reference.conf +++ b/src/main/resources/reference.conf @@ -10,9 +10,11 @@ defaults { # the git tag must be a valid SemVer so the tag format must be one of: # Version | VersionPreRelease | VersionBuildMetaData | VersionPreReleaseBuildMetaData tagFormat: VersionBuildMetaData + # name of the pre-release e.g. alpha, beta, rc + preReleaseName: "rc" # list of patches to be applied when `git mkver patch` is called patches: [ - # e.g. Helm + # e.g. HelmChart ] # list of formats formats: [ diff --git a/src/main/scala/net/cardnell/mkver/AppConfig.scala b/src/main/scala/net/cardnell/mkver/AppConfig.scala index af1dbfb..5adb4a1 100644 --- a/src/main/scala/net/cardnell/mkver/AppConfig.scala +++ b/src/main/scala/net/cardnell/mkver/AppConfig.scala @@ -1,5 +1,7 @@ package net.cardnell.mkver +import java.io + import zio.IO import zio.config._ import ConfigDescriptor._ @@ -9,6 +11,7 @@ import ConfigDocs.Details._ import better.files.File import com.typesafe.config.ConfigFactory import zio.config.typesafe.{TypeSafeConfigSource, TypesafeConfig} +import cats.implicits._ case class Format(name: String, format: String) object Format { @@ -50,9 +53,9 @@ object BranchConfig { nameDesc.default(".*") |@| prefixDesc.default("v") |@| tagDesc.default(false) |@| - tagFormatDesc.default("version") |@| + tagFormatDesc.default("VersionBuildMetaData") |@| tagMessageFormatDesc.default("release {Version}") |@| - preReleaseNameDesc.default("rc.") |@| + preReleaseNameDesc.default("rc") |@| formatsDesc.default(Nil) |@| patchesDesc.default(Nil) )(BranchConfig.apply, BranchConfig.unapply) @@ -89,24 +92,25 @@ object AppConfig { nested("patches")(list(PatchConfig.patchConfigDesc)) )(AppConfig.apply, AppConfig.unapply) - def getBranchConfig(configFile: Option[String], currentBranch: String): BranchConfig = { - val appConfig = getAppConfig(configFile) - val defaults = appConfig.defaults - - val branchConfig = appConfig.branches.find { bc => currentBranch.matches(bc.name) } - - branchConfig.map { bc => - BranchConfig( - name = bc.name, - prefix = bc.prefix.getOrElse(defaults.prefix), - tag = bc.tag.getOrElse(defaults.tag), - tagFormat = bc.tagFormat.getOrElse(defaults.tagFormat), - tagMessageFormat = bc.tagMessageFormat.getOrElse(defaults.tagMessageFormat), - preReleaseName = bc.preReleaseName.getOrElse(defaults.preReleaseName), - formats = mergeFormats(bc.formats.getOrElse(Nil), defaults.formats), - patches = bc.patches.getOrElse(defaults.patches) - ) - }.getOrElse(defaults) + def getBranchConfig(configFile: Option[String], currentBranch: String): Either[MkVerError, BranchConfig] = { + getAppConfig(configFile).map { appConfig => + val defaults = appConfig.defaults + + val branchConfig = appConfig.branches.find { bc => currentBranch.matches(bc.name) } + + branchConfig.map { bc => + BranchConfig( + name = bc.name, + prefix = bc.prefix.getOrElse(defaults.prefix), + tag = bc.tag.getOrElse(defaults.tag), + tagFormat = bc.tagFormat.getOrElse(defaults.tagFormat), + tagMessageFormat = bc.tagMessageFormat.getOrElse(defaults.tagMessageFormat), + preReleaseName = bc.preReleaseName.getOrElse(defaults.preReleaseName), + formats = mergeFormats(bc.formats.getOrElse(Nil), defaults.formats), + patches = bc.patches.getOrElse(defaults.patches) + ) + }.getOrElse(defaults) + } } def mergeFormats(branch: List[Format], defaults: List[Format]): List[Format] = { @@ -115,45 +119,60 @@ object AppConfig { val overridesMap = overrides.map( it => (it.name, it)).toMap overridesMap.values.foldLeft(startMap)((a, n) => a.+((n.name, n))).values.toList.sortBy(_.name) } - // Start with defaults - val v1 = update(defaults, branch) - val v2 = update(v1, Formatter.builtInFormats) - v2 + update(defaults, branch) } - def getPatchConfigs(configFile: Option[String], branchConfig: BranchConfig): List[PatchConfig] = { - val allPatchConfigs = getAppConfig(configFile).patches.map(it => (it.name, it)).toMap - branchConfig.patches.map( c => allPatchConfigs.get(c).orElse(sys.error(s"Can't find patch config named $c")).get) - } - - def getAppConfig(configFile: Option[String]): AppConfig = { - val file = if (configFile.exists(File(_).exists)) { - configFile - } else if (sys.env.get("GITMKVER_CONFIG").exists(File(_).exists)) { - sys.env.get("GITMKVER_CONFIG") - } else if (File("mkver.conf").exists) { - Some("mkver.conf") - } else { - None + def getPatchConfigs(configFile: Option[String], branchConfig: BranchConfig): Either[MkVerError, List[PatchConfig]] = { + getAppConfig(configFile).flatMap { appConfig => + val allPatchConfigs = appConfig.patches.map(it => (it.name, it)).toMap + val x: List[Either[MkVerError, PatchConfig]] = branchConfig.patches.map { c => + allPatchConfigs.get(c) match { + case Some(p) => Right[MkVerError, PatchConfig](p) + case None => Left[MkVerError, PatchConfig](MkVerError(s"Can't find patch config named $c")) + } + } + val y = x.sequence + y } + } - val hocon = file.map { f => - TypeSafeConfigSource.fromTypesafeConfig(ConfigFactory.parseFile(new java.io.File(f))) - // TODO Use this when in ZIO land - // TypeSafeConfigSource.fromHoconFile(new java.io.File("mkver.conf")) + def getAppConfig(configFile: Option[String]): Either[MkVerError, AppConfig] = { + val file = configFile.map { cf => + if (File(cf).exists) { + Right(Some(cf) + ) + } else { + Left(MkVerError(s"--config $cf does not exist")) + } + }.orElse { + sys.env.get("GITMKVER_CONFIG").map { cf => + if (File(cf).exists) { + Right(Some(cf)) + } else { + Left(MkVerError(s"GITMKVER_CONFIG $cf does not exist")) + } + } }.getOrElse { - TypeSafeConfigSource.fromTypesafeConfig(ConfigFactory.load("reference.conf")) + if (File("mkver.conf").exists) { + Right(Some("mkver.conf")) + } else { + Right(None) + } } - val config = - hocon match { - case Left(value) => sys.error("Unable to load config: " + value) - case Right(source) => read(AppConfig.appConfigDesc from source) + file.flatMap { of => + of.map { f => + TypeSafeConfigSource.fromTypesafeConfig(ConfigFactory.parseFile(new java.io.File(f))) + // TODO Use this when in ZIO land + // TypeSafeConfigSource.fromHoconFile(new java.io.File("mkver.conf")) + }.getOrElse { + TypeSafeConfigSource.fromTypesafeConfig(ConfigFactory.load("reference.conf")) + }.fold(l => Left(MkVerError(l)), r => Right(r)) + }.flatMap { source: ConfigSource[String, String] => + read(AppConfig.appConfigDesc from source) match { + case Left(value) => Left(MkVerError("Unable to parse config: " + value)) + case Right(result) => Right(result) } - - config match { - case Left(value) => sys.error("Unable to parse config: " + value) - case Right(result) => result } } } diff --git a/src/main/scala/net/cardnell/mkver/CommandLineArgs.scala b/src/main/scala/net/cardnell/mkver/CommandLineArgs.scala index 69afc96..c419e48 100644 --- a/src/main/scala/net/cardnell/mkver/CommandLineArgs.scala +++ b/src/main/scala/net/cardnell/mkver/CommandLineArgs.scala @@ -4,15 +4,19 @@ import com.monovore.decline.{Command, Opts} import cats.implicits._ object CommandLineArgs { - case class NextOpts(format: Option[String]) + case class NextOpts(format: Option[String], prefix: Boolean) case class TagOpts(format: Option[String]) case class PatchOpts(format: Option[String]) + case class InfoOpts(includeBranchConfig: Boolean) val configFile: Opts[Option[String]] = Opts.option[String]("config", short = "c", metavar = "file", help = "Config file to load").orNone val format: Opts[Option[String]] = Opts.option[String]("format", short = "f", metavar = "string", help = "Format string for the version number").orNone - val nextOptions: Opts[NextOpts] = format.map(NextOpts.apply) + val prefix: Opts[Boolean] = Opts.flag("prefix", short = "p", help = "Include the tag prefix in the output").orFalse + val includeBranchConfig: Opts[Boolean] = Opts.flag("include-branch-config", short = "i", help = "Format string for the version number").orTrue + val nextOptions: Opts[NextOpts] = (format, prefix).mapN(NextOpts.apply) val tagOptions: Opts[TagOpts] = format.map(TagOpts.apply) val patchOptions: Opts[PatchOpts] = format.map(PatchOpts.apply) + val infoOptions: Opts[InfoOpts] = includeBranchConfig.map(InfoOpts.apply) val nextCommand: Command[NextOpts] = Command("next", header = "Print the next version tag that would be used") { nextOptions @@ -26,9 +30,13 @@ object CommandLineArgs { patchOptions } + val infoCommand: Command[InfoOpts] = Command("info", header = "output all formats and branch configuration") { + infoOptions + } + case class CommandLineOpts(configFile: Option[String], p: Product) - val commands: Opts[Product] = Opts.subcommands(nextCommand, tagCommand, patchCommand) + val commands: Opts[Product] = Opts.subcommands(nextCommand, tagCommand, patchCommand, infoCommand) val commandLineOpts: Opts[CommandLineOpts] = (configFile, commands).mapN(CommandLineOpts.apply) diff --git a/src/main/scala/net/cardnell/mkver/Formatter.scala b/src/main/scala/net/cardnell/mkver/Formatter.scala index fd51f38..89f08fd 100644 --- a/src/main/scala/net/cardnell/mkver/Formatter.scala +++ b/src/main/scala/net/cardnell/mkver/Formatter.scala @@ -6,11 +6,7 @@ object Formatter { Format("VersionPreRelease", "{Version}-{PreRelease}"), Format("VersionBuildMetaData", "{Version}+{BuildMetaData}"), Format("VersionPreReleaseBuildMetaData", "{Version}-{PreRelease}+{BuildMetaData}"), - ) - - val defaultFormats = List( - Format("PreRelease", "rc-{PreReleaseName}"), - Format("BuildMetaData", "{br}.{sh}"), + Format("PreRelease", "{PreReleaseName}{PreReleaseNumber}"), ) case class Formatter(formats: List[Format]) { @@ -35,6 +31,11 @@ object Formatter { def apply(version: VersionData, branchConfig: BranchConfig): Formatter = { Formatter(List( + Format("Next", "{" + branchConfig.tagFormat + "}"), + Format("Tag", "{pr}{" + branchConfig.tagFormat + "}"), + Format("TagMessage", "{" + branchConfig.tagMessageFormat + "}"), + Format("PreReleaseName", branchConfig.preReleaseName), + Format("PreReleaseNumber", ""), Format("x", version.major.toString), Format("y", version.minor.toString), Format("z", version.patch.toString), @@ -47,7 +48,7 @@ object Formatter { Format("bn", version.buildNo), Format("tag?", branchConfig.tag.toString), Format("pr", branchConfig.prefix.toString) - ) ++ branchConfig.formats + ) ++ AppConfig.mergeFormats(branchConfig.formats, builtInFormats) ++ envVariables() ++ azureDevOpsVariables()) } @@ -72,6 +73,7 @@ object Formatter { branchName .replace("refs/heads/", "") .replace("refs/", "") - .replace("/", "_") + .replace("/", "-") + .replace("_", "-") } } diff --git a/src/main/scala/net/cardnell/mkver/Main.scala b/src/main/scala/net/cardnell/mkver/Main.scala index 41017c4..20f2397 100644 --- a/src/main/scala/net/cardnell/mkver/Main.scala +++ b/src/main/scala/net/cardnell/mkver/Main.scala @@ -2,7 +2,7 @@ package net.cardnell.mkver import better.files._ import net.cardnell.mkver.MkVer._ -import net.cardnell.mkver.CommandLineArgs.{CommandLineOpts, NextOpts, PatchOpts, TagOpts} +import net.cardnell.mkver.CommandLineArgs.{CommandLineOpts, InfoOpts, NextOpts, PatchOpts, TagOpts} case class ProcessResult(stdout: String, stderr: String, exitCode: Int) @@ -29,15 +29,19 @@ class Main(git: Git.Service = Git.Live.git()) { def run(opts: CommandLineOpts): Either[MkVerError, String] = { git.checkGitRepo().flatMap { _ => val currentBranch = git.currentBranch() - val config = AppConfig.getBranchConfig(opts.configFile, currentBranch) - opts.p match { - case nextOps@NextOpts(_) => - runNext(nextOps, config, currentBranch) - case TagOpts(_) => - runTag(config, currentBranch).map(_ => "") - case PatchOpts(_) => - val patchConfigs = AppConfig.getPatchConfigs(opts.configFile, config) - runPatch(config, currentBranch, patchConfigs).map(_ => "") + AppConfig.getBranchConfig(opts.configFile, currentBranch).flatMap { config => + opts.p match { + case nextOps@NextOpts(_, _) => + runNext(nextOps, config, currentBranch) + case TagOpts(_) => + runTag(config, currentBranch).map(_ => "") + case PatchOpts(_) => + AppConfig.getPatchConfigs(opts.configFile, config).flatMap { patchConfigs => + runPatch(config, currentBranch, patchConfigs).map(_ => "") + } + case InfoOpts(includeBranchConfig) => + runInfo(config, currentBranch, includeBranchConfig) + } } } } @@ -47,7 +51,7 @@ class Main(git: Git.Service = Git.Live.git()) { nextOpts.format.map { format => Right(Formatter(nextVersion, config).format(format)) }.getOrElse { - formatTag(config, nextVersion) + formatTag(config, nextVersion, nextOpts.prefix) } } } @@ -78,4 +82,20 @@ class Main(git: Git.Service = Git.Live.git()) { } } } + + def runInfo(config: BranchConfig, currentBranch: String, includeBranchConfig: Boolean): Either[MkVerError, String] = { + getNextVersion(git, config, currentBranch).map { nextVersion => + val formatter = Formatter(nextVersion, config) + val formats = formatter.formats.map { format => + val result = formatter.format(format.format) + s"${format.name}=$result" + }.mkString(System.lineSeparator()) + + if (includeBranchConfig) { + config.toString + System.lineSeparator() + System.lineSeparator() + formats + } else { + formats + } + } + } } diff --git a/src/main/scala/net/cardnell/mkver/MkVer.scala b/src/main/scala/net/cardnell/mkver/MkVer.scala index a5def29..1616004 100644 --- a/src/main/scala/net/cardnell/mkver/MkVer.scala +++ b/src/main/scala/net/cardnell/mkver/MkVer.scala @@ -63,12 +63,16 @@ object MkVer { } } - def formatTag(config: BranchConfig, versionData: VersionData): Either[MkVerError, String] = { + def formatTag(config: BranchConfig, versionData: VersionData, formatAsTag: Boolean = true): Either[MkVerError, String] = { val allowedFormats = Formatter.builtInFormats.map(_.name) if (!allowedFormats.contains(config.tagFormat)) { Left(MkVerError(s"tagFormat (${config.tagFormat}) must be one of: ${allowedFormats.mkString(", ")}")) } else { - Right(Formatter(versionData, config).format(s"${config.prefix}{${config.tagFormat}}")) + if (formatAsTag) { + Right(Formatter(versionData, config).format("{Tag}")) + } else { + Right(Formatter(versionData, config).format("{Next}")) + } } } diff --git a/src/test/scala/net/cardnell/mkver/AppConfigSpec.scala b/src/test/scala/net/cardnell/mkver/AppConfigSpec.scala index 66b7548..cbb5150 100644 --- a/src/test/scala/net/cardnell/mkver/AppConfigSpec.scala +++ b/src/test/scala/net/cardnell/mkver/AppConfigSpec.scala @@ -6,13 +6,17 @@ import org.scalatest.matchers.should.Matchers class AppConfigSpec extends AnyFlatSpec with Matchers { "getBranchConfig for master" should "return master config" in { - val branchConfig = AppConfig.getBranchConfig(None, "master") - branchConfig.name should be("master") + AppConfig.getBranchConfig(None, "master") match { + case Left(_) => fail() + case Right(branchConfig) => branchConfig.name should be("master") + } } "getBranchConfig for feat" should "return .* config" in { - val branchConfig = AppConfig.getBranchConfig(None, "feat/f1") - branchConfig.name should be(".*") + val branchConfig = AppConfig.getBranchConfig(None, "feat/f1") match { + case Left(_) => fail() + case Right(branchConfig) => branchConfig.name should be(".*") + } } "mergeFormats" should "merge formats" in { @@ -21,12 +25,12 @@ class AppConfigSpec extends AnyFlatSpec with Matchers { val f3 = Format("f3", "v3") val f1b = Format("f1", "v4") val result = AppConfig.mergeFormats(List(f1b, f2), List(f1, f3)) - result should be((Formatter.builtInFormats ++ List(f1b, f2, f3)).sortBy(_.name)) + result should be(List(f1b, f2, f3).sortBy(_.name)) } "getPatchConfigs" should "return nothing in reference config" in { val branchConfig = BranchConfig(".*", "v", true, "Version", "release {Version}", "RC", Nil, Nil) val patchConfigs = AppConfig.getPatchConfigs(None, branchConfig) - patchConfigs should be(Nil) + patchConfigs should be(Right(Nil)) } } diff --git a/src/test/scala/net/cardnell/mkver/EndToEndTests.scala b/src/test/scala/net/cardnell/mkver/EndToEndTests.scala index 4d9e238..ce661e6 100644 --- a/src/test/scala/net/cardnell/mkver/EndToEndTests.scala +++ b/src/test/scala/net/cardnell/mkver/EndToEndTests.scala @@ -10,7 +10,7 @@ class EndToEndTests extends AnyFlatSpec with Matchers { File.usingTemporaryDirectory("git-mkver") { tempDir => init(tempDir) fix("code1.py", tempDir) - run(tempDir, "next") should be(Right("v0.1.0")) + run(tempDir, "next") should be(Right("0.1.0")) } } @@ -20,7 +20,7 @@ class EndToEndTests extends AnyFlatSpec with Matchers { fix("code1.py", tempDir) run(tempDir, "tag") fix("code2.py", tempDir) - run(tempDir, "next") should be(Right("v0.1.1")) + run(tempDir, "next") should be(Right("0.1.1")) println(ProcessUtils.exec("git log --graph --full-history --color --oneline", Some(tempDir)).stdout) } } @@ -35,7 +35,7 @@ class EndToEndTests extends AnyFlatSpec with Matchers { checkout("master", tempDir) major("code3.py", tempDir) merge("feature/f1", tempDir) - run(tempDir, "next") should be(Right("v1.0.0")) + run(tempDir, "next") should be(Right("1.0.0")) println(ProcessUtils.exec("git log --graph --full-history --color --oneline", Some(tempDir)).stdout) } } @@ -50,7 +50,7 @@ class EndToEndTests extends AnyFlatSpec with Matchers { checkout("master", tempDir) feat("code3.py", tempDir) merge("feature/f1", tempDir) - run(tempDir, "next") should be(Right("v1.0.0")) + run(tempDir, "next") should be(Right("1.0.0")) println(ProcessUtils.exec("git log --graph --full-history --color --oneline", Some(tempDir)).stdout) } } @@ -71,7 +71,7 @@ class EndToEndTests extends AnyFlatSpec with Matchers { merge("feature/f1", tempDir) merge("feature/f2", tempDir) - run(tempDir, "next") should be(Right("v1.0.0")) + run(tempDir, "next") should be(Right("1.0.0")) println(ProcessUtils.exec("git log --graph --full-history --color --oneline", Some(tempDir)).stdout) } } diff --git a/src/test/scala/net/cardnell/mkver/FormatterSpec.scala b/src/test/scala/net/cardnell/mkver/FormatterSpec.scala index 12afb9e..112f4b0 100644 --- a/src/test/scala/net/cardnell/mkver/FormatterSpec.scala +++ b/src/test/scala/net/cardnell/mkver/FormatterSpec.scala @@ -26,7 +26,7 @@ class FormatterSpec extends AnyFlatSpec with Matchers { } "branchNameToVariable" should "replace variables" in { - Formatter.branchNameToVariable("refs/heads/feat/f1") should be("feat_f1") + Formatter.branchNameToVariable("refs/heads/feat/f1") should be("feat-f1") } "Formatter" should "default list" in { @@ -37,6 +37,6 @@ class FormatterSpec extends AnyFlatSpec with Matchers { formatter.format("{x}") should be("1") formatter.format("{y}") should be("2") formatter.format("{z}") should be("3") - formatter.format("{br}") should be("feature_f1") + formatter.format("{br}") should be("feature-f1") } } diff --git a/src/test/scala/net/cardnell/mkver/MainSpec.scala b/src/test/scala/net/cardnell/mkver/MainSpec.scala index 95b458c..5439a4c 100644 --- a/src/test/scala/net/cardnell/mkver/MainSpec.scala +++ b/src/test/scala/net/cardnell/mkver/MainSpec.scala @@ -12,18 +12,19 @@ class MainSpec extends AnyFlatSpec with Matchers { override def checkGitRepo(): Either[MkVerError, Unit] = Right(()) } - "next" should "return " in { + "next" should "return" in { val result = new Main(fakeGit("master", "", "v0.0.0-1-gabcdef")).mainImpl(Array("next")) - result should be(Right("v0.1.0")) + result should be(Right("0.1.0")) } - "tag" should "return " in { + "tag" should "return" in { val result = new Main(fakeGit("master", "", "v0.0.0-1-gabcdef")).mainImpl(Array("tag")) result should be(Right("")) } - "patch" should "return " in { - val result = new Main(fakeGit("master", "", "v0.0.0-1-gabcdef")).mainImpl(Array("patch")) - result should be(Right("")) - } + // TODO stop this actually patching files! +// "patch" should "return " in { +// val result = new Main(fakeGit("master", "", "v0.0.0-1-gabcdef")).mainImpl(Array("patch")) +// result should be(Right("")) +// } }