Repository navigation
fix(remediation): use PATCH for review requirements on protected branches (fixes #546) - #810
Daniel-park10 wants to merge 1 commit into
Conversation
8e13e65 to
5de932a
Compare
mlieberman85
left a comment
There was a problem hiding this comment.
Thanks @Daniel-park10. This PR hinges on one fact about GitHub: that PATCH .../required_pull_request_reviews turns reviews on for a protected branch that has none. That's exactly what #546 asks to check, and the recorded tests can't show it, because the simulated GitHub in conftest.py is changed here to accept the PATCH. GitHub's documentation doesn't say either way, and the status-checks endpoints of the same API answer 404 when their sub-protection is off.
If the PATCH is rejected, nothing is weakened. The read-back catches it, as #546 says. But AC-03.01 and QA-07.01 would then stop being fixed on those branches, where main fixes them today through the full PUT. So I'd like the evidence before approving. Could you add the transcript from your live check, with tokens and the repository name redacted as you like?
GET .../branches/{b}/protectionbefore, showing norequired_pull_request_reviews.- The
PATCH .../required_pull_request_reviewsrequest body and the response status and body. GET .../protectionafterwards, showingrequired_pull_request_reviewswithrequired_approving_review_countset and every other setting unchanged.
A regular protected branch (classic protection, not a ruleset) on a personal or organization repository is the case that matters.
Smaller:
- When reviews and status checks are both missing, the change set now sends the reviews
PATCHand then the fullPUT, which also carries the reviews. Nothing is lost, but it's two writes where main sent one, and thePUT's listed changes don't mention reviews. Folding reviews into thePUTwhenever there is one would keep it to one write. - The spec bump to 1.0.0-alpha.33 collides with #799 and the #802-#808 batch, which claim the same number. Whichever merges later renumbers.
Drafted with AI assistance (Claude), reviewed and filed by me.
e1fbd4e to
d578d23
Compare
|
Thanks @Daniel-park10. Folding reviews into the full What I still need before approving is the transcript from the live check you mention in the commit message: the protection GET before, the Also, the PR description still says "Removed Drafted with AI assistance (Claude), reviewed and filed by me. |
d578d23 to
9143fa2
Compare
…ches (fixes darnitdevorg#546) Enable or raise pull request review requirements with PATCH .../required_pull_request_reviews even when reviews are not yet configured on a protected branch, instead of triggering a full PUT. When another requirement already triggers a full PUT, fold the review change and its FieldChange into that PUT so only one write is sent. Verified against a disposable GitHub repository (classic branch protection) that PATCH .../required_pull_request_reviews returns 200 and preserves existing protection settings. Updated Section 4.5 of docs/architecture/framework-design.md, CHANGELOG.md, and the branch protection tests. Signed-off-by: Daniel-park10 <dev10.tennyson@gmail.com>
9143fa2 to
cf91e82
Compare
|
@mlieberman85 Updated the PR description to reflect the Here is the redacted transcript from verifying 1. Protection
|
Summary
Verified against the live GitHub REST API that
PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviewsenables pull request review requirements on a classic-protected branch without them (returning HTTP 200 and preserving existing protection settings, unlikerequired_status_checkswhich returns 404).Updated
_plan_branchinpackages/darnit/src/darnit/remediation/platform/targets.pyso missing review requirements usePATCH .../required_pull_request_reviewsdirectly when no other requirement needs a fullPUT. When another requirement already emits a fullPUT,fold_reviewsfolds the review change and itsFieldChangeinto thatPUTso only a single write is sent. Updateddocs/architecture/framework-design.md(Section 4.5,1.0.0-alpha.34),CHANGELOG.md,SimulatedGitHubinconftest.py, and the branch protection tests.Fixes #546.
Type of Change
Framework Changes Checklist
If this PR modifies the darnit framework (
packages/darnit/):docs/architecture/framework-design.md) if behavior changeduv run python scripts/validate_sync.py --verboseand it passesControl/TOML Changes Checklist
If this PR modifies controls or TOML configuration:
Testing
uv run pytest tests/darnit/remediation/platform/ tests/darnit_baseline/test_branch_protection_handler.py tests/darnit_baseline/test_enable_branch_protection.py -v)uv run ruff check .)Verified
PATCH .../required_pull_request_reviewson a disposable repository with classic branch protection (required_approving_review_countset to1and0).AI assistance
Additional Notes
None.