Skip to content

Commit dfad848

Browse files
committed
Add CommitHelper for Portal usage
1 parent 501be76 commit dfad848

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.codacy.client.bitbucket.service
22

33
import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
4+
import com.codacy.client.bitbucket.util.CommitHelper
45
import com.codacy.client.bitbucket.{CommitComment, PullRequestComment}
56
import play.api.libs.json.{JsNumber, JsObject, JsString}
67

78
class CommitServices(client: BitbucketClient) {
89

910
def createComment(author: String, repo: String, commit: String, body: String, file: Option[String] = None, line: Option[Int] = None): RequestResponse[CommitComment] = {
10-
val url = s"https://bitbucket.org/!api/1.0/repositories/$author/$repo/changesets/${commit.take(12)}/comments"
11+
val url = s"https://bitbucket.org/!api/1.0/repositories/$author/$repo/changesets/${CommitHelper.anchor(commit)}/comments"
1112

1213
val params = file.map(filename => "filename" -> JsString(filename)) ++
1314
line.map(lineTo => "line_to" -> JsNumber(lineTo))
@@ -18,7 +19,7 @@ class CommitServices(client: BitbucketClient) {
1819
}
1920

2021
def deleteComment(author: String, repo: String, commit: String, commentId: Long): Unit = {
21-
val url = s"https://bitbucket.org/!api/1.0/repositories/$author/$repo/changesets/${commit.take(12)}/comments/$commentId"
22+
val url = s"https://bitbucket.org/!api/1.0/repositories/$author/$repo/changesets/${CommitHelper.anchor(commit)}/comments/$commentId"
2223

2324
client.delete(url)
2425
}

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

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

33
import com.codacy.client.bitbucket.client.{BitbucketClient, Request, RequestResponse}
4+
import com.codacy.client.bitbucket.util.CommitHelper
45
import com.codacy.client.bitbucket.{PullRequest, PullRequestComment, SimpleCommit, SimplePullRequestComment}
56
import play.api.libs.json._
67

@@ -83,7 +84,7 @@ class PullRequestServices(client: BitbucketClient) {
8384
val params = file.map(filename => "filename" -> JsString(filename)) ++
8485
line.map(lineTo => "line_to" -> JsNumber(lineTo))
8586

86-
val values = JsObject(params.toSeq :+ "content" -> JsString(body) :+ "anchor" -> JsString(commitUUID.take(12)))
87+
val values = JsObject(params.toSeq :+ "content" -> JsString(body) :+ "anchor" -> JsString(CommitHelper.anchor(commitUUID)))
8788
postNewComment(author, repo, prId, values = values)
8889
}
8990

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codacy.client.bitbucket.util
2+
3+
object CommitHelper {
4+
def anchor(commitUUID: String): String = {
5+
commitUUID.take(12)
6+
}
7+
}

0 commit comments

Comments
 (0)