防止根据标签有条件地合并分支
Prevent merging of branch conditionally based on label
我的团队使用无法访问 Draft Pull Requests 的私有分支,但我仍然希望至少有一种方法可以防止合并 Pull Requests,因为它们应用了自定义标签,例如“Draft”或“开发中。
有没有办法建立自定义 必需的状态检查来检查该标签或使用GitHub 操作使 PR 无效,直到标签被删除或类似的东西?
由于您没有可用的拉取请求草案,我假设您也没有分支保护规则。因此,您不能真正强制执行 您在问题中描述的内容。但是,可以给出一些图形提示,让用户知道 PR 是草稿。
这可以通过 GitHub Actions. You need to add the opened
, labeled
and unlabeled
type on the pull_request
trigger in order to run the workflow when the PR gets created or when labels get changed. Afterwards, you can define a job which only runs when the custom label (e.g. draft
) is present and just run exit 1
to fail 检查中的工作流程来完成。
这是完整的工作流程(例如check-draft.yml):
name: Check Draft
on:
pull_request:
# branches:
# - main
types:
- opened
- labeled
- unlabeled
jobs:
fail-for-draft:
if: contains(github.event.pull_request.labels.*.name, 'draft')
runs-on: ubuntu-latest
steps:
- name: Fail if PR is a draft
run: |
echo "This PR is currently a draft."
exit 1
Failed check with draft
label on PR: (请注意,即使合并按钮是灰色的,如果没有分支保护规则,实际上可以合并 PR设置。)
成功 运行,PR 上没有 draft
标签:
我的团队使用无法访问 Draft Pull Requests 的私有分支,但我仍然希望至少有一种方法可以防止合并 Pull Requests,因为它们应用了自定义标签,例如“Draft”或“开发中。
有没有办法建立自定义 必需的状态检查来检查该标签或使用GitHub 操作使 PR 无效,直到标签被删除或类似的东西?
由于您没有可用的拉取请求草案,我假设您也没有分支保护规则。因此,您不能真正强制执行 您在问题中描述的内容。但是,可以给出一些图形提示,让用户知道 PR 是草稿。
这可以通过 GitHub Actions. You need to add the opened
, labeled
and unlabeled
type on the pull_request
trigger in order to run the workflow when the PR gets created or when labels get changed. Afterwards, you can define a job which only runs when the custom label (e.g. draft
) is present and just run exit 1
to fail 检查中的工作流程来完成。
这是完整的工作流程(例如check-draft.yml):
name: Check Draft
on:
pull_request:
# branches:
# - main
types:
- opened
- labeled
- unlabeled
jobs:
fail-for-draft:
if: contains(github.event.pull_request.labels.*.name, 'draft')
runs-on: ubuntu-latest
steps:
- name: Fail if PR is a draft
run: |
echo "This PR is currently a draft."
exit 1
Failed check with draft
label on PR: (请注意,即使合并按钮是灰色的,如果没有分支保护规则,实际上可以合并 PR设置。)
成功 运行,PR 上没有 draft
标签: