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

Add restrict_dismissals on github_branch_protection resource #839

Merged
merged 1 commit into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ func resourceGithubBranchProtection() *schema.Resource {
Optional: true,
},
PROTECTION_RESTRICTS_REVIEW_DISMISSALS: {
Type: schema.TypeBool,
Optional: true,
},
PROTECTION_RESTRICTS_REVIEW_DISMISSERS: {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down
6 changes: 5 additions & 1 deletion github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra
data.RequiresCodeOwnerReviews = v.(bool)
}
if v, ok := m[PROTECTION_RESTRICTS_REVIEW_DISMISSALS]; ok {
data.RestrictsReviewDismissals = v.(bool)
}
if v, ok := m[PROTECTION_RESTRICTS_REVIEW_DISMISSERS]; ok {
reviewDismissalActorIDs := make([]string, 0)
vL := v.(*schema.Set).List()
for _, v := range vL {
Expand Down Expand Up @@ -226,7 +229,8 @@ func setApprovingReviews(protection BranchProtectionRule) interface{} {
PROTECTION_REQUIRED_APPROVING_REVIEW_COUNT: protection.RequiredApprovingReviewCount,
PROTECTION_REQUIRES_CODE_OWNER_REVIEWS: protection.RequiresCodeOwnerReviews,
PROTECTION_DISMISSES_STALE_REVIEWS: protection.DismissesStaleReviews,
PROTECTION_RESTRICTS_REVIEW_DISMISSALS: dismissalActors,
PROTECTION_RESTRICTS_REVIEW_DISMISSALS: protection.RestrictsReviewDismissals,
PROTECTION_RESTRICTS_REVIEW_DISMISSERS: dismissalActors,
},
}

Expand Down
3 changes: 2 additions & 1 deletion github/util_v4_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const (
PROTECTION_REQUIRES_STATUS_CHECKS = "required_status_checks"
PROTECTION_REQUIRES_STRICT_STATUS_CHECKS = "strict"
PROTECTION_RESTRICTS_PUSHES = "push_restrictions"
PROTECTION_RESTRICTS_REVIEW_DISMISSALS = "dismissal_restrictions"
PROTECTION_RESTRICTS_REVIEW_DISMISSALS = "restrict_dismissals"
PROTECTION_RESTRICTS_REVIEW_DISMISSERS = "dismissal_restrictions"

REPOSITORY_ID = "repository_id"
)
6 changes: 4 additions & 2 deletions website/docs/r/branch_protection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ resource "github_branch_protection" "example" {
}

required_pull_request_reviews {
dismiss_stale_reviews = true
dismiss_stale_reviews = true
restrict_dismissals = true
dismissal_restrictions = [
data.github_user.example.node_id,
github_team.example.node_id,
Expand Down Expand Up @@ -93,7 +94,8 @@ The following arguments are supported:
`required_pull_request_reviews` supports the following arguments:

* `dismiss_stale_reviews`: (Optional) Dismiss approved reviews automatically when a new commit is pushed. Defaults to `false`.
* `dismissal_restrictions`: (Optional) The list of actor IDs with dismissal access.
* `restrict_dismissals`: (Optional) Restrict pull request review dismissals.
* `dismissal_restrictions`: (Optional) The list of actor IDs with dismissal access. If not empty, `restrict_dismissals` is ignored.
* `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 1-6. This requirement matches GitHub's API, see the upstream [documentation](https://developer.github.com/v3/repos/branches/#parameters-1) for more information.

Expand Down