gh api: only toggle lock_branch flag in branch protection
- Dominant language
- Go
- Stars
- 46.3k
- Forks
- 9k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 89
Description
I would like to toggle only `lock_branch` flag from branch protections, for that I am trying to use `gh api` with PUT request but giving following errors :
```
gh: Invalid request.
No subschema in "anyOf" matched.
No subschema in "anyOf" matched.
No subschema in "anyOf" matched.
More than one subschema in "oneOf" matched.
Not all subschemas of "allOf" matched.
For 'anyOf/1', {"url"=>"https://api.github.com/repos/repo/branches/main/protection/required_status_checks", "strict"=>true, "contexts"=>[], "contexts_url"=>"https://api.github.com/repos/repo/branches/main/protection/required_status_checks/contexts", "checks"=>[]} is not a null.
For 'allOf/0', {"url"=>"https://api.github.com/repos/repo/branches/main/protection/enforce_admins", "enabled"=>true} is not a boolean.
Not all subschemas of "allOf" matched.
For 'anyOf/1', {"url"=>"https://api.github.com/repos/repo/branches/main/protection/enforce_admins", "enabled"=>true} is not a null.
"teams" wasn't supplied.
Not all subschemas of "allOf" matched.
For 'anyOf/1', {"users"=>["users"]} is not a null. (HTTP 422)
```
_I am using the same payload generated from GET request for this as I **don't** want to change other settings_
```
echo '{
"enforce_admins": {
"url": "https://api.github.com/repos/repo/branches/main/protection/enforce_admins",
"enabled": true
},
"required_status_checks": {
"url": "https://api.github.com/repos/repo/branches/main/protection/required_status_checks",
"strict": true,
"contexts": [],
"contexts_url": "https://api.github.com/repos/repo/branches/main/protection/required_status_checks/contexts",
"checks": []
},
"required_pull_request_reviews": {
"url": "https://api.github.com/repos/repo/branches/main/protection/required_pull_request_reviews",
"dismiss_stale_reviews": true,
"require_code_owner_reviews": true,
"require_last_push_approval": false,
"required_approving_review_count": 1
},
"lock_branch": true,
"restrictions": {
"users": ["users"]
}
}' >/tmp/config-branch-rules
gh api --method PUT repos/repo/branches/main/protection --input /tmp/config-branch-rules >/dev/null
```
is there a clean way to toggle just `lock_branch` without sending this payload ? if not, what's wrong with the payload supplied, is it not possible to use the same payload given by GET ?
Contributor guide
Assessment
This issue has not been assessed yet.