Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

perl - How to install/config Git::Hooks to use with Gerrit

The Git::Hooks is a Perl framework for implementing Git/Gerrit hooks. What is the procedure to install and config it to use with Gerrit?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Installation

1) Install dependencies:

Ubuntu:

sudo apt-get install gcc make libcrypt-ssleay-perl

Red Hat:

sudo yum install gcc make libcrypt-ssleay-perl

2) Install Git::Hooks:

sudo cpanm Git::Hooks
sudo cpanm Gerrit::REST
sudo cpanm JIRA::REST

Configuration

0) Be sure you have the hooks plugin installed in Gerrit.

1) Create the Gerrit hooks patchset-created and draft-published (with execution permission) in GERRIT-SITE/hooks directory, with the following content:

#!/usr/bin/env perl
use Git::Hooks;
$ENV{HOME}="/home/GERRIT-USER";
run_hook($0, @ARGV);

2) Configure the Gerrit repositories:

Any repository can be set individually but it's easier to configure all-projects project in GERRIT-SITE/git/all-projects.git/config file like in the following example (some configurations itens can be added/removed as needed):

...
[githooks]
    plugin = CheckJira
    plugin = CheckLog
    plugin = CheckFile
    nocarp = 1
[githooks "gerrit"]
    url = https://GERRIT-SERVER
    username = GERRIT-USER
    password = GERRIT-PASS
    votes-to-approve = Verification+1
    votes-to-reject = Verification-1
    comment-ok = OK
    notify = OWNER
[githooks "checkjira"]
    jiraurl = https://JIRA-SERVER
    jirauser = JIRA-USER
    jirapass = JIRA-PASS
    matchlog = (?s)^(?:Revert\s")?\s*\[([^]]+)\]
    status = In Progress
    status = Analysing
    status = Treating
    status = Evaluating
    status = Waiting Information
[githooks "checklog"]
    title-required = 1
    title-max-width = 60
    body-max-width = 80
[githooks "checkfile"]
    sizelimit = 5242880
    name = *.p[lm] /usr/local/bin/perlcritic --stern --verbose 5
    name = *.pp /usr/local/bin/puppet-lint --error-level error --with-context --with-filename
    name = *.sh LANG=en_US.UTF-8 /usr/bin/shellcheck --exclude=SC2046,SC2053,SC2086
    name = *.erb /usr/bin/erb -P -x -T - {} | ruby -c
...

And then include the all-projects config in all repositories by adding the folling at GERRIT-SITE/git/REPO.git/config

[include]
    path = GERRIT-SITE/git/all-projects.git/config

If needed any configuration can be changed/added at some specific repository changing the GERRIT-SITE/git/repo.git/config like in the following example (some configurations itens can be added/removed as needed):

...
[githooks]
    plugin = CheckWhitespace
[githooks "checkjira"]
    require = 0
    unresolved = 0
...

To learn more about Git::Hooks configuration options see here.

3) Restart the Gerrit server

GERRIT-SITE/bin/gerrit.sh restart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...