A code review is an effective conversational technique of making sure only lean and quality software is being released. It's valuable time that shouldn't be wasted on trying to catch non-compliant commits that could've been rejected on the developer’s computer.
Git pre-receive hooks in GitLab CE (Community Edition) and GitLab EE (Enterprise Edition) are one way to make sure only those changes arrive in your product's Git repository that complies with your company’s or team’s agreed-upon rules.
The recent improvements in Better Commit Policy for Jira make this process easier.
GitLab-Jira integration for commit verification
Better Commit Policy is a popular Jira app that allows you to set up your custom rules to verify committed changes against. Since it runs in Jira, your rules can also verify Jira-specific (links to Jira issues, user identity, etc.) aspects on top of formal commit or commit message characteristics.
The recently shipped 4.3.0 version brings important new features that are reactions to popular customer requests for a Gitlab-Jira integration. GitLab and Jira are often used together on a company or team level: Jira for issue tracking and project management, and GitLab as code repository, version control and CI/CD tool.
Now you can have more control over what changes are accepted to your GitLab repository by using commit rules by Better Commit Policy for Jira.
With pre-receive hooks, you can verify a lot more aspects of commits than with GitLab’s "Push Rules" feature. You can also take Jira specific information into account.
Non-compliant commits get rejected based on general attributes of the commit and Jira specific information
How to install GitLab hooks
To create the GitLab pre-receive hook script for Better Commit Policy, launch the Hook Script Wizard, select "Git" as VCS, and follow the steps.
- Locate your Git repository in the server filesystem based on the storage behavior of your GitLab version.
We will call this
your_repository_dirin the next steps.
- Extract the hook script package to a directory named custom_hooks inside your Git repository. If custom_hooks does not exist yet, create it.
- Change the owner of the custom_hooks directory and all the files in it to
jcp_git_common.pyin a plain text editor, and modify the method called
started_manually()at the end of the file to this.
- To show rejection messages properly in the GitLab web-based file editor, there is one more change to make.
jcp_common.pyin a plain text editor and modify the method called
Issue key suggestions for commit messages
Even when the developer team is used to the commit rules and understand why those are helpful for the whole product development process, mistakes happen. The good thing is that mistakes are caught at commit time and those can’t reach the blessed repository or the reference codebase.
Better Commit Policy 4.3.0 makes correcting mistakes easier with the "Did you mean?" feature.
It's an intelligent method of suggesting relevant issue keys if the commit was rejected because of mentioning the wrong issue. The developer doesn’t have to switch context and go back to Jira to check what's the right issue but gets an educated guess of ten issues from the app she can choose from:
Better Commit Policy now can suggest relevant Jira issue keys to include in the Git commit message
Make your code change history audit-proof with custom commit rules and get started with Better Commit Policy 4.3.0 today!