Skip to content

Commit 84e8d55

Browse files
georgekazmatthewcostatidekfcampbell
authored
Feat: Fixes abandoned PR #2017: Add support for the require_last_push_approval flag in github_branch_protection_v3 (#2199)
* Add the require_last_push_approval flag as an option for the required_pull_request_reviews of github_branch_protection_v3 * Update github/resource_github_branch_protection_v3.go * Update website/docs/r/branch_protection_v3.html.markdown * Use local var to capture RequireLastPushApproval value, and pass it to the containing struct as a reference * Add missing property read --------- Co-authored-by: Matthew Costa <[email protected]> Co-authored-by: Keegan Campbell <[email protected]> Co-authored-by: Matthew Costa <[email protected]>
1 parent b1243e4 commit 84e8d55

4 files changed

+14
-0
lines changed

github/resource_github_branch_protection_v3.go

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func resourceGithubBranchProtectionV3() *schema.Resource {
128128
Description: "Require 'x' number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 0-6.",
129129
ValidateDiagFunc: toDiagFunc(validation.IntBetween(0, 6), "required_approving_review_count"),
130130
},
131+
"require_last_push_approval": {
132+
Type: schema.TypeBool,
133+
Optional: true,
134+
Default: false,
135+
Description: "Require that the most recent push must be approved by someone other than the last pusher.",
136+
},
131137
"bypass_pull_request_allowances": {
132138
Type: schema.TypeList,
133139
Optional: true,

github/resource_github_branch_protection_v3_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T)
320320
dismiss_stale_reviews = true
321321
require_code_owner_reviews = true
322322
required_approving_review_count = 1
323+
require_last_push_approval = true
323324
dismissal_users = ["a"]
324325
dismissal_teams = ["b"]
325326
dismissal_apps = ["c"]
@@ -347,6 +348,9 @@ func TestAccGithubBranchProtectionV3_required_pull_request_reviews(t *testing.T)
347348
resource.TestCheckResourceAttr(
348349
"github_branch_protection_v3.test", "required_pull_request_reviews.0.required_approving_review_count", "1",
349350
),
351+
resource.TestCheckResourceAttr(
352+
"github_branch_protection_v3.test", "required_pull_request_reviews.0.require_last_push_approval", "true",
353+
),
350354
resource.TestCheckResourceAttr(
351355
"github_branch_protection_v3.test", "required_pull_request_reviews.0.dismissal_users.#", "1",
352356
),

github/resource_github_branch_protection_v3_utils.go

+3
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func flattenAndSetRequiredPullRequestReviews(d *schema.ResourceData, protection
195195
"dismissal_teams": schema.NewSet(schema.HashString, teams),
196196
"dismissal_apps": schema.NewSet(schema.HashString, apps),
197197
"require_code_owner_reviews": rprr.RequireCodeOwnerReviews,
198+
"require_last_push_approval": rprr.RequireLastPushApproval,
198199
"required_approving_review_count": rprr.RequiredApprovingReviewCount,
199200
"bypass_pull_request_allowances": bpra,
200201
},
@@ -351,6 +352,8 @@ func expandRequiredPullRequestReviews(d *schema.ResourceData) (*github.PullReque
351352
rprr.DismissStaleReviews = m["dismiss_stale_reviews"].(bool)
352353
rprr.RequireCodeOwnerReviews = m["require_code_owner_reviews"].(bool)
353354
rprr.RequiredApprovingReviewCount = m["required_approving_review_count"].(int)
355+
requireLastPushApproval := m["require_last_push_approval"].(bool)
356+
rprr.RequireLastPushApproval = &requireLastPushApproval
354357
rprr.BypassPullRequestAllowancesRequest = bpra
355358
}
356359

website/docs/r/branch_protection_v3.html.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ For workflows that use reusable workflows, the pattern is `<initial_workflow.job
118118
* `require_code_owner_reviews`: (Optional) Require an approved review in pull requests including files with a designated code owner. Defaults to `false`.
119119
* `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.
120120
* `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.
121+
* `require_last_push_approval`: (Optional) Require that the most recent push must be approved by someone other than the last pusher. Defaults to `false`
121122

122123
### Restrictions
123124

0 commit comments

Comments
 (0)