Custom Merge Check

Custom merge checks allow you to cause a pull request merge to be vetoed. The same functionality can also be achieved using a Conditional Merge Check. However, custom merge checks are most useful when you want to dynamically generate the veto message.

Reject merge with message

Custom merge checks should return a RepositoryHookResult object. To block a merge, you should call the static RepositoryHookResult.rejected() method.

Enforcing reviewers in several timezones with dynamic veto message

The intention of this hook is to ensure that the author and reviewers are in at least three time zones, as a mechanism of ensuring people in different offices are aware of code changes.

import com.atlassian.bitbucket.hook.repository.RepositoryHookResult
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.bitbucket.timezone.UserTimeZoneSupplier
 
def final nTimeZonesRequired = 3
 
def participants = mergeRequest.pullRequest.reviewers*.user
participants << mergeRequest.pullRequest.author.user
 
def userTimeZoneSupplier = ComponentLocator.getComponent(UserTimeZoneSupplier)
def timeZones = participants.collect { participant ->
    userTimeZoneSupplier.getTimeZone(participant)
}
  
def actualTimeZones = timeZones.unique().size()
if (actualTimeZones < nTimeZonesRequired) {
    RepositoryHookResult.rejected("Not enough timezones covered",
        "You need reviewers in ${nTimeZonesRequired - actualTimeZones} more timezone(s). " +
            "Currently you have: ${timeZones.join(", ")}.")
}

On this page