Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Ability to merge based on the comments on a Pull request

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Oct 07, 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