gpt4 book ai didi

github-api - 我可以通过 GitHub API 添加新的分支保护规则吗?

转载 作者:行者123 更新时间:2023-12-04 13:42:28 24 4
gpt4 key购买 nike

我知道您可以通过 API 更新现有的分支保护规则,但是我在创建新规则的 v3 API 文档 WRT 中找不到任何引用。例如,如果我想将规则添加到与前缀为“dev_”的新分支匹配的存储库中,我必须通过 GUI 添加它,使用“将规则应用于”字段,然后我可以使用 API 来更新那些规则设置。理想情况下,如果向 repo 引入新分支但与现有规则不匹配,我希望有一个钩子(Hook)可以自动执行此操作。我应该能够通过 API 创建该规则。有没有办法做到这一点?

最佳答案

这为我为 GitHub Enterprise 做到了。

curl --location --request PUT 'https://github.company.com/api/v3/repos/ORG/REPO-NAME/branches/BRANCH-NAME/protection' \
--header 'Accept: application/vnd.github.v3+json' \
--header 'Accept: application/vnd.github.luke-cage-preview+json' \
--header 'Authorization: Basic .................... \
--header 'Content-Type: text/plain' \
--data-raw '{
"required_status_checks": {
"strict": false,
"contexts": ["continuous-integration/jenkins/BRANCH-NAME"]
},
"enforce_admins": true,
"required_pull_request_reviews": {
"dismissal_restrictions": {},
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"required_approving_review_count": 1
},
"restrictions": {
"users": ["users"],
"teams": ["teams"],
"apps": ["apps"]
}
}
'

关于github-api - 我可以通过 GitHub API 添加新的分支保护规则吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55122273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com