I am trying to set up branch protection for a new repository on GitHub through the API (https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#update-branch-protection). When trying it with gh cli I get the error message “expected map type under “required_status_checks”, got []interface {}” My command looks like this
gh api --method PUT -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/OWNER/REPO/branches/BRANCH/protection -F "required_status_checks[strict]=true" -f "required_status_checks[contexts[]]=build" -F "enforce_admins=false" -f "dismissal_restrictions[users[]]=null" -f "dismissal_restrictions[teams[]]=null" -F "required_pull_request_reviews[dismiss_stale_reviews]=true" -F "required_pull_request_reviews[require_code_owner_reviews]=false" -F "required_pull_request_reviews[required_approving_review_count]=1" -F "required_pull_request_reviews[require_last_push_approval]=false" -f "bypass_pull_request_allowances[users[]]=null" -f "bypass_pull_request_allowances[teams[]]=null" -f "restrictions[users[]]=null" -f "restrictions[teams[]]=team1" -f "restrictions[apps[]]=null" -F "require_linear_history=false" -F "allow_force_pushes=true" -F "allow_deletions=false" -F "block_creations=false" -F "required_conversation_solution=false" -F "lock_branch=false" -F "allow_fork_syncing=false"
with OWNER, REPO and BRANCH replaced accordingly.
I suspect required_status_checks[contexts[]]=build
is the problem so I tried putting build
in quotation marks and braces but to no avail. I also tried using curl and although this way it technically works, I need a token for my use-case and no token configuration worked with curl so far. So I went for gh cli instead.
Johannes L. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.