如何安装/配置Git :: Hooks以与Gerrit一起使用 [英] How to install/config Git::Hooks to use with Gerrit

查看:1670
本文介绍了如何安装/配置Git :: Hooks以与Gerrit一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

安装



1)安装依赖:

Ubuntu:

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

Red Hat:

  sudo yum install gcc make libcrypt-ssleay-perl 

2)安装Git :: Hooks:

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



配置


$ b $ 1)在GERRIT-SITE / hooks目录中创建Gerrit hooks patchset-created和draft-published(具有执行权限),其中包含以下内容:

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



<2>配置Gerrit存储库:

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

  ... 
[githooks]
插件= CheckJira
插件= CheckLog
插件= CheckFile
nocarp = 1
[githooksgerrit]
url = https:// GERRIT-SERVER
用户名= GERRIT-USER
密码= GERRIT -PASS
投票批准=验证+ 1
投票拒绝=验证-1
comment-ok =确定
通知=所有者
[githooks checkjira]
jiraurl = https:// JIRA-SERVER
jirauser = JIRA-USER
jirapass = JIRA-PASS
matchlog =(?s)^(?: Revert \\\\\\\)?\\\ * \\ [([^]] +)\\
status =进行中
s tatus =分析
status =处理
status =评估
status =等待信息
[githookschecklog]
title-required = 1
title-最大宽度= 60
body-max-width = 80
[githookscheckfile]
sizelimit = 5242880
name = * .p [lm] / usr / local / bin / perlcritic --stern --verbose 5
name = * .pp / usr / local / bin / puppet-lint - 错误级别错误--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
...

然后在所有存储库中包含all-projects配置通过在GERRIT-SITE / git / REPO.git / config中添加folling

$ $ $ $ $ $ $ $ -SITE / git / all-projects.git / config

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

 ... 
[githooks]
plugin = CheckWhitespace
[githookscheckjira]
require = 0
unresolved = 0
...

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



3)重新启动Gerrit服务器

  GERRIT-SITE / bin / gerrit.sh restart 


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?

解决方案

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

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

这篇关于如何安装/配置Git :: Hooks以与Gerrit一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆