Skip to content

Commit 53f97f4

Browse files
committed
Add comment endpoints and optimize imports
1 parent 94dd964 commit 53f97f4

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/main/scala/com/codacy/client/bitbucket/v2/service/BuildStatusServices.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package com.codacy.client.bitbucket.v2.service
22

33
import com.codacy.client.bitbucket.v2.BuildStatus
44
import com.codacy.client.client.{BitbucketClient, Request, RequestResponse}
5-
import play.api.libs.json.Json
5+
import play.api.libs.json._
6+
import play.api.libs.ws.DefaultBodyWritables._
67

78
class BuildStatusServices(client: BitbucketClient) {
89

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.codacy.client.bitbucket.v2.service
22

3-
import com.codacy.client.bitbucket.v2
4-
import com.codacy.client.bitbucket.v2.PullRequest
3+
import com.codacy.client.bitbucket.v2.{PullRequest, PullRequestComment, SimpleCommit, PullRequestReviewers}
54
import com.codacy.client.client.{BitbucketClient, Request, RequestResponse}
65
import play.api.libs.json._
76

@@ -23,10 +22,10 @@ class PullRequestServices(client: BitbucketClient) {
2322
* Gets the list of commits of a pull request
2423
*
2524
*/
26-
def getPullRequestCommits(owner: String, repository: String, prId: Long): RequestResponse[Seq[v2.SimpleCommit]] = {
25+
def getPullRequestCommits(owner: String, repository: String, prId: Long): RequestResponse[Seq[SimpleCommit]] = {
2726
val url = s"https://bitbucket.org/api/2.0/repositories/$owner/$repository/pullrequests/$prId/commits?pagelen=100"
2827

29-
client.executePaginated(Request(url, classOf[Seq[v2.SimpleCommit]]))
28+
client.executePaginated(Request(url, classOf[Seq[SimpleCommit]]))
3029
}
3130

3231
def create(owner: String, repository: String, title: String, sourceBranch: String, destinationBranch: String): RequestResponse[JsObject] = {
@@ -69,10 +68,38 @@ class PullRequestServices(client: BitbucketClient) {
6968
client.postJson(Request(url, classOf[JsObject]), JsNull)
7069
}
7170

72-
def getPullRequestsReviewers(owner: String, repository: String, prId: Long): RequestResponse[v2.PullRequestReviewers] = {
71+
def createComment(author: String, repo: String, prId: Int, body: String,
72+
file: Option[String], line: Option[Int]): RequestResponse[PullRequestComment] = {
73+
val url = s"https://bitbucket.org/api/2.0/repositories/$author/$repo/pullrequests/$prId/comments"
74+
75+
val params = for {
76+
filename <- file
77+
lineTo <- line
78+
} yield {
79+
"inline" -> Json.obj("path" -> JsString(filename), "to" -> JsNumber(lineTo))
80+
}
81+
82+
val values = JsObject(params.toSeq :+ "content" -> Json.obj("raw" -> JsString(body)))//, "anchor" -> JsString(CommitHelper.anchor(commitUUID))))
83+
client.postJson(Request(url, classOf[PullRequestComment]), values)
84+
}
85+
86+
def deleteComment(author: String, repo: String, pullRequestId: Int, commentId: Long): RequestResponse[Boolean] = {
87+
val url = s"https://bitbucket.org/api/2.0/repositories/$author/$repo/pullrequests/$pullRequestId/comments/$commentId"
88+
89+
client.delete(url)
90+
}
91+
92+
def listComments(author: String, repo: String, pullRequestId: Int): RequestResponse[Seq[PullRequestComment]] = {
93+
val url = s"https://bitbucket.org/api/2.0/repositories/$author/$repo/pullrequests/$pullRequestId/comments"
94+
95+
client.executePaginated(Request(url, classOf[Seq[PullRequestComment]]))
96+
.map(_.filterNot(_.deleted))
97+
}
98+
99+
def getPullRequestsReviewers(owner: String, repository: String, prId: Long): RequestResponse[PullRequestReviewers] = {
73100
val url = s"https://bitbucket.org/api/2.0/repositories/$owner/$repository/pullrequests/$prId"
74101

75-
client.execute(Request(url, classOf[v2.PullRequestReviewers]))
102+
client.execute(Request(url, classOf[PullRequestReviewers]))
76103
}
77104

78105
}

0 commit comments

Comments
 (0)