From 54e406b78f967a7ec2336ef8454c8c3e15ac8126 Mon Sep 17 00:00:00 2001 From: zumhagen Date: Fri, 30 Jun 2017 10:35:04 -0500 Subject: [PATCH] Add requirement that markdown cannot be generated with empty changes version: 0.7.0 tag: Added --- .travis.yml | 2 +- build.sbt | 4 +--- .../com/github/bzumhagen/sct/git/GitChangelog.scala | 5 +++-- .../com/github/bzumhagen/sct/git/GitChangelogTest.scala | 9 +++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1442386..a1b5b3e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,8 @@ before_install: - openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in credentials.sbt.enc -out local.credentials.sbt -d script: - sbt clean coverage test coverageReport coverageAggregate -after_success: - sbt coveralls +- sbt clean compile - sbt "+ publish-signed" - sbt "+ sonatypeRelease" env: diff --git a/build.sbt b/build.sbt index e4ec6a1..b11a098 100644 --- a/build.sbt +++ b/build.sbt @@ -2,7 +2,7 @@ name := "sct" organization := "com.github.bzumhagen" -version := "0.6.0" +version := "0.7.0" scalaVersion := "2.12.1" @@ -31,8 +31,6 @@ def betterFiles(scalaVersion: String) = scalaVersion match { case _ => "com.github.pathikrit" %% "better-files" % "2.17.0" } -coverageEnabled := true - pgpSecretRing := file("local.secring.asc") pgpPublicRing := file("local.pubring.asc") diff --git a/src/main/scala/com/github/bzumhagen/sct/git/GitChangelog.scala b/src/main/scala/com/github/bzumhagen/sct/git/GitChangelog.scala index acb16de..2954684 100644 --- a/src/main/scala/com/github/bzumhagen/sct/git/GitChangelog.scala +++ b/src/main/scala/com/github/bzumhagen/sct/git/GitChangelog.scala @@ -26,6 +26,8 @@ class GitChangelog(val config: ChangelogConfiguration, val gitDir: File) extends } override def generateMarkdown(file: File, changes: Seq[ChangelogChange]): File = { + require(changes.nonEmpty, "Cannot generate markdown without changes") + val engine = new TemplateEngine val changeBindings = buildChangeBindings(changes) val nameBinding = Map("name" -> config.name) @@ -72,8 +74,7 @@ class GitChangelog(val config: ChangelogConfiguration, val gitDir: File) extends case _ => None } - private def buildChangeBindings( - changes: Seq[ChangelogChange]): Map[String, Any] = + private def buildChangeBindings(changes: Seq[ChangelogChange]): Map[String, Any] = if (config.smartGrouping) { val latestVersion = changes.maxBy(_.version).version val latestPatchChanges = changes.filter { change => diff --git a/src/test/scala/com/github/bzumhagen/sct/git/GitChangelogTest.scala b/src/test/scala/com/github/bzumhagen/sct/git/GitChangelogTest.scala index f61dd44..6a87cb5 100644 --- a/src/test/scala/com/github/bzumhagen/sct/git/GitChangelogTest.scala +++ b/src/test/scala/com/github/bzumhagen/sct/git/GitChangelogTest.scala @@ -199,4 +199,13 @@ class GitChangelogTest extends FlatSpec with Matchers { val actualChanges = gitChangelog.getChanges gitChangelog.generateMarkdown(changelogFile, actualChanges).contentAsString shouldBe expectedMarkdown } + + it should "fail if no changes are provided to markdown generation" in { + val gitChangelog = new GitChangelog(DefaultConfiguration, File.newTemporaryDirectory()) + val changelogFile = File.newTemporaryFile("changelogTestFile") + + assertThrows[IllegalArgumentException] { + gitChangelog.generateMarkdown(changelogFile, Seq()) + } + } }