Skip to content

Commit c392e6f

Browse files
authored
chore: Simplify JSON marshaling for RepositoryRulesetRules (#3875)
1 parent b7fec34 commit c392e6f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

github/rules.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,9 +580,7 @@ type repositoryRulesetRuleWrapper struct {
580580

581581
// MarshalJSON is a custom JSON marshaler for RulesetRules.
582582
func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) {
583-
// The RepositoryRulesetRules type marshals to between 1 and 22 rules.
584-
// If new rules are added to RepositoryRulesetRules the capacity below needs increasing
585-
rawRules := make([]json.RawMessage, 0, 22)
583+
var rawRules []json.RawMessage
586584

587585
if r.Creation != nil {
588586
bytes, err := marshalRepositoryRulesetRule(RulesetRuleTypeCreation, r.Creation)
@@ -800,6 +798,10 @@ func (r *RepositoryRulesetRules) MarshalJSON() ([]byte, error) {
800798
rawRules = append(rawRules, json.RawMessage(bytes))
801799
}
802800

801+
if len(rawRules) == 0 {
802+
return []byte("[]"), nil
803+
}
804+
803805
return json.Marshal(rawRules)
804806
}
805807

0 commit comments

Comments
 (0)