Skip to content

Commit b79eb64

Browse files
authored
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
1 parent 1d40ad2 commit b79eb64

File tree

2 files changed

+3
-31
lines changed

2 files changed

+3
-31
lines changed

github/resource_github_branch_protection.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ func resourceGithubBranchProtection() *schema.Resource {
8585
},
8686
},
8787
PROTECTION_REQUIRES_STATUS_CHECKS: {
88-
Type: schema.TypeList,
89-
Optional: true,
90-
DiffSuppressFunc: statusChecksDiffSuppression,
88+
Type: schema.TypeList,
89+
Optional: true,
9190
Elem: &schema.Resource{
9291
Schema: map[string]*schema.Schema{
9392
PROTECTION_REQUIRES_STRICT_STATUS_CHECKS: {

github/util_v4_branch_protection.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra
155155
}
156156

157157
if v, ok := d.GetOk(PROTECTION_REQUIRES_STATUS_CHECKS); ok {
158+
data.RequiresStatusChecks = true
158159
vL := v.([]interface{})
159160
if len(vL) > 1 {
160161
return BranchProtectionResourceData{},
@@ -171,9 +172,6 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra
171172
}
172173

173174
data.RequiredStatusCheckContexts = expandNestedSet(m, PROTECTION_REQUIRED_STATUS_CHECK_CONTEXTS)
174-
if len(data.RequiredStatusCheckContexts) > 0 {
175-
data.RequiresStatusChecks = true
176-
}
177175
}
178176
}
179177

@@ -318,28 +316,3 @@ func getBranchProtectionID(repoID githubv4.ID, pattern string, meta interface{})
318316

319317
return nil, fmt.Errorf("Could not find a branch protection rule with the pattern '%s'.", pattern)
320318
}
321-
322-
func statusChecksDiffSuppression(k, old, new string, d *schema.ResourceData) bool {
323-
data := BranchProtectionResourceData{}
324-
checks := false
325-
326-
if v, ok := d.GetOk(PROTECTION_REQUIRES_STATUS_CHECKS); ok {
327-
vL := v.([]interface{})
328-
for _, v := range vL {
329-
if v == nil {
330-
break
331-
}
332-
333-
m := v.(map[string]interface{})
334-
data.RequiredStatusCheckContexts = expandNestedSet(m, PROTECTION_REQUIRED_STATUS_CHECK_CONTEXTS)
335-
if len(data.RequiredStatusCheckContexts) > 0 {
336-
checks = true
337-
}
338-
}
339-
}
340-
341-
if old == "0" && new == "1" && !checks {
342-
return true
343-
}
344-
return false
345-
}

0 commit comments

Comments
 (0)