Example scripts
To homepage
Bitbucket

Prevent Push If Commit Message Does Not Match Pattern
App in script

ScriptRunner For Bitbucket
by Adaptavist
Compatibility

Bitbucket (6.3 - 7.12)

ScriptRunner For Bitbucket (6.11.0)
Language |
groovy
import com.atlassian.bitbucket.hook.repository.CommitAddedDetails
import com.atlassian.bitbucket.hook.repository.PreRepositoryHookCommitCallback
import com.atlassian.bitbucket.hook.repository.RepositoryHookCommitFilter
import com.atlassian.bitbucket.hook.repository.RepositoryHookResult
import javax.annotation.Nonnull
def requiredCommitMessagePattern = ~/BUGFIX:.*/
commitCallback = new PreRepositoryHookCommitCallback() {
@Override
boolean onCommitAdded(@Nonnull CommitAddedDetails commitDetails) {
def commit = commitDetails.commit
if (!(commit.message ==~ requiredCommitMessagePattern)) {
def msg = "Commit message: (${commit.message}) does not match required pattern: $requiredCommitMessagePattern"
resultBuilder.veto(msg, msg)
return false
}
true
}
@Override
RepositoryHookResult getResult() {
resultBuilder.build()
}
}
commitFilters << RepositoryHookCommitFilter.ADDED_TO_ANY_REF
RepositoryHookResult.accepted()
Having an issue with this script?
Report it here