Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Ability to merge based on the comments on a Pull request

Mani Reddy October 23, 2019

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



1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Craig Nodwell
Community Champion
October 7, 2022

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

TAGS
AUG Leaders

Atlassian Community Events