-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from numa08/empty-note
Donesn't write message when comment is empty
- Loading branch information
Showing
6 changed files
with
94 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
package net.numa08.genrelease | ||
|
||
trait ReleaseNote { | ||
val releases: Seq[Release] | ||
|
||
val features: Seq[Feature] | ||
|
||
val fixes: Seq[Fix] | ||
|
||
val version: String | ||
|
||
val version: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
package net.numa08.genrelease | ||
|
||
trait ReleaseType{ | ||
case class Scope(scope: String) | ||
|
||
val scope: String | ||
sealed trait ReleaseType { | ||
val subject: String | ||
|
||
} | ||
|
||
case class Feature(scope: String, subject: String) extends ReleaseType | ||
case class Fix(scope: String, subject: String) extends ReleaseType | ||
|
||
case class Feature(subject: String) extends ReleaseType | ||
|
||
case class Fix(subject: String) extends ReleaseType | ||
|
||
object ReleaseType { | ||
|
||
def apply(t: String, scope: String, subject: String): ReleaseType = t match { | ||
case "fix" => Fix(scope, subject) | ||
case "feat" => Feature(scope, subject) | ||
def apply(t: String, subject: String): ReleaseType = t match { | ||
case "fix" => Fix(subject) | ||
case "feat" => Feature(subject) | ||
case _ => throw UnKnownTypeException(s"$t is unknown type") | ||
} | ||
|
||
} | ||
|
||
sealed trait Release {} | ||
|
||
case class Features(releases: Map[Scope, Seq[Feature]]) extends Release | ||
|
||
case class Fixes(releases: Map[Scope, Seq[Fix]]) extends Release | ||
|
||
case object Empty extends Release | ||
|
||
object Release { | ||
|
||
def apply[T <: ReleaseType](r: Map[Scope, Seq[T]]): Release = if (r.isEmpty) { | ||
Empty | ||
} else { | ||
r.values.head.head match { | ||
case Feature(_) => Features(r.asInstanceOf[Map[Scope, Seq[Feature]]]) | ||
case Fix(_) => Fixes(r.asInstanceOf[Map[Scope, Seq[Fix]]]) | ||
} | ||
} | ||
|
||
} | ||
|
||
case class UnKnownTypeException(message: String) extends RuntimeException(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 23 additions & 22 deletions
45
src/main/scala/net/numa08/genrelease/markdown/MarkdownConverter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
package net.numa08.genrelease.markdown | ||
|
||
import net.numa08.genrelease.{NoteConverter, ReleaseNote, ReleaseType} | ||
import net.numa08.genrelease._ | ||
|
||
class MarkdownConverter extends NoteConverter { | ||
|
||
override def convert(note: ReleaseNote): String = { | ||
val features = note.features.groupBy(_.scope) | ||
val fixes = note.fixes.groupBy(_.scope) | ||
override def convert(note: ReleaseNote): String = note.releases.map(makeMarkdown).mkString | ||
|
||
def makeMarkdown(keys: Iterable[String], notes: Map[String, Seq[ReleaseType]]): String = { | ||
(for (key <- keys) yield { | ||
val indexes = notes(key).map(_.subject).mkString(" - ", "\n - ", "") | ||
s""" | ||
|### $key | ||
| | ||
|$indexes | ||
|""".stripMargin | ||
}).mkString("") | ||
} | ||
|
||
|
||
s""" | ||
|## 新機能 | ||
|${makeMarkdown(features.keys, features)} | ||
|## 不具合修正 | ||
|${makeMarkdown(fixes.keys, fixes)} | ||
|""".stripMargin | ||
def make(release: Map[Scope, Seq[ReleaseType]]): String = { | ||
(for (k <- release.keys) yield { | ||
val i = release(k).map(_.subject).mkString(" - ", "\n - ", "") | ||
s""" | ||
|### ${k.scope} | ||
|$i | ||
""".stripMargin | ||
}).mkString | ||
} | ||
|
||
def makeMarkdown(release: Release): String = release match { | ||
case Empty => "" | ||
case Features(r) => | ||
s""" | ||
|## 新機能 | ||
|${make(r)} | ||
""".stripMargin | ||
case Fixes(r) => | ||
s""" | ||
|## 不具合修正 | ||
|${make(r)} | ||
""".stripMargin | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 23 additions & 11 deletions
34
src/test/scala/net/numa08/genrelease/markdown/MarkdownConverterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,43 @@ | ||
package net.numa08.genrelease.markdown | ||
|
||
import net.numa08.genrelease.{Feature, Fix, ReleaseNote} | ||
import net.numa08.genrelease._ | ||
import org.junit.runner.RunWith | ||
import org.scalatest.junit.JUnitRunner | ||
import org.scalatest.{FlatSpec, Matchers} | ||
|
||
import scala.collection.immutable.Stream.Empty | ||
|
||
@RunWith(classOf[JUnitRunner]) | ||
class MarkdownConverterSpec extends FlatSpec with Matchers { | ||
|
||
"MarkdownExporter" should "export markdown" in { | ||
val note = new ReleaseNote { | ||
override val fixes: Seq[Fix] = List( | ||
Fix("なんとか機能", "もうクラッシュなんてしない"), | ||
Fix("ほげ機能", "今度こそ大丈夫"), | ||
Fix("なんとか機能", "もう大丈夫") | ||
) | ||
override val version: String = "test" | ||
|
||
override val features: Seq[Feature] = List( | ||
Feature("むっちゃ使う機能", "驚天動地の最新機能"), | ||
Feature("微妙な機能", "いい感じやで"), | ||
Feature("むっちゃ使う機能", "めっちゃ使いやすくなった") | ||
override val releases: Seq[Release] = List( | ||
Release( | ||
Map((Scope("むっちゃ使う機能"), Feature("驚天動地の最新機能") :: Feature("めっちゃ使いやすくなった") :: Nil), | ||
(Scope("微妙な機能"), Feature("いい感じやで") :: Nil)) | ||
), | ||
Release( | ||
Map((Scope("なんとか機能"), Fix("もうクラッシュなんてしない") :: Fix("もう大丈夫") :: Nil), | ||
(Scope("ほげ機能"), Fix("今度こそ大丈夫") :: Nil)) | ||
) | ||
) | ||
override val version: String = "test" | ||
} | ||
|
||
val markdown = new MarkdownConverter().convert(note) | ||
println(markdown) | ||
|
||
} | ||
|
||
"Empty message" should "export empty markdown" in { | ||
val note = new ReleaseNote { | ||
override val releases: Seq[Release] = Empty | ||
override val version: String = "test" | ||
} | ||
|
||
val markdown = new MarkdownConverter().convert(note) | ||
assert(markdown.isEmpty) | ||
} | ||
} |