Workflow customizations with Stash’s repository hooks

Every team has its own workflow. Atlassian Stash is highly customizable by allowing you to adapt it to your specific workflow requirements with its repository hooks. Repository hooks are not a concept invented by Stash, but instead build upon the hooks of Git. Every time Git executes an action, we have the chance to run an operation before and after it. We can hook into actions like commits, pushes, applying patches, merges, etc. Stash wraps the Git hook functionality, and allows us to install them on a repository basis.

We at Mibex Software have already implemented and shipped various hooks for Stash. Our add-on Pull Request, please! enforces a pull request for every push to a list of configurable branches. This allows you to prevent direct pushes to branches like “master” or “develop”, but instead to enforce pull requests which will be reviewed, and hence get all the advantages of using pull requests.

Another Stash hook we have implemented is called Plan Branch Terminator for Stash. This hook shows that it is even possible to connect different Atlassian products with each other based on actions occurring in a Git repository. The intent of this hook is to immediately delete a plan branch in Atlassian Bamboo as soon as the corresponding Git branch is deleted in Stash. This is useful if you make heavy use of feature branches in your workflow and have the automatic plan branch creation in Bamboo enabled to build your feature branches automatically. In this case, you can get rid of the obsolete builds and their artifacts whenever you delete a feature branch, e.g. through merging it into another branch.

Other hooks we have implemented are not shipped as their own add-on, but instead are part of whole product. Our two products Code Review Assistant and Sonar for Stash contain a type of repository hook that checks certain quality requirements (e.g., no more than 5% increase in duplicate code lines, or at least 95% line coverage) for the code in a pull request. If these minimum requirements are not reached, the pull request cannot be merged.

As you can see, Stash hooks are very powerful.