Skip to content

Commit

Permalink
Fix strict branch protection (integrations#954)
Browse files Browse the repository at this point in the history
* Initial commit of strict protection fix

* Add back commented diff suppresion func to keep linter happy

* Remove diff suppression function entirely
  • Loading branch information
kfcampbell authored Nov 8, 2021
1 parent c5826fd commit 1c45216
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
5 changes: 2 additions & 3 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
29 changes: 1 addition & 28 deletions github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand All @@ -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
}
}
}

Expand Down Expand Up @@ -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
}

0 comments on commit 1c45216

Please sign in to comment.