From 8d3b207c089f208f855e0e82a47a0d88a897eb78 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 11 Dec 2025 14:17:54 +0200 Subject: [PATCH 1/2] refactor: Simplify JSON marshaling for RepositoryRulesetRules --- github/rules.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/github/rules.go b/github/rules.go index 1efb1783f92..57d29f8b938 100644 --- a/github/rules.go +++ b/github/rules.go @@ -573,9 +573,7 @@ type repositoryRulesetRuleWrapper struct { // MarshalJSON is a custom JSON marshaler for RulesetRules. func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) { - // The RepositoryRulesetRules type marshals to between 1 and 22 rules. - // If new rules are added to RepositoryRulesetRules the capacity below needs increasing - rawRules := make([]json.RawMessage, 0, 22) + var rawRules []json.RawMessage if r.Creation != nil { bytes, err := marshalRepositoryRulesetRule(RulesetRuleTypeCreation, r.Creation) From 6286ea6d87e4250727fb64a62f8b4733030a2121 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 11 Dec 2025 14:31:25 +0200 Subject: [PATCH 2/2] fix tests --- github/rules.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/github/rules.go b/github/rules.go index 57d29f8b938..f7ab4b613c9 100644 --- a/github/rules.go +++ b/github/rules.go @@ -791,6 +791,10 @@ func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) { rawRules = append(rawRules, json.RawMessage(bytes)) } + if len(rawRules) == 0 { + return []byte("[]"), nil + } + return json.Marshal(rawRules) }