验证GitHub重基和合并的提交消息
我正在寻找一种通过预接收挂钩验证提交消息的方法 我能够为挤压和合并提交验证它,但是,它不适用于GitHub重基和合并验证GitHub重基和合并的提交消息,github,rebase,githooks,git-rebase,Github,Rebase,Githooks,Git Rebase,我正在寻找一种通过预接收挂钩验证提交消息的方法 我能够为挤压和合并提交验证它,但是,它不适用于GitHub重基和合并 set -e zero_commit='0000000000000000000000000000000000000000' msg_regex='<pattern_here>' release_branches=( topic master ) exit_code=0 containsElement () { local e match="$1&qu
set -e
zero_commit='0000000000000000000000000000000000000000'
msg_regex='<pattern_here>'
release_branches=( topic master )
exit_code=0
containsElement () {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
while read oldsha newsha refname; do
short_current_branch="$(echo ${refname} | sed 's/refs\/heads\///g')"
if containsElement "${short_current_branch}" "${release_branches[@]}"; then
echo "${short_current_branch} is in ${release_branches[@]}"
else
echo "${short_current_branch} is not in ${release_branches[@]}"
echo "Skipping execution"
continue
fi
case ${oldsha},${newsha} in
*,${NULL_SHA1}) # it's a delete
any_deleted=true;;
${NULL_SHA1},*) # it's a create
new_list="$new_list $newsha";;
*,*) # it's an update
new_list="$new_list $newsha";;
esac
done
if [[ -z "$new_list" ]]
then
exit ${exit_code}
fi
commit_msg=()
git rev-list ${new_list} --not --all |
while read sha1; do
message=$( git log --max-count=1 --format=%B ${sha1} | head -1)
if ! echo "${message}" | grep -o "<regex_pattern>" ; then
echo "ERROR:"
echo "ERROR: Your push was rejected because commit: ${commit}"
echo "ERROR: is missing radar link in first line of below commit message:"
echo "ERROR: ${message}"
echo "ERROR:"
echo "ERROR: Please fix commit message and push again."
echo "ERROR: https://docs.github.com/en/enterprise-
server@2.21/github/committing-
changes-to-your-project/changing-a-commit-message"
echo "ERROR"
exit_code=1
fi
done
exit ${exit_code}
set-e
零提交='0000000000000000000000000000'
msg_regex=''
发布分支=(主题主控)
退出代码=0
容器组件(){
本地e匹配=“$1”
转移
对于e;do[“$e”==“$match”]]&&return 0;done
返回1
}
阅读oldsha newsha refname时;做
short_current_branch=“$(echo${refname}| sed's/refs\/heads\///g”)
如果containseElement“${short\u current\u branch}”${release\u branchs[@]}”;然后
echo“${short\u current\u branch}位于${release\u branchs[@]}”中
其他的
echo“${short\u current\u branch}不在${release\u branchs[@]}”中
回显“跳过执行”
持续
fi
案例${oldsha},${newsha}in
*,${NULL_SHA1})#这是一个删除
删除的任何_=真;;
${NULL_SHA1},*)#这是一个create
new_list=“$new_list$newsha”;;
*,*)#这是一个更新
new_list=“$new_list$newsha”;;
以撒
完成
如果[-z“$new_list”]]
然后
退出${exit_code}
fi
提交消息=()
git rev list${new_list}--不是--全部|
读sha1时;做
message=$(git log--max count=1--format=%B${sha1}| head-1)
如果!回显“${message}”| grep-o”;然后
回显“错误:”
echo“错误:推送被拒绝,因为提交:${commit}”
echo“错误:在下面提交消息的第一行中缺少雷达链接:”
echo“错误:${message}”
回显“错误:”
echo“错误:请修复提交消息并再次推送。”
“回声”错误:https://docs.github.com/en/enterprise-
server@2.21/github/提交-
对项目的更改/更改提交消息”
回显“错误”
退出代码=1
fi
完成
退出${exit_code}