fix(rules): keep the public toggle on repository visibility rules - #4455
Open
yordis wants to merge 1 commit into
Open
fix(rules): keep the public toggle on repository visibility rules#4455yordis wants to merge 1 commit into
yordis wants to merge 1 commit into
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>
5 tasks
Contributor
Author
|
@alexandear what about it? |
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.
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.