Skip to content

Commit 179ebc5

Browse files
committed
add pr actions (approve, delete approve, merge, decline)
1 parent cad153f commit 179ebc5

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
5656
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED).contains(result.status)) {
5757
val body = result.body
5858

59-
/* TODO: remove this when not needed (only keep for debug purposes) */
60-
// println("\n\n")
61-
// println(s"STATUS: ${result.status}")
62-
// println("\n\n")
63-
// println(body)
64-
// println("\n\n")
65-
6659
val jsValue = parseJson(body)
6760
jsValue match {
6861
case Right(responseObj) =>
@@ -74,6 +67,7 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
7467
RequestResponse(None, result.statusText, hasError = true)
7568
}
7669
}
70+
7771
/* copy paste from post ... */
7872
def delete[T](url: String): RequestResponse[Boolean] = {
7973
val client: WSClient = new NingWSClient(new AsyncHttpClient().getConfig)
@@ -83,8 +77,7 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
8377

8478
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED, HTTPStatusCodes.NO_CONTENT).contains(result.status)) {
8579
RequestResponse(Option(true))
86-
}
87-
else {
80+
} else {
8881
RequestResponse(None, result.statusText, hasError = true)
8982
}
9083
}
@@ -97,14 +90,6 @@ class BitbucketClient(key: String, secretKey: String, token: String, secretToken
9790

9891
if (Seq(HTTPStatusCodes.OK, HTTPStatusCodes.CREATED).contains(result.status)) {
9992
val body = result.body
100-
101-
/* TODO: remove this when not needed (only keep for debug purposes) */
102-
// println("\n\n")
103-
// println(s"STATUS: ${result.status}")
104-
// println("\n\n")
105-
// println(body)
106-
// println("\n\n")
107-
10893
parseJson(body)
10994
} else {
11095
Left(ResponseError(java.util.UUID.randomUUID().toString, result.statusText, result.statusText))

src/main/scala/com/codacy/client/bitbucket/service/PullRequestServices.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.codacy.client.bitbucket.service
22

33
import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
44
import com.codacy.client.bitbucket.{Commit, PullRequest}
5+
import play.api.libs.json.JsObject
56

67
class PullRequestServices(client: BitbucketClient) {
78

@@ -27,4 +28,24 @@ class PullRequestServices(client: BitbucketClient) {
2728
client.executePaginated(Request(url, classOf[Seq[Commit]]))
2829
}
2930

31+
def postApprove(owner: String, repository: String, prId: Long): RequestResponse[JsObject] = {
32+
val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests/$prId/approve"
33+
client.post(Request(url, classOf[JsObject]), Map.empty)
34+
}
35+
36+
def deleteApprove(owner: String, repository: String, prId: Long): RequestResponse[Boolean] = {
37+
val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests/$prId/approve"
38+
client.delete(url)
39+
}
40+
41+
def merge(owner: String, repository: String, prId: Long): RequestResponse[JsObject] = {
42+
val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests/$prId/merge"
43+
client.post(Request(url, classOf[JsObject]), Map.empty)
44+
}
45+
46+
def decline(owner: String, repository: String, prId: Long): RequestResponse[JsObject] = {
47+
val url = s"https://bitbucket.org/!api/2.0/repositories/$owner/$repository/pullrequests/$prId/decline"
48+
client.post(Request(url, classOf[JsObject]), Map.empty)
49+
}
50+
3051
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.codacy.client.bitbucket.service
22

33
import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
4-
import play.api.libs.json.JsValue
4+
import play.api.libs.json.JsObject
55

66
class UrlServices(client: BitbucketClient) {
77

88
/*
99
* Post to a api url
1010
*/
11-
def post(url: String): RequestResponse[JsValue] = {
12-
client.post(Request(url, classOf[JsValue]), Map.empty)
11+
def post(url: String): RequestResponse[JsObject] = {
12+
client.post(Request(url, classOf[JsObject]), Map.empty)
1313
}
1414

1515
}

0 commit comments

Comments
 (0)