Search for Comments with CommentsService


I’m trying to find / list the comments on a pull request. However, I’m always get a result of zero.
I’m testing it on BB 7.8.0 at the moment.

          val existingComments =
            new CommentSearchRequest.Builder(pr.pullRequest)
            new PageRequestImpl(0, 10)
          println(s"==========> ${existingComments.getSize}")

I’m running the query as a service user. I only need to find the comments made by that same service user.

What am I missing?

1 Like

Are you referring to com.atlassian.bitbucket.comment.CommentService in the Bitbucket API?

In which authentication context is the API call made? Is user in this auth context permitted to read the repo? Bitbucket API has a way of swallowing permission exceptions and you would not see them unless you turn on debug level logging for com.atlassian.bitbucket.internal IIRC.

You can wrap your code into an escalated security context with REPO_READ permissions if the current auth context is not sufficient - Make sure the bugcrowd don’t catch you out on this :smile_cat: if you’re returning data via a REST API call…

Yes, I’m using the com.atlassian.bitbucket.comment.CommentService service.

The operation is done in the background. It is using a service user, and has security context of repo read:

      .impersonating(user, "using service user for background operation")
      .call(new UncheckedOperation<T>() {
        override def perform(): T = {
              "necessary as service user does not have rights otherwise"
            .call(new UncheckedOperation<T> {
                     // Trying to read the comments in here.

Thanks for the debug / suppressed exception tip. I’ll run in debug logs and check if I find something.

Looks like you need to add a anchorState(CommentThreadDiffAnchorState.ALL) to get any result.

With that anchor state query added, I get the answers back.

        val existingComments =
          new CommentSearchRequest.Builder(pr.pullRequest)
          PageUtils.newRequest(0, 10)

Thank you @RomanStoffel for the update at your own question.