Skip to content

Bitbucket Cloud status check that ensures your pull requests follow the Conventional Commits spec

License

Notifications You must be signed in to change notification settings

maxbrunet/bitbucket-semantic-pull-requests

Repository files navigation

Bitbucket Semantic Pull Requests

release build go report

Bitbucket Cloud status check that ensures your pull requests follow the Conventional Commits spec.

Heavily inspired by zeke/semantic-pull-requests, if not a rewrite in Go for Bitbucket Cloud.

How it works

By default, only the PR title OR at least one commit message needs to have semantic prefix. If you wish to change this behavior, see configuration section below.

Scenario Status Status Check Message
PR title is semantic 💚 ready to be squashed
any commit is semantic 💚 ready to be merged or fast-forwarded
nothing is semantic 💛 add a semantic commit or PR title

Please see zeke/semantic-pull-requests for the full rational.

Installation

  1. Create a Bitbucket Cloud account for the bot and add it to your team (Recommended)

  2. Create an App password with pullrequest scope ("Pull request: Read")

  3. Grant read access on your repositories to the bot account

  4. Export the bot's Bitbucket credentials via environment variables (or use --help flag for more options):

    • BITBUCKET_USERNAME: Bitbucket username associated with the account used for renovate-approve-bot
    • BITBUCKET_PASSWORD: Bitbucket App password created in step 2
  5. Start the bot:

    • With Docker:

      docker run --rm \
        --env BITBUCKET_USERNAME \
        --env BITBUCKET_PASSWORD \
        --publish 8888:8888 \
        ghcr.io/maxbrunet/bitbucket-semantic-pull-requests:latest
    • With a binary (downloadable from the Releases page):

      ./bitbucket-semantic-pull-requests
  6. Add a webhook to your repository

    • Title: Semantic Pull Requests
    • URL: https://<bot-address>/
    • Status: Active
    • Triggers:
      • pullrequest:created
      • pullrequest:updated

Configuration

It is the same as zeke/semantic-pull-requests.

By default, no configuration is necessary.

If you wish to override some behaviors, you can add a semantic.yml file to your .bitbucket directory with the following optional settings:

# Disable validation, and skip status check creation
enabled: false
# Always validate the PR title, and ignore the commits
titleOnly: true
# Always validate all commits, and ignore the PR title
commitsOnly: true
# Always validate the PR title AND all the commits
titleAndCommits: true
# Require at least one commit to be valid
# this is only relevant when using commitsOnly: true or titleAndCommits: true,
# which validate all commits by default
anyCommit: true
# You can define a list of valid scopes
scopes:
  - scope1
  - scope2
  ...
# By default conventional types as definited by go-conventionalcommits are used.
# See "conventional": https://github.com/leodido/go-conventionalcommits#types
# You can override the valid types
types:
  - feat
  - fix
  - docs
  - style
  - refactor
  - perf
  - test
  - build
  - ci
  - chore
  - revert
# Allow use of Merge commits (e.g. "Merge branch 'master' into feature/ride-unicorns")
allowMergeCommits: true
# Allow use of Revert commits (e.g. "Revert "feat: ride unicorns"")
allowRevertCommits: true

Note about conventional-changelog

The mergePattern parser option can be used to extract the Pull Request title from Bitbucket's merge message:

parserOpts:
  mergePattern: '^Merged in (\S+) \(pull request #(\d+)\)$'
  mergeCorrespondence: ['branch', 'prId']

License

Apache 2.0