Skip to content

Commit

Permalink
Add diff suppression function to the branch protection resource (inte…
Browse files Browse the repository at this point in the history
…grations#614)

Adding a diff suppression function to the branch protection resource to
ignore the strict status check field if no contexts have been specified.

This resolves the issue with the GraphQL API returning a strict status
check value of "true" by default, regardless of contexts being set or
not.
  • Loading branch information
patrickmarabeas authored Dec 18, 2020
1 parent c73564e commit 3363991
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func resourceGithubBranchProtection() *schema.Resource {
PROTECTION_REQUIRES_STATUS_CHECKS: {
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: statusChecksDiffSuppression,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
PROTECTION_REQUIRES_STRICT_STATUS_CHECKS: {
Expand Down
25 changes: 25 additions & 0 deletions github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,28 @@ func getBranchProtectionID(name string, pattern string, meta interface{}) (githu

return id, nil
}

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 3363991

Please sign in to comment.