Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diff suppression function to the branch protection resource #614

Merged
merged 1 commit into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}