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}}
@CTO Build, Run, and Architecture,
Your request is pretty light on details, which makes it difficult to nail down what's going on.
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.