Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

CommentService.addComment not appearing

CTO Build, Run, and Architecture January 17, 2018

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
Atlassian Team members are employees working across the company in a wide variety of roles.
January 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
TAGS
AUG Leaders

Atlassian Community Events