Skip to content

Commit b492ef4

Browse files
committed
Fix SimpleRepository info parsing when the created_on has no miliseconds
1 parent 359d414 commit b492ef4

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/main/scala/com/codacy/client/bitbucket/Repository.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ case class Repository(name: String, full_name: String, description: String, scm:
1111

1212
object Repository {
1313
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZ"
14+
val dateFormatWithoutMillis = "yyyy-MM-dd'T'HH:mm:ssZZ"
15+
1416
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
17+
.orElse(Reads.jodaDateReads(dateFormatWithoutMillis))
1518

1619
implicit val reader: Reads[Repository] = {
1720
((__ \ "name").read[String] and

src/main/scala/com/codacy/client/bitbucket/SimpleRepository.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ case class SimpleRepository(name: String, description: String, scm: String, crea
1414

1515
object SimpleRepository {
1616
val dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
17+
val dateFormatWithoutMillis = "yyyy-MM-dd'T'HH:mm:ss"
18+
1719
implicit val jodaDateTimeReads = Reads.jodaDateReads(dateFormat)
20+
.orElse(Reads.jodaDateReads(dateFormatWithoutMillis))
1821

1922
implicit val reader: Reads[SimpleRepository] =
2023
((__ \ "slug").read[String] and
@@ -27,5 +30,5 @@ object SimpleRepository {
2730
(__ \ "has_issues").read[Boolean] and
2831
(__ \ "is_private").read[Boolean] and
2932
(__ \ "language").read[String]
30-
)(SimpleRepository.apply _)
33+
) (SimpleRepository.apply _)
3134
}

src/test/scala/RemoteRepositorySpecs.scala

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,48 @@ class RemoteRepositorySpecs extends FlatSpec with Matchers {
462462
repo => repo.length shouldBe 2
463463
)
464464
}
465+
466+
it should "successfully parse a JSON into an array of SimpleRepository that has no milliseconds on the created date" in {
467+
468+
val input =
469+
"""[
470+
|{
471+
| "scm": "git",
472+
| "has_wiki": false,
473+
| "last_updated": "2016-01-26T21:39:24.485",
474+
| "no_forks": false,
475+
| "created_on": "2015-09-04T20:33:22",
476+
| "owner": "carrots",
477+
| "logo": "https://bitbucket.org/carrots/potatos/avatar/32/?ts=1453840764",
478+
| "email_mailinglist": "",
479+
| "is_mq": false,
480+
| "size": 14544338,
481+
| "read_only": false,
482+
| "fork_of": null,
483+
| "mq_of": null,
484+
| "state": "available",
485+
| "utc_created_on": "2015-09-04 18:37:22+00:00",
486+
| "website": "",
487+
| "description": "",
488+
| "has_issues": false,
489+
| "is_fork": false,
490+
| "slug": "potatos",
491+
| "is_private": true,
492+
| "name": "Carrots and company",
493+
| "language": "",
494+
| "utc_last_updated": "2016-01-26 20:39:24+00:00",
495+
| "no_public_forks": true,
496+
| "creator": null,
497+
| "resource_uri": "/1.0/repositories/carrots/potatos"
498+
|}
499+
|]
500+
""".stripMargin
501+
val json = Json.parse(input)
502+
val value = json.validate[Seq[SimpleRepository]]
503+
504+
value.fold(e =>
505+
fail(s"$e"),
506+
repo => repo.length shouldBe 1
507+
)
508+
}
465509
}

0 commit comments

Comments
 (0)