1
1
package com .codacy .client .bitbucket .v2 .service
2
2
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 }
5
4
import com .codacy .client .client .{BitbucketClient , Request , RequestResponse }
6
5
import play .api .libs .json ._
7
6
@@ -23,10 +22,10 @@ class PullRequestServices(client: BitbucketClient) {
23
22
* Gets the list of commits of a pull request
24
23
*
25
24
*/
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 ]] = {
27
26
val url = s " https://bitbucket.org/api/2.0/repositories/ $owner/ $repository/pullrequests/ $prId/commits?pagelen=100 "
28
27
29
- client.executePaginated(Request (url, classOf [Seq [v2. SimpleCommit ]]))
28
+ client.executePaginated(Request (url, classOf [Seq [SimpleCommit ]]))
30
29
}
31
30
32
31
def create (owner : String , repository : String , title : String , sourceBranch : String , destinationBranch : String ): RequestResponse [JsObject ] = {
@@ -69,10 +68,38 @@ class PullRequestServices(client: BitbucketClient) {
69
68
client.postJson(Request (url, classOf [JsObject ]), JsNull )
70
69
}
71
70
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 ] = {
73
100
val url = s " https://bitbucket.org/api/2.0/repositories/ $owner/ $repository/pullrequests/ $prId"
74
101
75
- client.execute(Request (url, classOf [v2. PullRequestReviewers ]))
102
+ client.execute(Request (url, classOf [PullRequestReviewers ]))
76
103
}
77
104
78
105
}
0 commit comments