gh api: only toggle lock_branch flag in branch protection
- Lingua principale
- Go
- Stelle
- 46.3k
- Fork
- 9k
- Merge medio
- 2g 6h
- PR unite (30g)
- 97
Descrizione
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 ?
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con l’endpoint PUT di GitHub per la protezione dei branch e con l’utilizzo di gh api --method PUT --input mostrato nell’issue. Confronta la risposta GET con lo schema della richiesta dell’endpoint, concentrandoti su lock_branch e sui campi di sola lettura. Il lavoro è completato quando viene documentato o supportato un modo pulito per alternare solo lock_branch senza inviare campi non validi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- github, go, shell
- Ambito
- api, cli
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 28/100