DevSensei | Code Owners for Bitbucket

Merge Check Section

  • 🔰 fundamental topics for beginners getting started with DevSensei

  • 🔬 advanced topics for once you have your first workflows automated

List of enforced checks that protect against merging unless they all succeed.

Let us know if your use case is not covered.

Merge checks reuse the same expressions as conditions, and can be grouped with a custom title. DevSensei also offers alias merge checks for common use cases.

Custom Check

Example

YAML
merge-checks:
  - title: block when PR title requests
    check:
      - title ~!= '[block]*'

Properties

Property

Definition

check (required)

a list of conditions that must all be met for the check to pass. The list of conditions are implicitly combined with and, so an empty list will always pass the check.

title (required)

a (string) label to describe the custom check. It will also display in the UI, and helps to identify in error messages which check is blocking merging of a PR.

Alias: Minimum Approvals

Equivalent to a custom merge check with the single condition count(approved-by) >= n for positive number n.

Example

YAML
merge-checks:
  - minimum-approvals: 1

Properties

Property

Definition

minimum-approvals (required)

a positive (int) integer value, representing the minimum number of approvers on the PR for the check to succeed.

Alias: Minimum Successful Builds

Equivalent to a custom merge check with the conditions:

  • count(builds.successful) >= n for a positive number n.

  • count(builds.failed) = 0 disallow failed builds

  • count(builds.in-progress) = 0 wait for all builds to be complete

Example

YAML
merge-checks:
  - minimum-successful-builds: 1

Properties

Property

Definition

minimum-successful-builds (required)

a positive (int) integer value, representing the minimum number successful builds on the PRs latest commit to succeed.

Alias: No Open Tasks

Equivalent to a custom merge check with the single condition count(open-tasks) = 0.

Add this merge check by adding the string no-open-tasks to the workflow merge-checks list.

Example

YAML
merge-checks:
  - no-open-tasks

Properties

This merge check alias has no property.

Code Owners Merge Check

This merge check enforces rules as described in the Code Owners documentation. For existing CODEOWNERS users, copy your merge checks to this section.

Properties

Property

Definition

codeowners-check (required)

a multiline string, where each line is an independent rule, and each line must be simultaneously true. Combine multiple rules on the same line with | (OR) or & (AND). Check the exact rules.

Example

YAML
merge-checks:
- codeowners-check: |
    (Check(@@MyDevs >= 2) | Check(@@JavaExperts >= 1))

Merge Check Use Cases

The merge-checks section gives more control over which pull requests should be merged, for example applying unique checks to specific branch patterns.

Use Case

Example Workflow

Enforce that there are no incomplete tasks

YAML
merge-checks:
  - title: require no incomplete tasks
    check:
    - count(open-tasks) = 0

Enforce that the build passed, and no other build is in progress or failed

YAML
merge-checks:
  - title: require a successful build
    check:
    - count(builds.successful) > 1
    - count(builds.in-progress) = 0
    - count(builds.failed) = 0

Enforce that on PRs to the main branch there are at least 3 approvers

YAML
workflows:
  - name: strict main checks
    conditions:
      - destination = 'main'
    merge-checks:
      - title: 3 approvers on main
        check:
          - count(approved-by) >= 3

Enforce branch naming conventions

YAML
merge-checks:
  - title: Follow branch pattern
    check:
      - or:
          - source ~= 'feature/*'
          - source ~= 'release/*'
          - source ~= 'hotfix/*'
          - source = 'main'

Prevent merge to release branch from a feature branch.

YAML
workflows:
  - name: strict release checks
    conditions:
      - destination ~= 'release/*'
    merge-checks:
      - title: never release from feature
        check:
          - source ~!= 'feature/*'

Restrict PRs on certain branches to be specific author.

YAML
workflows:
  - name: strict release author checks
    conditions:
      - destination ~= 'release/*'
    merge-checks:
      - title: enforce PR author
        check:
          - author = 'release-admin'

Prevent merge PR where either title or description are too long.

YAML
workflows:
  - name: Formatting checks
    conditions:
    merge-checks:
      - title: enforce text size
        check:
          - title <= 50
          - description <= 10000

Ensure there are Jira issues references and commit titles follow a guide line

YAML
workflows:
  - name: Commit message checks
    conditions:
    merge-checks:
    - title: Ensure that Jira key issues is referenced
      check:
        - count(jira-keys) > 0
    - title: Ensure your commit title starts with FIX,FEATURE or MISC
      check:
        - forall(commits.titles, $1~=regex('(FIX|FEATURE|MISC).*'))

Prevent merge PR with too many file changes.

YAML
workflows:
  - name: Size checks
    conditions:
    merge-checks:
      - title: enforce max changed files
        check:
          - count(changed-files.added) <= 50

Prevent merge if draft or conflicting.

This matches Bitbucket’s own behavior so is unnecessary, but demonstrates how you could create equivalent checks with conditions.

YAML
merge-checks:
  - title: Not draft or conflicting
    check:
      - not(draft)
      - not(conflicts)
Planned Use Cases

The following ideas rely upon planned or otherwise unimplemented features. Contact support to let us know your use case.

Fine-grained equivalents to built-in Bitbucket merge checks

Supporting the following would allow to create finer grained checks (e.g. by filtering on destination branch pattern):

  • Require no "requested changes" status

Support non-functional requirements

  • Require that a pull request has been open long enough to be seen (time-based condition)

  • Prevent merge to a release branch on a specific day.

More fine-grained attributes

  • check text contents of open-tasks, e.g. if your team uses a marker to indicate some tasks can be ignored.

  • check specific user in approved-by.

Code Owners merge checks

Over time we hope to migrate the merge checks from the add-codeowners action, starting with the codeowners-check option. We could possibly make them more flexible, for example check the intersection of approved-by with the added code owners.