From fb3f0aabfe0e4114f49e4c389a6f5666295449fd Mon Sep 17 00:00:00 2001 From: Matthew Costa Date: Tue, 14 Nov 2023 16:58:55 +0000 Subject: [PATCH 1/5] Add the require_last_push_approval flag as an option for the required_pull_request_reviews of github_branch_protection_v3 --- github/resource_github_branch_protection_v3.go | 6 ++++++ github/resource_github_branch_protection_v3_test.go | 4 ++++ github/resource_github_branch_protection_v3_utils.go | 1 + website/docs/r/branch_protection_v3.html.markdown | 1 + 4 files changed, 12 insertions(+) diff --git a/github/resource_github_branch_protection_v3.go b/github/resource_github_branch_protection_v3.go index d653856cac..61680f3e83 100644 --- a/github/resource_github_branch_protection_v3.go +++ b/github/resource_github_branch_protection_v3.go @@ -128,6 +128,12 @@ func resourceGithubBranchProtectionV3() *schema.Resource { Description: "Require 'x' number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6.", ValidateFunc: validation.IntBetween(0, 6), }, + "require_last_push_approval": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Require that The most recent push must be approved by someone other than the last pusher.", + }, "bypass_pull_request_allowances": { Type: schema.TypeList, Optional: true, diff --git a/github/resource_github_branch_protection_v3_test.go b/github/resource_github_branch_protection_v3_test.go index 80d7ab1c16..f26544b930 100644 --- a/github/resource_github_branch_protection_v3_test.go +++ b/github/resource_github_branch_protection_v3_test.go @@ -320,6 +320,7 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T) dismiss_stale_reviews = true require_code_owner_reviews = true required_approving_review_count = 1 + require_last_push_approval = true dismissal_users = ["a"] dismissal_teams = ["b"] dismissal_apps = ["c"] @@ -347,6 +348,9 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T) resource.TestCheckResourceAttr( "github_branch_protection_v3.test", "required_pull_request_reviews.0.required_approving_review_count", "1", ), + resource.TestCheckResourceAttr( + "github_branch_protection_v3.test", "required_pull_request_reviews.0.require_last_push_approval", "true", + ), resource.TestCheckResourceAttr( "github_branch_protection_v3.test", "required_pull_request_reviews.0.dismissal_users.#", "1", ), diff --git a/github/resource_github_branch_protection_v3_utils.go b/github/resource_github_branch_protection_v3_utils.go index 596933e115..87d4d46f61 100644 --- a/github/resource_github_branch_protection_v3_utils.go +++ b/github/resource_github_branch_protection_v3_utils.go @@ -351,6 +351,7 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool) rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool) rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int) + *rprr.RequireLastPushApproval = m["require_last_push_approval"].(bool) rprr.BypassPullRequestAllowancesRequest = bpra } diff --git a/website/docs/r/branch_protection_v3.html.markdown b/website/docs/r/branch_protection_v3.html.markdown index 7a23f37941..5c54aa11d7 100644 --- a/website/docs/r/branch_protection_v3.html.markdown +++ b/website/docs/r/branch_protection_v3.html.markdown @@ -112,6 +112,7 @@ The following arguments are supported: * `require_code_owner_reviews`: (Optional) Require an approved review in pull requests including files with a designated code owner. Defaults to `false`. * `required_approving_review_count`: (Optional) Require x number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6. This requirement matches GitHub's API, see the upstream [documentation](https://developer.github.com/v3/repos/branches/#parameters-1) for more information. * `bypass_pull_request_allowances`: (Optional) Allow specific users, teams, or apps to bypass pull request requirements. See [Bypass Pull Request Allowances](#bypass-pull-request-allowances) below for details. +* `require_last_push_approval`: (Optional) Require that The most recent push must be approved by someone other than the last pusher. Defaults to `false` ### Restrictions From ec4ded4fbdb50b93194ae4c95d9fb53e75e91c9e Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Tue, 21 Nov 2023 14:24:01 -0800 Subject: [PATCH 2/5] Update github/resource_github_branch_protection_v3.go --- github/resource_github_branch_protection_v3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/resource_github_branch_protection_v3.go b/github/resource_github_branch_protection_v3.go index 61680f3e83..39456688c0 100644 --- a/github/resource_github_branch_protection_v3.go +++ b/github/resource_github_branch_protection_v3.go @@ -132,7 +132,7 @@ func resourceGithubBranchProtectionV3() *schema.Resource { Type: schema.TypeBool, Optional: true, Default: false, - Description: "Require that The most recent push must be approved by someone other than the last pusher.", + Description: "Require that the most recent push must be approved by someone other than the last pusher.", }, "bypass_pull_request_allowances": { Type: schema.TypeList, From dd87fc0baa6623ddf00b9f4911c995a62b467598 Mon Sep 17 00:00:00 2001 From: Keegan Campbell Date: Tue, 21 Nov 2023 14:24:07 -0800 Subject: [PATCH 3/5] Update website/docs/r/branch_protection_v3.html.markdown --- website/docs/r/branch_protection_v3.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/branch_protection_v3.html.markdown b/website/docs/r/branch_protection_v3.html.markdown index 5c54aa11d7..7e5556e2c3 100644 --- a/website/docs/r/branch_protection_v3.html.markdown +++ b/website/docs/r/branch_protection_v3.html.markdown @@ -112,7 +112,7 @@ The following arguments are supported: * `require_code_owner_reviews`: (Optional) Require an approved review in pull requests including files with a designated code owner. Defaults to `false`. * `required_approving_review_count`: (Optional) Require x number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6. This requirement matches GitHub's API, see the upstream [documentation](https://developer.github.com/v3/repos/branches/#parameters-1) for more information. * `bypass_pull_request_allowances`: (Optional) Allow specific users, teams, or apps to bypass pull request requirements. See [Bypass Pull Request Allowances](#bypass-pull-request-allowances) below for details. -* `require_last_push_approval`: (Optional) Require that The most recent push must be approved by someone other than the last pusher. Defaults to `false` +* `require_last_push_approval`: (Optional) Require that the most recent push must be approved by someone other than the last pusher. Defaults to `false` ### Restrictions From f305b05d8e36552a428881bc2f20ff132f1b554d Mon Sep 17 00:00:00 2001 From: Matthew Costa Date: Fri, 24 Nov 2023 13:33:53 +0000 Subject: [PATCH 4/5] Use local var to capture RequireLastPushApproval value, and pass it to the containing struct as a reference --- github/resource_github_branch_protection_v3_utils.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github/resource_github_branch_protection_v3_utils.go b/github/resource_github_branch_protection_v3_utils.go index 87d4d46f61..39010c3d30 100644 --- a/github/resource_github_branch_protection_v3_utils.go +++ b/github/resource_github_branch_protection_v3_utils.go @@ -351,7 +351,8 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool) rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool) rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int) - *rprr.RequireLastPushApproval = m["require_last_push_approval"].(bool) + requireLastPushApproval := m["require_last_push_approval"].(bool) + rprr.RequireLastPushApproval = &requireLastPushApproval rprr.BypassPullRequestAllowancesRequest = bpra } From 9cafcf9d3f8da3dff1a6c0787c96c69a5d15559e Mon Sep 17 00:00:00 2001 From: georgekaz <1391828+georgekaz@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:27:52 +0000 Subject: [PATCH 5/5] Add missing property read --- github/resource_github_branch_protection_v3_utils.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/resource_github_branch_protection_v3_utils.go b/github/resource_github_branch_protection_v3_utils.go index 39010c3d30..978b8f8c5e 100644 --- a/github/resource_github_branch_protection_v3_utils.go +++ b/github/resource_github_branch_protection_v3_utils.go @@ -195,6 +195,7 @@ func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection "dismissal_teams": schema.NewSet(schema.HashString, teams), "dismissal_apps": schema.NewSet(schema.HashString, apps), "require_code_owner_reviews": rprr.RequireCodeOwnerReviews, + "require_last_push_approval": rprr.RequireLastPushApproval, "required_approving_review_count": rprr.RequiredApprovingReviewCount, "bypass_pull_request_allowances": bpra, },