使用 Github API 禁用拉取请求的合并按钮并使用 REST 重新启用它
Use Github API to disable the merge button on a pull request and reenable it using REST
我开发了自己的网络服务器,可以在我的 android 应用程序上实现自动化。如果自动化运行时出现问题,我想使用 cURL REST 命令以编程方式禁用 github 拉取请求上的 "merge" 按钮。我无法找到执行此操作的正确方法,但似乎很多人会从该功能中受益。
可在此处找到 github 拉取请求的 api:https://developer.github.com/v3/pulls/
我知道这是可能的,因为如果你的分支上有合并冲突,按钮会变灰,你不能 click/merge 它。这正是我正在寻找的功能。任何帮助将不胜感激。
这是可能的。您应该采取几个步骤来启用此功能。
- Configure some of your branches (typically it's
master
or/and develop
, depends on your workflow) as protected
.
- 使用 Statuses API 可以发送
Pending
、Success
、Error
和 Failure
状态。 Pending
、Error
和 Failed
状态将阻止合并按钮。
完成后,您可以根据您的业务规则 POST 状态。
POST /repos/:owner/:repo/statuses/:sha
:sha
是 Pull Request 中最新提交的哈希值
像这样的负载:
{
"state": "success",
"target_url": "https://link.to/some/repotring/page",
"description": "Automation tests passed!",
"context": "continuous-integration/automation-tests"
}
有一件事值得一提。当您发布至少一个状态时,context
字段中的值将显示在受保护分支设置页面上。不要忘记将此状态标记为必需:
保护分支然后在状态检查未通过或审查未完成时阻止合并是可行的。这是一个非常直接的解决方案,而且效果很好。
但是,如果您更好奇,请尝试在不保护分支的情况下进行操作。我找不到执行此操作的方法。
我开发了自己的网络服务器,可以在我的 android 应用程序上实现自动化。如果自动化运行时出现问题,我想使用 cURL REST 命令以编程方式禁用 github 拉取请求上的 "merge" 按钮。我无法找到执行此操作的正确方法,但似乎很多人会从该功能中受益。
可在此处找到 github 拉取请求的 api:https://developer.github.com/v3/pulls/
我知道这是可能的,因为如果你的分支上有合并冲突,按钮会变灰,你不能 click/merge 它。这正是我正在寻找的功能。任何帮助将不胜感激。
这是可能的。您应该采取几个步骤来启用此功能。
- Configure some of your branches (typically it's
master
or/anddevelop
, depends on your workflow) asprotected
. - 使用 Statuses API 可以发送
Pending
、Success
、Error
和Failure
状态。Pending
、Error
和Failed
状态将阻止合并按钮。
完成后,您可以根据您的业务规则 POST 状态。
POST /repos/:owner/:repo/statuses/:sha
:sha
是 Pull Request 中最新提交的哈希值
像这样的负载:
{
"state": "success",
"target_url": "https://link.to/some/repotring/page",
"description": "Automation tests passed!",
"context": "continuous-integration/automation-tests"
}
有一件事值得一提。当您发布至少一个状态时,context
字段中的值将显示在受保护分支设置页面上。不要忘记将此状态标记为必需:
保护分支然后在状态检查未通过或审查未完成时阻止合并是可行的。这是一个非常直接的解决方案,而且效果很好。 但是,如果您更好奇,请尝试在不保护分支的情况下进行操作。我找不到执行此操作的方法。