31

How to install pre-receive hooks in GitLab | Midori

 4 years ago
source link: https://www.midori-global.com/blog/2019/10/29/how-to-install-pre-receive-hooks-in-gitlab
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to install pre-receive hooks in GitLab

29 Oct 2019 Levente Szabo
in Better Commit Policy, Jira, Tutorial, Featured
• 4 min read

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.

  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.

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!

Give Better Commit Policy a closer look!

Question or feedback on this post? Let @MidoriGlobal know on Twitter (or send us an email).


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK