Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ case class Repository(
language: Option[String],
urls: Seq[RepositoryUrl],
uuid: String,
slug: String
slug: String,
project: Option[Project]
)

object Repository {
Expand All @@ -32,6 +33,9 @@ object Repository {
.localDateTimeReads(dateFormat)
.orElse(Reads.localDateTimeReads(dateFormatWithoutMillis))

implicit val projectReads: Reads[Project] =
((__ \ "name").read[String] and (__ \ "key").read[String])(Project.apply _)

// format: off
implicit val reader: Reads[Repository] = {
((__ \ "name").read[String] and
Expand All @@ -47,7 +51,8 @@ object Repository {
(__ \ "language").readNullable[String] and
(__ \ "links").read[Map[String, JsValue]].map(parseLinks) and
(__ \ "uuid" ).read[String] and
(__ \ "slug" ).read[String]
(__ \ "slug" ).read[String] and
(__ \ "project").readNullable[Project]
) (Repository.apply _)
}
// format: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class RepositorySpecs extends FlatSpec with Matchers {
| "type": "repository",
| "slug": "tweakmsg",
| "is_private": false,
| "project": {"name": "tweakmsg", "key": "TWEAKMSG"},
| "description": "Mercurial (hg) extension to allow commenting on commit messages. Mainly written for practice reading & working with mercurial internals.\r\n"
|}""".stripMargin
val json = Json.parse(input)
Expand All @@ -135,6 +136,7 @@ class RepositorySpecs extends FlatSpec with Matchers {
value.fold(e => fail(s"$e"), r => {
r.name shouldBe "tweakmsg"
r.owner.display_name shouldBe "John Mulligan"
r.project.map(_.name) shouldBe Some("tweakmsg")
})
}

Expand Down