gpt4 book ai didi

git - 使用 GitLab 自定义接收后文件

转载 作者:太空狗 更新时间:2023-10-29 13:17:05 28 4
gpt4 key购买 nike

我正在尝试用一个启用邮件支持的新文件替换由 GitLab 自动生成的接收后 Hook ,因此必须触发“接收后”。

这是我文件的以前版本:

#!/usr/bin/env bash

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

while read oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
repo_path=`pwd`
env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostRe
ceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}
" > /dev/null 2>&1
done

当我用文件末尾包含上述行的新文件替换该文件时,GitLab 在管理区域显示:“项目有无效的后接收文件”,但电子邮件已正确发送。

您知道如何处理多个接收后支持的问题吗?目前我完全不知道文件的 gitlab 特定部分是否正确执行。

感谢您的帮助!

更新:

现在使用下面提到的解决方案( pull 请求)调用文件夹中的脚本。但我不明白为什么标准的“post-receive-email”脚本如果包含在目录中则不发送任何邮件。如果它作为接收后直接调用,它工作正常。

不知道为什么我必须更改顺序,但以下对我有用(即使我不知道现在是否正确创建了 resque 作业:

#!/usr/bin/env bash

repo_path=`pwd`

if [ -d hooks/post-receive.secondary.d ]; then

for i in hooks/post-receive.secondary.d/*
do
[ -x "$i" ] || continue
# call the hooklet with the same arguments we got
path=$repo_path"/"$i
"$path" "$@" || {
# hooklet failed; we need to log it...
echo hooklet $i failed
perl -I$GL_BINDIR -Mgitolite -e "log_it('hooklet $i failed')"
# ...and send back some non-zero exit code ;-)
exit 1
}
done

fi

while read oldrev newrev ref
do
# For every branch or tag that was pushed, create a Resque job in redis.
env -i redis-cli rpush "resque:gitlab:queue:post_receive" "{\"class\":\"PostReceive\",\"args\":[\"$repo_path\",\"$oldrev\",\"$newrev\",\"$ref\",\"$GL_USER\"]}" > /dev/null 2>&1
done

exit 0

最佳答案

2014 年更新,GitLab 不再使用 gitolite:

作为mentioned below通过 Ciro Santilli , 现在有一个官方的方式来 setup custom hooks (GitLab 7.5.0+,2014 年 11 月)。

  1. Pick a project that needs a custom git hook.
  2. On the GitLab server, navigate to the project's repository directory.
    For a manual install the path is usually /home/git/repositories/<group>/<project>.git.
    For Omnibus installs the path is usually /var/opt/gitlab/git-data/repositories/<group>/<project>.git.
  3. Create a new directory in this location called custom_hooks.
  4. Inside the new custom_hooks directory, create a file with a name matching the hook type.
    For a pre-receive hook the file name should be pre-receive with no extension.
  5. Make the hook file executable and make sure it's owned by git.
  6. Write the code to make the git hook function as expected. Hooks can be in any language. Ensure the 'shebang' at the top properly reflects the language type.
    For example, if the script is in Ruby the shebang will probably be #!/usr/bin/env ruby.

原始答案(2013 年 1 月)

这(允许自定义 Hook )已通过 pull request 555 解决和 commit 2245a6bbe ,当时 GitLab 使用更新后 Hook 。

您需要声明一个 hooks/post-receive.secondary.d在由 gitolite 和 GitLab 管理的 git bare repo 中。
将所有更新后 Hook 放在那里。

您可以修改 gitolite following that model 发布的更新后 Hook : 如果检测到,它将调用您所有的更新后 Hook 。


问题是:

使用 Gitolite V2,GitLab 最终将管理委托(delegate)给 Gitolite,因为您可以 declare post-update.secondary hooks , Gitolite 本身会调用。

With Gitolite V3, there is no longer any reserved hook (除了 gitolite-admin repo 中的更新),所以没有 gitolite “辅助”机制。
但是 GitLab(现在使用接收后 Hook )尚未更新其 Hook 管理以考虑新的现实(gitolite 不再允许二次 Hook )。

关于git - 使用 GitLab 自定义接收后文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14317452/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com