是否有替代“推”钩? [英] Is there an alternative to a "push" hook?

查看:170
本文介绍了是否有替代“推”钩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bitbucket,Github和其他服务往往有一个推挂钩,所以当你将代码推送到存储库时,该服务可以打到一个URL(可能在生产服务器上),告诉它提取最新的代码。



问题是,如果我在云端有多个服务器(根据加载进入和退出),我没有办法知道多少服务器在任何给定的时间都在云中,所以我无法配置哪个URL推到。有没有一种替代方法?



有没有办法让所有的生产服务器在github,bitbucket等上打到一个url,并检查他们是否需要更新?这不是特定于任何一个服务,因为我想象如果任何一个服务都有它所有的一切。我只是不知道这个功能将被调用。

解决方案


Bitbucket,Github和其他服务往往有一个推钩子


其实,一个Git repo托管服务器将有另一个选项与Git 2.10(Q3 2016):推选项



请参阅 commit 3ac8703 commit f6a4e61 提交c714e45 commit 77a9745 (2016年7月14日)由 Stefan Beller ( stefanbeller

(合并b y Junio C Hamano - gitster - commit cf27c79 ,03 Aug 2016)



该功能是在此主题中提出的:


允许用户将信息沿推送到遥控器上的前/后接收挂钩。



当使用不仅仅是一个简单的Git主机的远程时(例如, Gerrit,
Git {hub / lab}等)这可能会变得更加明显:(服务器后端具体)推送选项可以指示服务器:




  • 开启拉票请求

  • 发送电子邮件要求查看

  • (un)触发持续集成

  • 设定持续整合的优先级(即机器人推送可能会要求以
    的优先级与人类相比较优先)

  • ...



大多数这些操作也可以在客户端完成,但是在这些以远程为中心的工作流程中,更容易在远程服务器上执行此操作,是为什么我们需要在那里传输信息。



更具体的例子:




  • 当您想要将Gerrit的变更提交给refs / heads / master时,您将
    推送到魔术分支 refs / for / master ,Gerrit将为您创建一个更改(类似于拉请求)。

    而不是w e可以想象,你可以通过推选项 create-change 推送到一个神奇的 refs / heads / master

  • 当推送到Gerrit时,您可以通过添加,然后将参数附加到ref,即与Gerrit进行交互时,可以执行 1 这样的操作:




  git push origin HEAD:refs / for / master%draft% topic=example%cc=jon.doe@xxxxxxxxxxx 




这不是吸引我们的用户,因为它看起来像黑客一样使其工作。



如果拼写为:




  git push origin HEAD:refs / for / master \ 
--push-option draft \
--push-option topic = example \
- -push-option cc=jon.doe@xxxxxxxxxxx




简单的形式,更容易键入,但这是更直观的)



Bitbucket, Github and other services tend to have a "push" hook, so that when you push code to the repository, the service can hit a url (possible on a production server), telling it to pull the latest code.

The problem is, if I have a number of servers in the cloud (which come in and out based on load), I do not have a way of knowing how many servers are in the cloud at any given time, so I cannot configure which urls to "push" to. Is there an alternative way?

Is there a way to instead have all the production servers hit a url on github, bitbucket etc, and check if they need to update ? This is not specific to any one service, because I imagine if any one service has it all of them will. I just don't know what the "feature" would be called.

解决方案

Bitbucket, Github and other services tend to have a "push" hook

Actually, a Git repo hosting server will have another option with Git 2.10 (Q3 2016): push options.

See commit 3ac8703, commit f6a4e61, commit c714e45, commit 77a9745 (14 Jul 2016) by Stefan Beller (stefanbeller).
(Merged by Junio C Hamano -- gitster -- in commit cf27c79, 03 Aug 2016)

That feature was proposed in this thread:

Allow a user to pass information along a push to the pre/post-receive hook on the remote.

When using a remote that is more than just a plain Git host (e.g. Gerrit, Git{hub/lab}, etc) this may become more obvious: The (server backend specific) push options can instruct the server to:

  • open a pull request
  • send out emails asking for review
  • (un)trigger continuous integration
  • set priority for continuous integration (i.e. bots pushing may ask to be treated with lower priority compared to humans)
  • ...

Most of these actions can be done on the client side as well, but in these remote-centric workflows it is easier to do that on the remote, which is why we need to transport the information there.

More concrete examples:

  • When you want a change in Gerrit to be submitted to refs/heads/master, you push instead to a magic branch refs/for/master and Gerrit will create a change for you (similar to a pull request).
    Instead we could imagine that you push to a magical refs/heads/master with a push option "create-change".
  • When pushing to Gerrit you can already attach some of this information by adding a '%' followed by the parameter to the ref, i.e. when interacting with Gerrit it is possible to do things like1:

git push origin HEAD:refs/for/master%draft%topic=example%cc=jon.doe@xxxxxxxxxxx

This is not appealing to our users as it looks like hacks upon hacks to make it work.

It would read better if it was spelled as:

git push origin HEAD:refs/for/master \
  --push-option draft \
  --push-option topic=example \
  --push-option cc=jon.doe@xxxxxxxxxxx

(with a short form that is even easier to type, but this is is more intuitive already)

这篇关于是否有替代“推”钩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆