简体   繁体   English

GitHub webhooks-如何检测合并的事实?

[英]GitHub webhooks - how to detect fact of merge?

I am developing an app that would detect that something was merged in specific branch and take some actions based on that. 我正在开发一个应用程序,该应用程序将检测到特定分支中已合并了某些内容,并根据该内容采取了一些措施。 In order to solve my problem I need to find the name of a branch that was merged to the branch I monitor. 为了解决我的问题,我需要找到已合并到我监视的分支的分支的名称。

Let's say GitHub sends me "everything" and my script must react when "some-branch" is merged to branch "Tests". 假设GitHub给我发送了“一切”,并且当“ some-branch”合并到分​​支“ Tests”时,我的脚本必须做出反应。 Also my script must be able to detect the name of merged branch (in this case "some-branch"). 我的脚本还必须能够检测合并分支的名称(在本例中为“ some-branch”)。

Only solution I found so far - is to read property "message" of every commit in array "commits" and parse it. 到目前为止,我发现的唯一解决方案是读取数组“ commits”中每个提交的“ message”属性并进行解析。 They are pretty tipical: "Merge branch 'some-branch' into Tests". 它们非常典型:“将分支“分支”合并到Tests中”。

There are two problems 有两个问题

  • Message theoretically could be modified by user (for example SourceTree shows you editor after conflict resolve) 理论上,消息可以由用户修改(例如,冲突解决后,SourceTree向您显示编辑器)
  • In case of Fast-Forward there is no message 如果是快进,则没有消息

What could you advise, how can I detect fact of merge and the name of merged branch better? 您能提供什么建议,如何更好地检测合并事实和合并分支的名称?

Thanks! 谢谢!

Only if the branch merge is via pull request on github, then you can detect the event or relate things, such as pull_request_review event. 仅当分支合并是通过github上的pull request时,您才能检测到该事件或将其关联起来,例如pull_request_review事件。

And for the command to view branches merged into Tests branch is git branch --merged Tests . 对于查看合并到Tests分支的分支的命令是git branch --merged Tests

I'm afraid due to the protocol of git, this is not always possible. 恐怕由于git的协议,这并不总是可能的。

  1. In fast-forward case, no new blobs are created, but only blobs are transferred to github. 在快进情况下,不会创建新的Blob,而只会将Blob传输到github。

  2. If a merge commit exists, as you already realized, the commit message may be overridden by user. 如您已经意识到的,如果存在一个合并提交,则该提交消息可能会被用户覆盖。

I guess the best we can do is to monitor a branch, and consider in terms of push instead of merge . 我想我们最好的办法是监视分支,并考虑使用push而不是merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM