Common Use Cases

This page contains common use cases for 3 types of the hooks provided by the add-on.

Pre Receive Hook #

Common cases are:

  • to reject a commit based on a set of rules,
  • to get immediate feedback on the git push command.

Validation rules should be enforced by a third-party tool like:

  • test runners (junit, go test, phpunit),
  • linters (phpmd, golint, gometalinter, eslint, findbugs),
  • issue tracker linkers (e.g., to link commits with JIRA Issue),
  • any shell script commit checkers to enforce a commit message style.

The Pre Receive Hook can submit pushed commits to the build server and reply with a URL of a build status page. The user gets immediate feedback on their pushed changes.

Async Post Receive Hook #

This type of hook cannot be used to reject commits or to get feedback to user due to Bitbucket API limitations.

Therefore, this type of hook is only useful in specific scenarios when the action results can be hidden from the user.

For example, the Post Receive hook can be applied to mirror changes to the backup server or to send a notification to Slack messenger.

Merge Check #

This type of hooks is useful for validating changes in Pull Requests.

It can be utilized in the same way as the Pre Receive Hook to validate commits with various linters or run tests to avoid merging changes that do not match code quality requirements.

The Merge Check hook runs when somebody visits a pull request page. If the hook exits with non-zero exit code, the user is unable to merge the pull request and sees a message about discovered errors.