0

We are planning to have some policies that will ensure we don't accept commits that won't adhere to commit message policy. This policy is specific to a repo.

Is it possible to run pre-receive style hooks in Gerrit where we can run these policies before the patch gets created?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108

1 Answers1

2

Yes, Gerrit has its own hook mechanism included via the hooks plugin so it's possible to block the push if some policy is not valid.

Consider also to use the Git::Hooks. We use it and it's really good. Using Git::Hooks you can implement a better strategy to manage these checks:

1) Accept the commit (patchset is created)

2) Execute the policy checks

3) Vote in the review (approving or blocking the change)

  • Can you please point me to some documentation or reading material for hooks plugin, I cant seem to figure out how to use this plugin. Thanks in advance. – Raghavendra Pathi Jul 13 '17 at 12:23
  • Take a look here: https://gerrit.googlesource.com/plugins/hooks/+/refs/heads/master/src/main/resources/Documentation – Marcelo Ávila de Oliveira Jul 18 '17 at 00:02
  • On my Gerrit server I am planning to download this hooks plugin to this folder location - /var/gerrit/review_site/plugins/ I am not able to find the .jar file to place in this location. Could you please let me know if this needs to be built or can be downloaded readily from somewhere? Gerrit Hooks Link - https://gerrit-review.googlesource.com/admin/projects/plugins/hooks – Raghavendra Pathi Aug 10 '17 at 18:20
  • The hooks plugin is a core plugin, it's preinstalled in the Gerrit release (.war file). When you execute "java -jar gerrit.war init -d /var/gerrit/review_site" it will ask if you want to install de hooks plugin. More info here: https://gerrit-review.googlesource.com/Documentation/config-plugins.html – Marcelo Ávila de Oliveira Aug 10 '17 at 19:09
  • Following is my plan to do pre-recieve style hook, please let me know if that would work, – Raghavendra Pathi Sep 07 '17 at 12:05
  • Ignore my previous comment @marcelo-Ávila-de-oliveira , I am a newbee to PERL and i want to use Git:Hooks, Can you tell me where can i specify these configurations "githooks.gerrit.url URL" "githooks.gerrit.username USERNAME" "githooks.gerrit.password PASSWORD", should they go into gerrit config? – Raghavendra Pathi Sep 07 '17 at 12:47
  • I just create a question/answer detailed about this, take a look and see if it helps: https://stackoverflow.com/questions/46100437/how-to-install-config-githooks/46100438 – Marcelo Ávila de Oliveira Sep 07 '17 at 15:48