Repository navigation
fix: Send empty required status check lists - #4736
LemonCondor wants to merge 1 commit into
Conversation
RequiredStatusChecksRequest tagged Contexts and Checks with omitempty, so an explicitly empty slice was dropped from the PATCH body and UpdateRequiredStatusChecks could not clear the required checks of a protected branch: the request became a no-op for those lists. Use omitzero so nil slices are still omitted while non-nil empty slices are sent as [].
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4736 +/- ##
=======================================
Coverage 98.64% 98.64%
=======================================
Files 204 204
Lines 19164 19164
=======================================
Hits 18904 18904
Misses 260 260 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gmlewis
left a comment
There was a problem hiding this comment.
Thank you, @LemonCondor!
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
| }) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
We are essentially testing the marshaling behavior of omitzero here.
Do we really need this test?
There was a problem hiding this comment.
Fair point, it mostly tests omitzero itself. I can remove it, or keep a single empty Checks case as a guard against going back to omitempty. Which do you prefer?
There was a problem hiding this comment.
I prefer the second option.
RequiredStatusChecksRequesttagsContextsandCheckswithomitempty, so an explicitly empty slice is dropped from the request body. Because of this,UpdateRequiredStatusCheckscannot clear the required checks of a protected branch while keeping status check protection (andstrict) enabled:The response type
RequiredStatusChecksalready documents that "An empty slice is valid" for these fields and uses pointer slices so that[]can be sent.This PR switches the two fields to
omitzero, likeBypassActors(#3891) andPatternsAllowed(#4371). A nil slice is still omitted, so existing callers that leave the fields unset send the same body as before (#2976 showed that sendingnullis rejected); only a non-nil empty slice now goes out as[].Tests:
TestRepositoriesService_UpdateRequiredStatusChecks_EmptyListschecks the raw PATCH body for an emptyChecks, an emptyContexts, and unset lists. The first two cases fail without the change and pass with it.Ran locally:
go test ./github/,go vet ./github/,gofmt -l github/, and thestructfieldanalyzer on the package (no finding on the changed fields). I did not run the fullscript/lint.sh(custom golangci-lint build) orscript/generate.sh; the field types are unchanged, so the generated accessors should not change.AI disclosure: an AI coding assistant found this issue and wrote the change, the test and this description.