You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Webhooks allow you to build or set up integrations which subscribe to certain events on GitHub.com. When one of those events is triggered, we'll send a HTTP POST payload to the webhook's configured URL. Webhooks can be used to update an external issue tracker, trigger CI builds, update a backup mirror, or even deploy to your production server. You're only limited by your imagination.
The text was updated successfully, but these errors were encountered:
webhooks类似于事件。
举例来说,如果一个webhook被设置成发表评论后触发,设置的URL是http://example.com ,当有人发表评论后,github/gitlab/bitbucket的服务器会向http://example.com 发送一个http请求,请求中会包含一些信息,比如评论内容、作者、在哪里评论的等等。所以一般需要创建一个服务来处理这个http请求,在本地执行自定义的脚本。
那么可以做些什么呢?
测试
如果有了个pull request,可以发表一个包含开始测试命令的评论,服务收到请求后,根据评论内容匹配命令,执行相应的脚本,主要是pull这个分支的代码,执行测试。如果涉及到UI,还可以在测试环境执行切换分支的命令,成功后就可以在测试环境查看UI的变化了。
以github和node为例,执行指令:
安全性
服务需要确定收到的请求没有被伪造,以github为例,github会对请求的body签名,所以服务需要对签名进行验证。
以github和node为例,计算签名:
具体的文档,可见https://developer.github.com/webhooks/securing/ 。
权限问题:可以设置白名单,只有白名单内的人的评论,才会触发脚本的执行。
以github和node为例,验证评论人:
反馈结果
以上做法,并不能确定测试是否成功。
可以创建一个robot账户,当脚本执行成功或失败后,以这个robot账户的身份通过API发表评论,评论的内容就是反馈的结果。
以github和node为例,发表评论:
具体文档,可见https://developer.github.com/v3/issues/comments/#create-a-comment 。
部署和回滚
如果测试通过、code review通过、UI也OK,pull request就被合并了,如果发布一个带部署指令的评论,相应的部署脚本被执行,就可以实现部署了。
这是一个部署的例子:plantain-00/SubsNoti#168 ,这个例子里,部署指令是:
robot
、deploy
和please
都在评论内容里。checklist
一个pull request被创建后,robot立刻发布包含checklist的评论,所有参与人就可以按照这个checklist review代码,checklist中每一项的状态会一直存在,就像这样:
这是一个checklist的具体例子:DefinitelyTyped/DefinitelyTyped#7704
命令队列
同时执行多个命令很可能造成错误,所以收到命令后,应该先存到队列中,再依次执行。
自定义邮件通知
一个pull request被创建后,robot可以发邮件给多个相关的reviewer。
同意license
这个例子里,服务会查询作者有没有同意过license,如果没有,就会发评论提示,并加上
cla-required
tag,当作者通过链接同意了协议后,服务会移除cla-required
tag,并加上cla-signed
tag。具体例子:microsoft/TypeScript#6512 ,
结束
最后以Github文档中的一段(https://developer.github.com/webhooks/ ),来结束:
The text was updated successfully, but these errors were encountered: