git post-receive钩子抓取提交消息并发回URL [英] git post-receive hook that grabs commit messages and posts back to URL
问题描述
我们正在使用售票系统,我想在开发人员将其更改推送到服务器时自动更新。为了更新它,我只需要提供一个具有提交消息的特定URL作为GET变量。被调用的页面将记录此更改。我知道我的路要走钩子,但我不熟悉Bash和Perl所以这非常具有挑战性。
我想达到这个目的:
post-receive
钩子运行并检查哪些不同的提交是新的(因为可能有多次推送) curl http://server.com/logthis.asp?msg=Here_goes_the_commit_message$打开一个URL c $ c>,类似的东西)
就是这样。尽管我已经检出了一些 samples 与这种想法有关,但没有一个是完全这样做的。这怎么能做到?
主要的PITA是将我从/ usr / share / doc / git借用的新修订版/ contrib / hooks / post-receive-email(show_new_revisions)。
while read oval nval ref;如果expr为$ ref,则做
pre>
:^ refs / heads /;然后
如果expr$ oval:'0 * $'> / dev / null
然后
revspec = $ nval
else
revspec = $ oval。 。$ nval
fi
other_branches = $(git for-each-ref --format ='%(refname)'refs / heads / |
grep -F -v $ ref)
#您可能希望收集修订,以便在传输到错误追踪程序之前清理
#重复项,
#但不进行排序更容易;-)
在`git rev-parse - 不是$ other_branches | git rev-list --stdin $ revspec`;做
#我不知道你是否需要url转义内容
#你也可能想要在POST请求中传输数据
wgethttp:// server。 com / logthis.asp?msg = $(git log $ revision〜1 .. $ revision)
done
fi
done
We are using a ticketing system that I want to automatically update as developers push their changes to the server. In order to update it, I only need to provide a specific URL with the commit message as a GET variable. The page being called will then log this change. I know my way to go is with hooks, but I am not familiar with Bash nor Perl so it is quite challenging.
I want to achieve this:
- Developer PUSHes to the server
post-receive
hook runs and checks which different commits are new (because there could be several in one push)- It loops through them, and for each commit, it will open a URL with the commit message (
curl http://server.com/logthis.asp?msg=Here_goes_the_commit_message
, something like that)
That's it. Although I have checked out some samples related to this kind of idea, none do exactly this. How could this be done?
The main PITA is to isolate the correct list of new revisions, which I borrowed from /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钩子抓取提交消息并发回URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!