如何在Gerrit 2.16中配置服务器端挂钩 [英] How to configure server side hooks in Gerrit 2.16

查看:211
本文介绍了如何在Gerrit 2.16中配置服务器端挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始使用Gerrit 2.16作为代码审查工具,并希望配置服务器端挂钩以在将更改提交/推送到gerrit时验证git commit消息.

I have started using Gerrit 2.16 as code review tool and want to configure server side hooks to validate the git commit message when a change is committed/pushed to gerrit.

尝试通过使用钩子将脚本复制到$ GIT_DIR/hooks(诸如ref-update,patchset创建的,更改合并的脚本),在gerrit服务器上授予了权限,但没有任何效果.

Tried using hooks by copying scripts to $GIT_DIR/hooks (scripts like ref-update, patchset-created, change-merged), gave permission on the gerrit server but nothing works.

commit-msg挂钩

commit-msg hook can be enabled on local repository by using command give in gerrit UI

示例: git clone ssh://@:29418/Project1&& scp -p -P 29418 @:hooks/commit-msg/.git/hooks/

example: git clone ssh://@:29418/Project1 && scp -p -P 29418 @:hooks/commit-msg /.git/hooks/

change_ID.

change_ID will be automatically generated if this hook is enabled.

执行上述命令后,此脚本commit-msg将下载到本地存储库中.
我的问题;可以在gerrit服务器上找到此脚本的路径,以便我可以修改并强制执行git commit消息验证吗?

This script commit-msg gets downloaded to local repository when above command is executed.
My question; can we find path of this script on the gerrit server, so that I can modify and enforce git commit message validation?

或者还有其他方法可以启用gerrit服务器端挂钩吗?

Or is there any other way to enable gerrit server side hooks?

推荐答案

#!/bin/bash
echo "Executing hook from Gerrit_DIR "
bold=$(tput bold)
normal=$(tput sgr0)
RED='\033[0;31m'
NC='\033[0m' # No Color
GIT_DIR="/opt/gerrit/site/git"
PROJECT=$2
REFNAME=$4
UPLOADER=$6
OLDREV=$8
NEWREV="${10}"
BASE="<baseDir>"
RepoDir="$GIT_DIR/$PROJECT.git"
echo $RepoDir
echo $PROJECT
echo $8
echo ${10}


# execute the project specific hook
if [ -f "$RepoDir/hooks/commit-received" ]
    then
    echo "Executing the project specific hook"
    $RepoDir/hooks/commit-received $RepoDir ${10}
else
    echo "There is no project specific hook"
fi

这篇关于如何在Gerrit 2.16中配置服务器端挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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