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 vote
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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

27,637 views 26 12
Join discussion

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