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

前端 未结 1 956
野趣味
野趣味 2020-12-10 22:57

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?

相关标签:
1条回答
  • 2020-12-10 23:20

    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
    
    0 讨论(0)
提交回复
热议问题