CommentService.addComment not appearing

I am trying to use the CommentService to add a comment through Java code. 

 

This is what I have:

AddCommentRequest addCommentRequest = new AddCommentRequest.Builder(request.getPullRequest(), "a comment").build();

Comment comment = commentService.addComment(addCommentRequest);

 

I see in the logs the code is executed, but it is being executed as  "GET" instead of a "POST" and it's not showing up in the UI. Is there something else I need to do to add comments in the activities of a pull request?

 

"GET /rest/api/latest/projects/..../repos/testbitbucketplugin/pull-requests/1/merge HTTP/1.1" c.a.s.i.n.DefaultNotificationManager Managing notification: PullRequestActivityNotification{user=InternalNormalUser{id=1, username=admin}, timestamp=Wed Jan 17 11:41:27 EST 2018, pullRequest=testbitbucketplugin:3, activity=InternalPullRequestCommentActivity{id=133, user=InternalNormalUser{id=1, username=admin}, action=COMMENTED, pullRequest.id=3, commentAction=ADDED, comment=InternalComment{id=23, author=InternalNormalUser{id=1, username=admin}, text=a comment}}

 

1 answer

0 votes
Bryan Turner Atlassian Team Jan 24, 2018

@CTO Build, Run, and Architecture,

Your request is pretty light on details, which makes it difficult to nail down what's going on.

  • What version of Bitbucket Server is affected?
  • Where is the (tiny) code snippet you provided being run? Have you implemented a RepositoryMergeCheck, or perhaps a PreRepositoryHook accepting a PullRequestMergeHookRequest? Just showing how you're adding the comment doesn't help much without knowing where you're adding it

That said, my bet would be you're running into BSERV-10565. I've made a fix for it, which will be included in forthcoming point releases of Bitbucket Server 5.6 and 5.7, as well as 5.8.0, but I can't offer any timeline for those releases.

In the interim, the solution is to import SAL's TransactionTemplate (com.atlassian.sal.api.transaction.TransactionTemplate; you can use whatever mechanism you're using to import the CommentService) and wrap your code in a TransactionCallback. Something like this:

Comment comment = transactionTemplate.execute(() -> {
AddCommentRequest addCommentRequest = new AddCommentRequest.Builder(request.getPullRequest(), "a comment").build();
return commentService.addComment(addCommentRequest);
});

That will promote the read-only transaction you're in to a read/write transaction so that your new comment will actually be committed to the database instead of rolled back. When execute completes, the comment will be committed to the database.

Hope this helps!
Bryan Turner
Atlassian Bitbucket

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

631 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot