From d27da3529b874c5800fdef3c25bde603d1f0d4c2 Mon Sep 17 00:00:00 2001 From: Joshua Grohn Date: Tue, 17 Jan 2023 18:24:43 -0500 Subject: [PATCH] Bugfix: fix github_branch_protection required_status_checks not removing contexts (#1492) * fix github_branch_protection removing required_status_check contexts Now when github_branch_protection.required_status_checks.contexts is changed from a non-empty list to an empty list, all status checks are removed from the branch protection. * remove now unused githubV4STringSlice function Co-authored-by: Keegan Campbell --- github/resource_github_branch_protection.go | 4 ++-- github/util_v4.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index a99e089ffa..7a14a951a6 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -196,7 +196,7 @@ func resourceGithubBranchProtectionCreate(d *schema.ResourceData, meta interface PushActorIDs: githubv4NewIDSlice(githubv4IDSlice(data.PushActorIDs)), RepositoryID: githubv4.NewID(githubv4.ID(data.RepositoryID)), RequiredApprovingReviewCount: githubv4.NewInt(githubv4.Int(data.RequiredApprovingReviewCount)), - RequiredStatusCheckContexts: githubv4NewStringSlice(githubv4StringSlice(data.RequiredStatusCheckContexts)), + RequiredStatusCheckContexts: githubv4NewStringSlice(githubv4StringSliceEmpty(data.RequiredStatusCheckContexts)), RequiresApprovingReviews: githubv4.NewBoolean(githubv4.Boolean(data.RequiresApprovingReviews)), RequiresCodeOwnerReviews: githubv4.NewBoolean(githubv4.Boolean(data.RequiresCodeOwnerReviews)), RequiresCommitSignatures: githubv4.NewBoolean(githubv4.Boolean(data.RequiresCommitSignatures)), @@ -368,7 +368,7 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta interface Pattern: githubv4.NewString(githubv4.String(data.Pattern)), PushActorIDs: githubv4NewIDSlice(githubv4IDSlice(data.PushActorIDs)), RequiredApprovingReviewCount: githubv4.NewInt(githubv4.Int(data.RequiredApprovingReviewCount)), - RequiredStatusCheckContexts: githubv4NewStringSlice(githubv4StringSlice(data.RequiredStatusCheckContexts)), + RequiredStatusCheckContexts: githubv4NewStringSlice(githubv4StringSliceEmpty(data.RequiredStatusCheckContexts)), RequiresApprovingReviews: githubv4.NewBoolean(githubv4.Boolean(data.RequiresApprovingReviews)), RequiresCodeOwnerReviews: githubv4.NewBoolean(githubv4.Boolean(data.RequiresCodeOwnerReviews)), RequiresCommitSignatures: githubv4.NewBoolean(githubv4.Boolean(data.RequiresCommitSignatures)), diff --git a/github/util_v4.go b/github/util_v4.go index 035a94dbbe..87a0e841b3 100644 --- a/github/util_v4.go +++ b/github/util_v4.go @@ -21,8 +21,8 @@ func expandNestedSet(m map[string]interface{}, target string) []string { return res } -func githubv4StringSlice(ss []string) []githubv4.String { - var vGh4 []githubv4.String +func githubv4StringSliceEmpty(ss []string) []githubv4.String { + vGh4 := make([]githubv4.String, 0) for _, s := range ss { vGh4 = append(vGh4, githubv4.String(s)) }