From 1c452165685ad01c80b100afb45b348f8443d7fa Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Mon, 8 Nov 2021 05:50:17 -0800 Subject: [PATCH] Fix strict branch protection (#954) * Initial commit of strict protection fix * Add back commented diff suppresion func to keep linter happy * Remove diff suppression function entirely --- github/resource_github_branch_protection.go | 5 ++-- github/util_v4_branch_protection.go | 29 +-------------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index 1f99a3db5a..1fec983f9b 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -85,9 +85,8 @@ func resourceGithubBranchProtection() *schema.Resource { }, }, PROTECTION_REQUIRES_STATUS_CHECKS: { - Type: schema.TypeList, - Optional: true, - DiffSuppressFunc: statusChecksDiffSuppression, + Type: schema.TypeList, + Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ PROTECTION_REQUIRES_STRICT_STATUS_CHECKS: { diff --git a/github/util_v4_branch_protection.go b/github/util_v4_branch_protection.go index e3f43aa61c..e55f47cdb4 100644 --- a/github/util_v4_branch_protection.go +++ b/github/util_v4_branch_protection.go @@ -155,6 +155,7 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra } if v, ok := d.GetOk(PROTECTION_REQUIRES_STATUS_CHECKS); ok { + data.RequiresStatusChecks = true vL := v.([]interface{}) if len(vL) > 1 { return BranchProtectionResourceData{}, @@ -171,9 +172,6 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra } data.RequiredStatusCheckContexts = expandNestedSet(m, PROTECTION_REQUIRED_STATUS_CHECK_CONTEXTS) - if len(data.RequiredStatusCheckContexts) > 0 { - data.RequiresStatusChecks = true - } } } @@ -318,28 +316,3 @@ func getBranchProtectionID(repoID githubv4.ID, pattern string, meta interface{}) return nil, fmt.Errorf("Could not find a branch protection rule with the pattern '%s'.", pattern) } - -func statusChecksDiffSuppression(k, old, new string, d *schema.ResourceData) bool { - data := BranchProtectionResourceData{} - checks := false - - if v, ok := d.GetOk(PROTECTION_REQUIRES_STATUS_CHECKS); ok { - vL := v.([]interface{}) - for _, v := range vL { - if v == nil { - break - } - - m := v.(map[string]interface{}) - data.RequiredStatusCheckContexts = expandNestedSet(m, PROTECTION_REQUIRED_STATUS_CHECK_CONTEXTS) - if len(data.RequiredStatusCheckContexts) > 0 { - checks = true - } - } - } - - if old == "0" && new == "1" && !checks { - return true - } - return false -}