git post-receive 钩子,抓取提交消息并回发到 URL

发布于 2024-12-18 10:15:41 字数 715 浏览 3 评论 0原文

我们正在使用一个票务系统,当开发人员将更改推送到服务器时,我希望自动更新该系统。为了更新它,我只需要提供一个带有提交消息的特定 URL 作为 GET 变量。然后,被调用的页面将记录此更改。我知道我的方法是使用 hooks,但我不熟悉 Bash 也不熟悉 Perl所以这是相当有挑战性的。

我想实现这一点:

  • 开发人员推送到服务器
  • post-receive 挂钩运行并检查哪些不同的提交是新的(因为一次推送中可能有多个)
  • 它循环遍历它们,并且对于每个提交,它将打开一个带有提交消息的 URL(curl http://server.com/logthis.asp?msg=Here_goes_the_commit_message,类似的东西)

就是这样。尽管我已经查看了一些 示例 与这种想法相关,没有人完全做到这一点。这怎么可能做到呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲸落 2024-12-25 10:15:41

主要的 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文