如何安装/配置Git ::与Gerrit配合使用

Mar*_*ira 2 git perl hook gerrit

混帐::挂钩是实现的Git /格里特挂钩一个Perl框架。安装和配置与Gerrit一起使用的过程是什么?

Mar*_*ira 5

安装

1)安装依赖项:

Ubuntu:

sudo apt-get install gcc make libcrypt-ssleay-perl
Run Code Online (Sandbox Code Playgroud)

红帽:

sudo yum install gcc make libcrypt-ssleay-perl
Run Code Online (Sandbox Code Playgroud)

2)安装Git :: Hooks:

sudo cpanm Git::Hooks
sudo cpanm Gerrit::REST
sudo cpanm JIRA::REST
Run Code Online (Sandbox Code Playgroud)

组态

0)确保已在Gerrit中安装了hooks插件

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

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

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
...
Run Code Online (Sandbox Code Playgroud)

然后通过在GERRIT-SITE / git / REPO.git / config中添加以下代码,将all-projects配置包括在所有存储库中

[include]
    path = GERRIT-SITE/git/all-projects.git/config
Run Code Online (Sandbox Code Playgroud)

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

...
[githooks]
    plugin = CheckWhitespace
[githooks "checkjira"]
    require = 0
    unresolved = 0
...
Run Code Online (Sandbox Code Playgroud)

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

3)重新启动Gerrit服务器

GERRIT-SITE/bin/gerrit.sh restart
Run Code Online (Sandbox Code Playgroud)