Skip to content

Commit e39f178

Browse files
committed
Fix unexpected changes reported branch protection
1 parent 94f71cf commit e39f178

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

github/resource_github_branch_protection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func resourceGithubBranchProtection() *schema.Resource {
133133
PROTECTION_REQUIRED_STATUS_CHECK_CONTEXTS: {
134134
Type: schema.TypeSet,
135135
Optional: true,
136+
Computed: true,
136137
Description: "The list of status checks to require in order to merge into this branch. No status checks are required by default.",
137138
Elem: &schema.Schema{Type: schema.TypeString},
138139
},

github/resource_github_branch_protection_v3_utils.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,29 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
5050

5151
// TODO: Remove once contexts is fully deprecated.
5252
// Flatten contexts
53-
for _, c := range *rsc.Contexts {
54-
// Parse into contexts
55-
contexts = append(contexts, c)
53+
if rsc.Contexts != nil {
54+
for _, c := range *rsc.Contexts {
55+
// Parse into contexts
56+
contexts = append(contexts, c)
57+
}
58+
}
59+
60+
// Fallback to populating contexts from checks if it's empty (e.g. archived repo)
61+
if len(contexts) == 0 && rsc.Checks != nil {
62+
for _, chk := range *rsc.Checks {
63+
contexts = append(contexts, chk.Context)
64+
}
5665
}
5766

5867
// Flatten checks
59-
for _, chk := range *rsc.Checks {
60-
// Parse into checks
61-
if chk.AppID != nil {
62-
checks = append(checks, fmt.Sprintf("%s:%d", chk.Context, *chk.AppID))
63-
} else {
64-
checks = append(checks, chk.Context)
68+
if rsc.Checks != nil {
69+
for _, chk := range *rsc.Checks {
70+
// Parse into checks
71+
if chk.AppID != nil {
72+
checks = append(checks, fmt.Sprintf("%s:%d", chk.Context, *chk.AppID))
73+
} else {
74+
checks = append(checks, chk.Context)
75+
}
6576
}
6677
}
6778

0 commit comments

Comments
 (0)