我们正在使用一个票务系统,我想在开发人员将他们的更改推送到服务器时自动更新该系统。为了更新它,我只需要提供一个带有提交消息的特定 URL 作为 GET 变量。被调用的页面随后将记录此更改。我知道我要走的路是 hooks ,但我对 Bash 和 Perl 都不熟悉,所以这很有挑战性。
我想实现这个:
- 开发者推送到服务器
post-receive
Hook 运行并检查哪些不同的提交是新的(因为一次推送可能有多个)- 它循环遍历它们,对于每次提交,它将打开一个包含提交消息的 URL(
curl http://server.com/logthis.asp?msg=Here_goes_the_commit_message
,类似这样的内容)
最佳答案
主要的 PITA 是隔离正确的新修订列表,这是我从/usr/share/doc/git/contrib/hooks/post-receive-email(show_new_revisions) 借来的。
while read oval nval ref ; do
if expr "$ref" : "^refs/heads/"; then
if expr "$oval" : '0*$' >/dev/null
then
revspec=$nval
else
revspec=$oval..$nval
fi
other_branches=$(git for-each-ref --format='%(refname)' refs/heads/ |
grep -F -v $ref)
# You may want to collect the revisions to sort out
# duplicates before the transmission to the bugtracker,
# but not sorting is easier ;-)
for revision in `git rev-parse --not $other_branches | git rev-list --stdin $revspec`; do
# I don't know if you need to url-escape the content
# Also you may want to transmit the data in a POST request,
wget "http://server.com/logthis.asp?msg=$(git log $revision~1..$revision)"
done
fi
done
关于git post-receive hook 抓取提交消息并回发到 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8263186/