Hi Everyone!! I am trying to write a merge check, which will allow users to merge only when a specific comment is added to the pull request. I am unable to print any relevant info in the bitbucket logs. Can someone please help in dubbing the below script.
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.comment.CommentService
import com.atlassian.bitbucket.comment.CommentSearchRequest
import com.atlassian.bitbucket.util.PageRequestImpl
import com.atlassian.bitbucket.pull.PullRequestService
import com.atlassian.bitbucket.pull.PullRequestAction
import com.atlassian.bitbucket.pull.PullRequestActivity
import com.atlassian.bitbucket.pull.PullRequestCommentActivity
import com.atlassian.bitbucket.comment.Comment
/* def commentService = ComponentLocator.getComponent(CommentService)
def threads = commentService.searchThreads(
new CommentSearchRequest.Builder(mergeRequest.pullRequest).build(),
new PageRequestImpl(0, PageRequestImpl.MAX_PAGE_LIMIT)
).values */
/*def status = false
for(thread in threads){
def comment = thread.getRootComment().getText()
if (comment.contains('Alpha'))
{ status = true break }
}
return status*/
def pullId = mergeRequest.pullRequest.getId()
def repository = mergeRequest.pullRequest.getToRef().getRepository();
def repoId = repository.getId()
def pullRequestService = ComponentLocator.getComponent(PullRequestService)
def pageReq = new PageRequestImpl(0, 1000);
def activities = pullRequestService.getActivities(repoId, pullId, pageReq);
def status = false
for(activity in activities.getValues().iterator()){
PullRequestActivity pa = (PullRequestActivity) activity;
PullRequestAction prAction = (PullRequestAction)pa.getAction();
if (prAction == PullRequestAction.COMMENTED){
def commentActivity = (PullRequestCommentActivity) pa;
def comment = (Comment)commentActivity.getComment();
def commentMessage = comment.getText();
if (commentMessage.contains('This is a test'))
{ status = true; break; }
}
}
return status
I don't see anywhere in your script where you are telling it to log anything. Is this what you are asking for? How to log? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.