Skip to content

Commit 32ebf8f

Browse files
fix: accept Repository without optional fields in json (#127)
1 parent 8859725 commit 32ebf8f

File tree

3 files changed

+115
-10
lines changed

3 files changed

+115
-10
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ case class Repository(
1212
description: String,
1313
scm: String,
1414
created_on: LocalDateTime,
15-
updated_on: LocalDateTime,
15+
updated_on: Option[LocalDateTime],
1616
owner: Owner,
17-
size: Long,
18-
has_issues: Boolean,
17+
size: Option[Long],
18+
has_issues: Option[Boolean],
1919
is_private: Boolean,
20-
language: String,
20+
language: Option[String],
2121
urls: Seq[RepositoryUrl],
2222
uuid: String,
2323
slug: String
@@ -36,15 +36,15 @@ object Repository {
3636
implicit val reader: Reads[Repository] = {
3737
((__ \ "name").read[String] and
3838
(__ \ "full_name").read[String] and
39-
(__ \ "description").read[String] and
39+
(__ \ "description").read[String] and
4040
(__ \ "scm").read[String] and
4141
(__ \ "created_on").read[LocalDateTime] and
42-
(__ \ "updated_on").read[LocalDateTime] and
42+
(__ \ "updated_on").readNullable[LocalDateTime] and
4343
(__ \ "owner").read[Owner] and
44-
(__ \ "size").read[Long] and
45-
(__ \ "has_issues").read[Boolean] and
44+
(__ \ "size").readNullable[Long] and
45+
(__ \ "has_issues").readNullable[Boolean] and
4646
(__ \ "is_private").read[Boolean] and
47-
(__ \ "language").read[String] and
47+
(__ \ "language").readNullable[String] and
4848
(__ \ "links").read[Map[String, JsValue]].map(parseLinks) and
4949
(__ \ "uuid" ).read[String] and
5050
(__ \ "slug" ).read[String]
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
"type": "repository",
3+
"full_name": "adinsbitbucket2/atacso-new",
4+
"links": {
5+
"self": {
6+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new"
7+
},
8+
"html": {
9+
"href": "https://bitbucket.org/adinsbitbucket2/atacso-new"
10+
},
11+
"avatar": {
12+
"href": "https://bytebucket.org/ravatar/%7Ba0eed669-d61c-429d-91d7-9c140adf32c5%7D?ts=default"
13+
},
14+
"pullrequests": {
15+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/pullrequests"
16+
},
17+
"commits": {
18+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/commits"
19+
},
20+
"forks": {
21+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/forks"
22+
},
23+
"watchers": {
24+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/watchers"
25+
},
26+
"branches": {
27+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/refs/branches"
28+
},
29+
"tags": {
30+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/refs/tags"
31+
},
32+
"downloads": {
33+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/downloads"
34+
},
35+
"source": {
36+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/src"
37+
},
38+
"clone": [
39+
{
40+
"name": "https",
41+
"href": "https://willisadins@bitbucket.org/adinsbitbucket2/atacso-new.git"
42+
}, {
43+
"name": "ssh",
44+
"href": "git@bitbucket.org:adinsbitbucket2/atacso-new.git"
45+
}
46+
],
47+
"hooks": {
48+
"href": "https://bitbucket.org/!api/2.0/repositories/adinsbitbucket2/atacso-new/hooks"
49+
}
50+
},
51+
"name": "ATACSO New",
52+
"slug": "atacso-new",
53+
"description": "",
54+
"scm": "git",
55+
"website": null,
56+
"owner": {
57+
"display_name": "AdInsBitBucket2",
58+
"links": {
59+
"self": {
60+
"href": "https://bitbucket.org/!api/2.0/workspaces/%7Bee3b0b8f-7a8b-4aa3-b09e-76b0b1068b42%7D"
61+
},
62+
"avatar": {
63+
"href": "https://bitbucket.org/account/adinsbitbucket2/avatar/"
64+
},
65+
"html": {
66+
"href": "https://bitbucket.org/%7Bee3b0b8f-7a8b-4aa3-b09e-76b0b1068b42%7D/"
67+
}
68+
},
69+
"type": "team",
70+
"uuid": "{ee3b0b8f-7a8b-4aa3-b09e-76b0b1068b42}",
71+
"username": "adinsbitbucket2"
72+
},
73+
"workspace": {
74+
"type": "workspace",
75+
"uuid": "{ee3b0b8f-7a8b-4aa3-b09e-76b0b1068b42}",
76+
"name": "AdInsBitBucket2",
77+
"slug": "adinsbitbucket2",
78+
"links": {
79+
"avatar": {
80+
"href": "https://bitbucket.org/workspaces/adinsbitbucket2/avatar/?ts=1709775650"
81+
},
82+
"html": {
83+
"href": "https://bitbucket.org/adinsbitbucket2/"
84+
},
85+
"self": {
86+
"href": "https://bitbucket.org/!api/2.0/workspaces/adinsbitbucket2"
87+
}
88+
}
89+
},
90+
"is_private": false,
91+
"created_on": "2024-03-05T08:07:33.038149+00:00",
92+
"uuid": "{a0eed669-d61c-429d-91d7-9c140adf32c5}",
93+
"override_settings": {
94+
"default_merge_strategy": true,
95+
"branching_model": true
96+
},
97+
"parent": null
98+
}

src/test/scala/com/codacy/client/bitbucket/v2/RepositorySpecs.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.codacy.client.bitbucket.v2
2+
import com.codacy.client.bitbucket.TestUtils
23
import org.scalatest.{Matchers, _}
3-
import play.api.libs.json.Json
4+
import play.api.libs.json.{JsSuccess, Json}
45

56
class RepositorySpecs extends FlatSpec with Matchers {
67

@@ -136,4 +137,10 @@ class RepositorySpecs extends FlatSpec with Matchers {
136137
r.owner.display_name shouldBe "John Mulligan"
137138
})
138139
}
140+
141+
it should "parse minimal repository without optional fields" in {
142+
val rawJson = TestUtils.getTestContent("/test-files/minimal_repository.json")
143+
val value = Json.parse(rawJson).validate[Repository]
144+
value shouldBe a[JsSuccess[_]]
145+
}
139146
}

0 commit comments

Comments
 (0)