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

fix(branch_protection_v3): ignore context when value exists in checks #2232

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 13 additions & 6 deletions github/resource_github_branch_protection_v3_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
var contexts []interface{}
var checks []interface{}

// TODO: Remove once contexts is fully deprecated.
// Flatten contexts
for _, c := range rsc.Contexts {
// Parse into contexts
contexts = append(contexts, c)
}
// Store check names
checksSet := make(map[string]struct{})

// Flatten checks
for _, chk := range rsc.Checks {
// Store check context
checksSet[chk.Context] = struct{}{}
// Parse into checks
if chk.AppID != nil {
checks = append(checks, fmt.Sprintf("%s:%d", chk.Context, *chk.AppID))
Expand All @@ -65,6 +63,15 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
}
}

// TODO: Remove once contexts is fully deprecated.
// Flatten contexts
for _, c := range rsc.Contexts {
// If the context is not in the checks, parse it into contexts.
if _, exists := checksSet[c]; !exists {
contexts = append(contexts, c)
}
}

return d.Set("required_status_checks", []interface{}{
map[string]interface{}{
"strict": rsc.Strict,
Expand Down
Loading