Skip to content

fix: call the GitHub API with gh api instead of curl - #76

Open
sbp-bvanb wants to merge 2 commits into
mainfrom
fix-64-branch-protection-gh-api
Open

sbp-bvanb wants to merge 2 commits into
mainfrom
fix-64-branch-protection-gh-api

Conversation

@sbp-bvanb

Copy link
Copy Markdown
Collaborator

What and why

  • [Should fix] curl calls fail silently and build JSON by hand #64: the four curl --fail --silent calls (workflow permissions, actions permissions, selected actions, branch protection) are replaced with gh api -X PUT. gh uses GH_TOKEN and prints the API error on a 4xx, so the old silent exit 22 is gone. The workflow-permissions body is no longer JSON built by hand. It is sent as -f default_workflow_permissions=... -F can_approve_pull_request_reviews=.... -F turns true/false into JSON booleans. Any other value is sent as a string, and the API rejects it with a visible 422. The other calls send the files that main.py already writes, using --input. The debug input now sets GH_DEBUG=api instead of curl --verbose.
  • [Should fix] Redundant GraphQL branch-protection creation path #65: REST PUT /repos/{owner}/{repo}/branches/main/protection creates protection when none exists. The "is it protected?" check, the repositoryId lookup and the GraphQL createBranchProtectionRule mutation are removed, leaving a single PUT. Nothing else used create-branch-protection-rule.graphql, so it is deleted.
  • [Should fix] Dead locals in main.py branch-protection payload #68: the dead locals in main.py's branch_protection_rules are removed. None is now written straight into the dict, and required_pull_request_reviews is set directly instead of going through dict.update on a wrapper dict. The JSON it produces is unchanged.

Testing

  • uv run --no-project --python 3.11 --with '.[dev]' pytest: 6 passed. The existing tests cover both branch-protection paths and needed no changes.
  • action.yml parses as YAML. Every step's run script was extracted and passes bash -n. shellcheck reports nothing new; its only finding is a pre-existing info-level SC2153 on the topics step.
  • Not tested: I could not run the action against a real repository. The new gh api calls and creating protection on a branch that has none have not been run end to end. This repo's own settings.yml sets settings_protect_main_branch: false, so its own run will not exercise the branch-protection step either.

The general/PR-validation checks end in startup_failure on this fork because its Actions policy blocks schubergphilis/* actions. That problem already existed and is not caused by this change.

Closes #64
Closes #65
Closes #68

🤖 Generated with Claude Code

sbp-bvanb and others added 2 commits October 10, 2026 19:12
curl ran with --fail --silent, so a 4xx exited 22 without a message,
and the workflow-permissions body was JSON built by hand. gh api prints
API errors, uses GH_TOKEN and builds the body from typed fields or the
files main.py writes. The debug input now sets GH_DEBUG=api.

Branch protection is set with a single REST PUT, which creates the
protection when none exists, so the GraphQL create path, the
repositoryId lookup and create-branch-protection-rule.graphql go.

Closes #64
Closes #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Closes #68

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant