|
1 | 1 | package com.codacy.client.bitbucket.service
|
2 | 2 |
|
3 | 3 | import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
|
4 |
| -import com.codacy.client.bitbucket.{PullRequest, SimpleCommit} |
5 |
| -import play.api.libs.json.{JsNull, JsObject, Json} |
| 4 | +import com.codacy.client.bitbucket.{PullRequestComment, PullRequest, SimpleCommit} |
| 5 | +import play.api.libs.json._ |
6 | 6 |
|
7 | 7 | class PullRequestServices(client: BitbucketClient) {
|
8 | 8 |
|
@@ -68,4 +68,21 @@ class PullRequestServices(client: BitbucketClient) {
|
68 | 68 | client.post(Request(url, classOf[JsObject]), JsNull)
|
69 | 69 | }
|
70 | 70 |
|
| 71 | + def createComment(author: String, repo: String, prId: Int, commitUUID: String, body: String, file: Option[String], line: Option[Int]): RequestResponse[PullRequestComment] = { |
| 72 | + val url = s"https://bitbucket.org/api/1.0/repositories/$author/$repo/pullrequests/$prId/comments" |
| 73 | + |
| 74 | + val params = file.map(filename => "filename" -> JsString(filename)) ++ |
| 75 | + line.map(lineTo => "line_to" -> JsNumber(lineTo)) |
| 76 | + |
| 77 | + val values = JsObject(params.toSeq :+ "content" -> JsString(body) :+ "anchor" -> JsString(commitUUID.take(12))) |
| 78 | + |
| 79 | + client.post(Request(url, classOf[PullRequestComment]), values) |
| 80 | + } |
| 81 | + |
| 82 | + def deleteComment(author: String, repo: String, commitUUID: String, pullRequestId: Int, commentId: Long): Unit = { |
| 83 | + val url = s"https://bitbucket.org/api/1.0/repositories/$author/$repo/pullrequests/$pullRequestId/comments/$commentId" |
| 84 | + |
| 85 | + client.delete(url) |
| 86 | + } |
| 87 | + |
71 | 88 | }
|
0 commit comments