How to install pre-receive hooks in GitLab

The code review is a conversational technique to ensure that 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 at commit time.

GitLab server pre-receive hooks in GitLab CE (Community Edition) and GitLab EE (Enterprise Edition) can verify the changes sent to the server. They can guarantee that only those changes arrive to the Git repository that comply with your GitLab Push Rules or other team rules.

The recent improvements in Better Commit Policy for Jira make commit verification in GitLab better and installing GitLab hooks easier.

GitLab - Jira integration for commit verification

Better Commit Policy is a Jira app, popular among developers who also use different other GitLab hooks. The app allows you to set up your custom rules to verify committed changes against. Commit rules can also verify Jira-specific aspects (links to Jira issues, user identity, etc.) on top of formal commit or commit message characteristics.

GitLab and Jira are often used together on a company or team level. Teams use Jira for issue tracking and project management, and GitLab as code repository, version control and CI/CD tool.

Install Better Commit Policy for Jira and see how it can simplify commit verification with GitLab. You will discover that the recently shipped 4.3.0 version brings important new features for the GitLab-Jira integration.

With pre-receive hooks, you can verify a lot more aspects of commits than with GitLab’s Push Rules. Jira specific information or other custom requirement can be included in the verification's scope.

Pre-receive hooks take your commit verification efforts beyond the GitLab Push Rules and allow you to have more control over what changes are accepted to your GitLab repository. The GitLab - Jira integration by Better Commit Policy for Jira is free to try!

Non-compliant commits get rejected based on general attributes of the commit and Jira specific information

How to install GitLab pre-receive 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.

  1. Locate your Git repository in the server filesystem based on the storage behavior of your GitLab version. We will call this your_repository_dir in the next steps.
  2. Extract the hook script package to a directory named custom_hooks inside your Git repository. If custom_hooks does not exist yet, create it.
  3. Change the owner of the custom_hooks directory and all the files in it to git:git.
  4. Open jcp_git_common.py in a plain text editor, and modify the method called started_manually() at the end of the file to this.
  5. To show rejection messages properly in the GitLab web-based file editor, there is one more change to make. Open jcp_common.py in a plain text editor and modify the method called print_stderr(*s) to this.

Jira issue key suggestions for commit messages

Jira issue keys are often misspelled in commit messages. The good thing is that mistakes are caught at commit time and can’t reach the blessed repository or the reference codebase.

Better Commit Policy for Jira makes correcting commit message mistakes easier with the "Did you mean?" feature.

It's an intelligent method of suggesting relevant Jira 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. They get ten suggested issues from the app to 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 today!

Give Better Commit Policy a closer look!

 

Be the first to hear about the Midori news, Jira, Confluence, Bitbucket guides, and productivity tips that accelerate your team.

Subscribe now