fix: Keep the public toggle on repository visibility rules - #4455
Conversation
GitHub's repository policy API exposes a third visibility toggle, and dropping it on unmarshal silently revokes public visibility on any full-replace update built from a ruleset the SDK read back. Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
|
@alexandear what about it? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4455 +/- ##
=======================================
Coverage 98.51% 98.51%
=======================================
Files 194 194
Lines 17603 17603
=======================================
Hits 17342 17342
Misses 261 261 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
public toggle on repository visibility rules
|
@gmlewis aye, let me know, as soon as this is merged, I will follow up on fixing the terraform provider, just so my paranoia is checked 😅 |
Sorry, I should have been more specific. I was pointing at the "Assisted contributions" section:
The PR description reads as AI-assisted to me, and this is unnecessary:
If a tool helped here, could you add a oneline note about it? Not blocking the review - just keeping us consistent with the guideline. |
|
Thank you, @yordis, @stevehipwell, and @alexandear! @yordis - you can address @alexandear's comments after the merge. |

RepositoryVisibilityRuleParametersmodels onlyinternalandprivate, but the repository policy API has a third toggle,public. Becauseencoding/jsondiscards unknown keys, the flag is lost on read, and sincePUT /orgs/{org}/rulesets/{ruleset_id}is a full replace, writing back a ruleset the SDK just read silently resets public visibility tofalse.Found while adding the
repositoryruleset target to the Terraform provider: integrations/terraform-provider-github#3598.Verified against the live API
Against a real
target: repositoryruleset on a github.com organization on the Team plan, using a program that fetches the same ruleset twice: once over plainnet/httpto capture the wire bytes, and once throughOrganizations.GetRepositoryRuleset. Org name and ruleset ID redacted.On
v90.0.0:The server sends the key and the SDK drops it. Since
UpdateRepositoryRulesetis a full replace, a read-modify-write built from that value omitspublicand the API resolves it tofalse.With this patch applied:
Then a write round trip through
Organizations.UpdateRepositoryRuleset, toggling onlyPublicon the decoded struct:The API accepts the field on write and echoes it back, and the "Restrict visibility" section of the org policy UI showed Public checked while it was
true. After restoring, the full ruleset body diffed equal to a backup taken before the run, ignoringupdated_at.Verified in this repo
go build ./...go test ./... -count=1script/fmt.shandscript/lint.sh, including the generated-files checkgithub-accessors.goandgithub-accessors_test.goare regenerated output.Test coverage added for the round trip: the
repository_visibilitycases inTestRepositoryRulenow carrypublic: truein both the marshal and unmarshal tables, which fails without the struct field.For context on why this was missed:
repository_visibilitydoes not appear anywhere ingithub/rest-api-description(zero matches in bothapi.github.com.jsonandghec.jsonas of today), so there is no generated schema to check the field list against. The name and JSON shape used here come from the live responses above.