In this page

What is this?

This page describes the solution for common problems and efficient techniques to implement powerful commit policies with Bitbucket.

Commit message recipes

Minimum length

Use the commit.message.pattern parameter with this regex to require at least 10 character long commit messages (excluding whitespace):

(?:\S|\S\s*){10,}

Work item key in the beginning of the commit message

Use the commit.message.work-item.jql parameter with this regex, so that users need to enter a work item key from the FOO or BAR projects in the commit message. Use this with a JQL condition within the same rule, to restrict the work item keys allowed:

(?s)(?:FOO|BAR)-\d+.*

The leading (?s) allows multi-line commit messages.

Enforcing the 50/72 rule (Linux Kernel style formatting for commit messages)

To adopt this best practice promoted by the Linux Kernel team, check out our blog post.

Pull request title recipes

Minimum length

Use the pull-request.title.pattern parameter with this regex to require at least 10 character long pull request titles (excluding whitespace):

(?:\S|\S\s*){10,}

Work item key in the beginning of the pull request title

Use the pull-request.title.work-item.jql parameter with this regex, so that users need to enter a work item key from the FOO or BAR projects in the pull request title. Use this with a JQL condition within the same rule, to restrict the work item keys allowed:

(?:FOO|BAR)-\d+.*

Pull request description recipes

Minimum length

Use the pull-request.description.pattern parameter with this regex to require at least 10 character long pull request descriptions (excluding whitespace):

(?:\S|\S\s*){10,}

Work item key in the beginning of the pull request description

Use the pull-request.description.work-item.jql parameter with this regex, so that users need to enter a work item key from the FOO or BAR projects in the pull request description. Use this with a JQL condition within the same rule, to restrict the work item keys allowed:

(?:FOO|BAR)-\d+.*

Pull request source branch name recipes

Minimum length

Restrict source branch name prefixes

Work item key in the source branch name

Pull request destination branch name recipes

Minimum length

Restrict destination branch name prefixes

Work item key in the source branch name

JQL condition recipes

Restrict commits to work items in a specific project

Use the commit.message.work-item.jql parameter with this query (JXLS is the key of the project):

project = JXLS

Tip:

Restrict commits to work items assigned to the committer

Use the commit.message.work-item.jql parameter with this query (JXLS is the key of the project):

project = JXLS and assignee = "$commit.author"

Restrict commits to work items assigned to the committer or generally by a reviewer

This is a smarter version of the previous recipe. The problem with original version is that if the changes are reviewed by another developer (supervisor), then he can't commit his additional changes against the original work item, because that is assigned to the developer making the original changes. To solve this, we allow project leads to commit against any work item in their projects, in addition to the original rule! This is dead simple and works wonderfully in practice.

Use the commit.message.work-item.jql parameter with this query (JXLS is the key of the project):

project = JXLS and (assignee = "$commit.author" or project in projectsLeadByUser("$commit.author"))

Restrict commits to stories in the current sprint

Use the commit.message.work-item.jql parameter with this query (JXLS is the key of the project):

project = JXLS and type = Story and sprint in openSprints()

Tip:

Restrict commits to work items scheduled for the current version

Use the commit.message.work-item.jql" parameter with this query (JXLS is the key of the project):

project = JXLS and fixVersion in (1.0.0, 1.0.1)

Tip:

Restrict commits to a list of unresolved work items

Use the commit.message.work-item.jql parameter with this query (JXLS is the key of the project):

key in ("JXLS-1", "JXLS-2", "JXLS-3") and resolution is empty

Tip:

Committing against subtasks of unresolved work items, linked work items, versions matching a pattern, etc.

Although the default JQL function set is great, the ScriptRunner and the JQL Tricks app provide various additional JQL functions! Make sure to check those out if you have more sophisticated requirements.

Skip checks

Skip checks for a commit

To skip the check of a single commit, simply include some text that matches the pattern defined in the commit.message.skip-pattern parameter.

Skip checks for a pull request

In case you want to skip the check of a pull request, you have multiple options:

Questions?

Ask us any time.