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

Feat: Add support for the require_last_push_approval flag in github_branch_protection_v3 #2017

6 changes: 6 additions & 0 deletions github/resource_github_branch_protection_v3.go
Expand Up @@ -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.",
kfcampbell marked this conversation as resolved.
Show resolved Hide resolved
},
"bypass_pull_request_allowances": {
Type: schema.TypeList,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions github/resource_github_branch_protection_v3_test.go
Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
),
Expand Down
1 change: 1 addition & 0 deletions github/resource_github_branch_protection_v3_utils.go
Expand Up @@ -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)
matthewcostatide marked this conversation as resolved.
Show resolved Hide resolved
rprr.BypassPullRequestAllowancesRequest = bpra
}

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/branch_protection_v3.html.markdown
Expand Up @@ -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`
kfcampbell marked this conversation as resolved.
Show resolved Hide resolved

### Restrictions

Expand Down