Skip to content

Commit 9c26378

Browse files
committed
feat: expand basecommit fields & add more nullable (ala-797)
1 parent b47c234 commit 9c26378

File tree

4 files changed

+138
-18
lines changed

4 files changed

+138
-18
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,32 @@ import play.api.libs.json._
66
import java.time.LocalDateTime
77

88
case class Account(
9-
uuid: String,
10-
username: String,
9+
uuid: Option[String],
10+
accountId: Option[String],
11+
username: Option[String],
1112
displayName: Option[String],
13+
nickname: Option[String],
1214
avatarLink: Option[String],
13-
createdOn: LocalDateTime
14-
)
15+
createdOn: Option[LocalDateTime]
16+
) {
17+
18+
def getIdentifier: Option[String] =
19+
List(uuid, accountId).find(_.isDefined).flatten
20+
21+
def getName: Option[String] =
22+
List(username, displayName, nickname).find(_.isDefined).flatten
23+
}
1524

1625
object Account {
1726

1827
implicit val accountReads: Reads[Account] = (
19-
(__ \ "uuid").read[String] and
20-
(__ \ "username").read[String] and
28+
(__ \ "uuid").readNullable[String] and
29+
(__ \ "account_id").readNullable[String] and
30+
(__ \ "username").readNullable[String] and
2131
(__ \ "display_name").readNullable[String] and
32+
(__ \ "nickname").readNullable[String] and
2233
(__ \ "links" \ "avatar" \ "href").readNullable[String] and
23-
(__ \ "created_on").read[LocalDateTime]
34+
(__ \ "created_on").readNullable[LocalDateTime]
2435
)(Account.apply _)
2536

2637
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"type": "commit",
3+
"hash": "62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b",
4+
"date": "2023-10-04T07:47:43+00:00",
5+
"author": {
6+
"type": "author",
7+
"raw": "integrationtest <[email protected]>",
8+
"user": {
9+
"display_name": "integrationtest",
10+
"links": {
11+
"self": {
12+
"href": "https://bitbucket.org/!api/2.0/users/%7B33caa461-1dd0-425d-a569-281bfdfe7431%7D"
13+
},
14+
"avatar": {
15+
"href": "https://secure.gravatar.com/avatar/14eb94da37830f3dc181afb0eb562086?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FI-1.png"
16+
},
17+
"html": {
18+
"href": "https://bitbucket.org/%7B33caa461-1dd0-425d-a569-281bfdfe7431%7D/"
19+
}
20+
},
21+
"type": "user",
22+
"uuid": "{33caa461-1dd0-425d-a569-281bfdfe7431}",
23+
"account_id": "5e7e1b2c0c8c030c39aa03d6",
24+
"nickname": "integrationtest"
25+
}
26+
},
27+
"message": "test 2",
28+
"summary": {
29+
"type": "rendered",
30+
"raw": "test 2",
31+
"markup": "markdown",
32+
"html": "<p>test 2</p>"
33+
},
34+
"links": {
35+
"self": {
36+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/commit/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b"
37+
},
38+
"html": {
39+
"href": "https://bitbucket.org/integrationtestsadmin/integration-test-repo1/commits/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b"
40+
},
41+
"diff": {
42+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/diff/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b"
43+
},
44+
"approve": {
45+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/commit/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b/approve"
46+
},
47+
"comments": {
48+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/commit/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b/comments"
49+
},
50+
"statuses": {
51+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/commit/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b/statuses"
52+
},
53+
"patch": {
54+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/patch/62de4d69c4ef7d6bc7a0725da9694b8c0d70b42b"
55+
}
56+
},
57+
"parents": [
58+
{
59+
"hash": "16ee7641208c284c2a16b67dcfdfd6e4be54c58b",
60+
"links": {
61+
"self": {
62+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1/commit/16ee7641208c284c2a16b67dcfdfd6e4be54c58b"
63+
},
64+
"html": {
65+
"href": "https://bitbucket.org/integrationtestsadmin/integration-test-repo1/commits/16ee7641208c284c2a16b67dcfdfd6e4be54c58b"
66+
}
67+
},
68+
"type": "commit"
69+
}
70+
],
71+
"rendered": {
72+
"message": {
73+
"type": "rendered",
74+
"raw": "test 2",
75+
"markup": "markdown",
76+
"html": "<p>test 2</p>"
77+
}
78+
},
79+
"repository": {
80+
"type": "repository",
81+
"full_name": "integrationtestsadmin/integration-test-repo1",
82+
"links": {
83+
"self": {
84+
"href": "https://bitbucket.org/!api/2.0/repositories/integrationtestsadmin/integration-test-repo1"
85+
},
86+
"html": {
87+
"href": "https://bitbucket.org/integrationtestsadmin/integration-test-repo1"
88+
},
89+
"avatar": {
90+
"href": "https://bytebucket.org/ravatar/%7B91601b90-9742-4ec1-b950-a091f8f57587%7D?ts=default"
91+
}
92+
},
93+
"name": "integration-test-repo1",
94+
"uuid": "{91601b90-9742-4ec1-b950-a091f8f57587}"
95+
},
96+
"participants": []
97+
}

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,32 @@ import com.codacy.client.bitbucket.TestUtils
44
import org.scalatest._
55
import play.api.libs.json.{JsError, JsSuccess, Json}
66

7-
class CommitSpecs extends FlatSpec with Matchers {
7+
class CommitSpecs extends WordSpec with Matchers {
88

9-
"Reads[BaseCommit]" should "successfully parse BaseCommit" in {
10-
val rawJson = TestUtils.getTestContent("/test-files/get_a_commit.json")
11-
val json = Json.parse(rawJson)
12-
val value = json.validate[BaseCommit]
9+
"Reads[BaseCommit]" should {
1310

14-
val expectedAvatarLink =
15-
"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:3aae1e05-702a-41e5-81c8-f36f29afb6ca/613070db-28b0-421f-8dba-ae8a87e2a5c7/128"
11+
"successfully parse default bitbucket response" in {
12+
val rawJson = TestUtils.getTestContent("/test-files/get_a_commit_1.json")
13+
val json = Json.parse(rawJson)
14+
val value = json.validate[BaseCommit]
1615

17-
value match {
18-
case JsSuccess(value, _) => assert(value.author.user.flatMap(_.avatarLink).contains(expectedAvatarLink))
19-
case JsError(errors) => fail(s"Failed with$errors")
16+
val expectedAvatarLink =
17+
"https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/557058:3aae1e05-702a-41e5-81c8-f36f29afb6ca/613070db-28b0-421f-8dba-ae8a87e2a5c7/128"
18+
19+
value match {
20+
case JsSuccess(value, _) => assert(value.author.user.flatMap(_.avatarLink).contains(expectedAvatarLink))
21+
case JsError(errors) => fail(s"Failed with$errors")
22+
}
2023
}
21-
}
2224

25+
"successfully parse default remote-provider-service integration-test-repo1 repository commit" in {
26+
val rawJson = TestUtils.getTestContent("/test-files/get_a_commit_2.json")
27+
val value = Json.parse(rawJson).validate[BaseCommit]
28+
29+
value match {
30+
case JsSuccess(value, _) => assert(value.author.user.flatMap(_.nickname).contains("integrationtest"))
31+
case JsError(errors) => fail(s"Failed with$errors")
32+
}
33+
}
34+
}
2335
}

0 commit comments

Comments
 (0)