Update an existing ruleset instead of failing to create a second one - #39
Merged
Conversation
Found finishing the `oposs/mkp-builder` conversion. `apply --item required-checks` died with `gh: Validation Failed (HTTP 422)`: the repository already had a ruleset named `main`, and POST creates rather than adopts. This is not an edge case. It is every repository that was protected before it was converted, and `check` says so on the line above -- `branch-protection ok` is read from exactly the ruleset the POST then collides with. mkp-builder's existing ruleset was the standard's payload minus the required_status_checks rule, which is the whole reason `required-checks` was the item still missing. `Gh.ruleset_id` looks for a Repository-source ruleset of that name; PUT to it when there is one, POST when there is not. An organisation ruleset is not adopted: it cannot be written through this endpoint and its name does not collide with a repository one. Every guard on the POST path is on the PUT path, because they are the same code after the call -- the read-back that rejects a ruleset which comes back disabled, bypassed, not covering the default branch, or missing the required contexts. A test pins that for the PUT path specifically. Four fault injections, each confirmed red: always POST, always PUT, adopt an organisation ruleset, and the read-back on the PUT path. 290 tests, ruff clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found finishing the
oposs/mkp-builderconversion — the second defect that only usingapplyon a real repository could surface.The repository already had a ruleset named
main. POST creates; it cannot adopt.This is not an edge case
It is every repository that was protected before it was converted — and
checksays so on the line directly above:Both facts are read from the same ruleset. The one that reads
okis the one the POST collides with. mkp-builder’s existing ruleset was the standard’s payload minus therequired_status_checksrule, which is exactly whyrequired-checkswas the item still outstanding.Fix
Gh.ruleset_idlooks for aRepository-source ruleset of that name. PUT to it when there is one, POST when there is not.An organisation ruleset is deliberately not adopted: it cannot be written through the repository endpoint, and its name does not collide with a repository one.
Every guard on the POST path is on the PUT path — they are the same code after the call — so a ruleset that comes back disabled, bypassed, not covering the default branch, or missing a required context is still refused. A test pins that for the PUT path specifically, because "the write did not error" was never the evidence here.
Evidence
290 passed, 5 deselected,uvx ruff check .clean.🤖 Generated with Claude Code