如何安装/配置Git :: Hooks与Gerrit一起使用

时间:2017-09-07 15:42:14

标签: git perl hook gerrit

Git::Hooks是用于实现Git / Gerrit挂钩的Perl框架。安装和配置它以与Gerrit一起使用的过程是什么?

1 个答案:

答案 0 :(得分:5)

安装

1)安装依赖项:

Ubuntu的:

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

红帽:

sudo yum install gcc make libcrypt-ssleay-perl

2)安装Git :: Hooks:

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

配置

1)在GERRIT-SITE / hooks目录中创建Gerrit钩子补丁集创建和草稿发布(带执行权限),内容如下:

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

2)配置Gerrit存储库:

任何存储库都可以单独设置,但更容易在GERRIT-SITE / git / all-projects.git / config文件中配置所有项目项目,如下例所示(某些配置可根据需要添加/删除) :

...
[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
...

然后通过在GERRIT-SITE / git / REPO.git / config

中添加folling来在所有存储库中包含所有项目配置
[include]
    path = GERRIT-SITE/git/all-projects.git/config

如果需要,可以在某个特定的存储库中更改/添加任何配置,更改GERRIT-SITE / git / repo.git / config,如下例所示(某些配置可以根据需要添加/删除):

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

要了解有关Git :: Hooks配置选项的更多信息,请参阅here

3)重启Gerrit服务器

GERRIT-SITE/bin/gerrit.sh restart