diff --git a/github/orgs_rules_test.go b/github/orgs_rules_test.go index 50ba4e20c01..eb40929acb3 100644 --- a/github/orgs_rules_test.go +++ b/github/orgs_rules_test.go @@ -115,10 +115,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T) "type": "creation" }, { - "type": "update", - "parameters": { - "update_allows_fetch_and_merge": true - } + "type": "update" }, { "type": "deletion" @@ -234,9 +231,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T) }, Rules: []*RepositoryRule{ NewCreationRule(), - NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{ - UpdateAllowsFetchAndMerge: true, - }), + NewUpdateRule(), NewDeletionRule(), NewRequiredLinearHistoryRule(), NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{ @@ -320,9 +315,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoNames(t *testing.T) }, Rules: []*RepositoryRule{ NewCreationRule(), - NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{ - UpdateAllowsFetchAndMerge: true, - }), + NewUpdateRule(), NewDeletionRule(), NewRequiredLinearHistoryRule(), NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{ @@ -429,10 +422,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) { "type": "creation" }, { - "type": "update", - "parameters": { - "update_allows_fetch_and_merge": true - } + "type": "update" }, { "type": "deletion" @@ -546,9 +536,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) { }, Rules: []*RepositoryRule{ NewCreationRule(), - NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{ - UpdateAllowsFetchAndMerge: true, - }), + NewUpdateRule(), NewDeletionRule(), NewRequiredLinearHistoryRule(), NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{ @@ -630,9 +618,7 @@ func TestOrganizationsService_CreateOrganizationRuleset_RepoIDs(t *testing.T) { }, Rules: []*RepositoryRule{ NewCreationRule(), - NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{ - UpdateAllowsFetchAndMerge: true, - }), + NewUpdateRule(), NewDeletionRule(), NewRequiredLinearHistoryRule(), NewRequiredDeploymentsRule(&RequiredDeploymentEnvironmentsRuleParameters{ diff --git a/github/repos_rules.go b/github/repos_rules.go index 4e6f5f13474..4e5c4f9d4f9 100644 --- a/github/repos_rules.go +++ b/github/repos_rules.go @@ -66,11 +66,6 @@ type RulePatternParameters struct { Pattern string `json:"pattern"` } -// UpdateAllowsFetchAndMergeRuleParameters represents the update rule parameters. -type UpdateAllowsFetchAndMergeRuleParameters struct { - UpdateAllowsFetchAndMerge bool `json:"update_allows_fetch_and_merge"` -} - // RequiredDeploymentEnvironmentsRuleParameters represents the required_deployments rule parameters. type RequiredDeploymentEnvironmentsRuleParameters struct { RequiredDeploymentEnvironments []string `json:"required_deployment_environments"` @@ -115,18 +110,8 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error { r.Type = RepositoryRule.Type switch RepositoryRule.Type { - case "creation", "deletion", "required_linear_history", "required_signatures", "non_fast_forward": + case "creation", "update", "deletion", "required_linear_history", "required_signatures", "non_fast_forward": r.Parameters = nil - case "update": - params := UpdateAllowsFetchAndMergeRuleParameters{} - if err := json.Unmarshal(*RepositoryRule.Parameters, ¶ms); 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, ¶ms); err != nil { @@ -184,14 +169,9 @@ func NewCreationRule() (rule *RepositoryRule) { } // NewUpdateRule creates a rule to only allow users with bypass permission to update matching refs. -func NewUpdateRule(params *UpdateAllowsFetchAndMergeRuleParameters) (rule *RepositoryRule) { - bytes, _ := json.Marshal(params) - - rawParams := json.RawMessage(bytes) - +func NewUpdateRule() (rule *RepositoryRule) { return &RepositoryRule{ - Type: "update", - Parameters: &rawParams, + Type: "update", } } diff --git a/github/repos_rules_test.go b/github/repos_rules_test.go index 582ec89245b..8edebe461df 100644 --- a/github/repos_rules_test.go +++ b/github/repos_rules_test.go @@ -60,17 +60,12 @@ func TestRepositoryRule_UnmarshalJSON(t *testing.T) { Parameters: nil, }, }, - "Valid update params": { - data: `{"type":"update","parameters":{"update_allows_fetch_and_merge":true}}`, - want: NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{UpdateAllowsFetchAndMerge: true}), - }, - "Invalid update params": { - data: `{"type":"update","parameters":{"update_allows_fetch_and_merge":"true"}}`, + "Valid update": { + data: `{"type":"update"}`, want: &RepositoryRule{ Type: "update", Parameters: nil, }, - wantErr: true, }, "Valid required_deployments params": { data: `{"type":"required_deployments","parameters":{"required_deployment_environments":["test"]}}`, @@ -254,10 +249,7 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) { "type": "creation" }, { - "type": "update", - "parameters": { - "update_allows_fetch_and_merge": true - } + "type": "update" } ]`) }) @@ -269,9 +261,7 @@ func TestRepositoriesService_GetRulesForBranch(t *testing.T) { } creationRule := NewCreationRule() - updateRule := NewUpdateRule(&UpdateAllowsFetchAndMergeRuleParameters{ - UpdateAllowsFetchAndMerge: true, - }) + updateRule := NewUpdateRule() want := []*RepositoryRule{ creationRule,