Repository: google/go-github
File: github/repos_rules.go (Go)

Code before:
	StrictRequiredStatusChecksPolicy bool                       `json:"strict_required_status_checks_policy"`
}

// RepositoryRule represents a GitHub Rule.
type RepositoryRule struct {
	Type       string           `json:"type"`
	Parameters *json.RawMessage `json:"parameters,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// This helps us handle the fact that RepositoryRule parameter field can be of numerous types.
func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
	type rule RepositoryRule
	var RepositoryRule rule
	if err := json.Unmarshal(data, &RepositoryRule); err != nil {
		return err
	}

	r.Type = RepositoryRule.Type

	switch RepositoryRule.Type {
	case "creation", "deletion", "required_linear_history", "required_signatures", "non_fast_forward":
		r.Parameters = nil
	case "update":
		params := UpdateAllowsFetchAndMergeRuleParameters{}
		if RepositoryRule.Parameters != nil {
			if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
				return err
			}

			bytes, _ := json.Marshal(params)
			rawParams := json.RawMessage(bytes)

			r.Parameters = &rawParams
		} else {
			r.Parameters = nil
		}
	case "required_deployments":
		params := RequiredDeploymentEnvironmentsRuleParameters{}
		if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
			return err
		}

		bytes, _ := json.Marshal(params)
		rawParams := json.RawMessage(bytes)

		r.Parameters = &rawParams
	case "commit_message_pattern", "commit_author_email_pattern", "committer_email_pattern", "branch_name_pattern", "tag_name_pattern":
		params := RulePatternParameters{}
		if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
			return err

Review comment (suggestion):
Let's please change this to make it easier to read:

```go
if RepositoryRule.Parameters == nil {
  r.Parameters = nil
  return nil
}
```

Code after:
	StrictRequiredStatusChecksPolicy bool                       `json:"strict_required_status_checks_policy"`
}

// RepositoryRule represents a GitHub Rule.
type RepositoryRule struct {
	Type       string           `json:"type"`
	Parameters *json.RawMessage `json:"parameters,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// This helps us handle the fact that RepositoryRule parameter field can be of numerous types.
func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
	type rule RepositoryRule
	var RepositoryRule rule
	if err := json.Unmarshal(data, &RepositoryRule); err != nil {
		return err
	}

	r.Type = RepositoryRule.Type

	switch RepositoryRule.Type {
	case "creation", "deletion", "required_linear_history", "required_signatures", "non_fast_forward":
		r.Parameters = nil
	case "update":
		if RepositoryRule.Parameters == nil {
			r.Parameters = nil
			return nil
		}
		params := UpdateAllowsFetchAndMergeRuleParameters{}
		if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
			return err
		}

		bytes, _ := json.Marshal(params)
		rawParams := json.RawMessage(bytes)

		r.Parameters = &rawParams

	case "required_deployments":
		params := RequiredDeploymentEnvironmentsRuleParameters{}
		if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {
			return err
		}

		bytes, _ := json.Marshal(params)
		rawParams := json.RawMessage(bytes)

		r.Parameters = &rawParams
	case "commit_message_pattern", "commit_author_email_pattern", "committer_email_pattern", "branch_name_pattern", "tag_name_pattern":
		params := RulePatternParameters{}
		if err := json.Unmarshal(*RepositoryRule.Parameters, &params); err != nil {