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 require_linear_history on github_branch_protection resource #887

Merged
merged 3 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ func resourceGithubBranchProtection() *schema.Resource {
Optional: true,
Default: false,
},
PROTECTION_REQUIRES_LINEAR_HISTORY: {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
PROTECTION_REQUIRES_APPROVING_REVIEWS: {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -217,6 +222,11 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{}
log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_REQUIRES_COMMIT_SIGNATURES, protection.Repository.Name, protection.Pattern, d.Id())
}

err = d.Set(PROTECTION_REQUIRES_LINEAR_HISTORY, protection.RequiresLinearHistory)
if err != nil {
log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_REQUIRES_LINEAR_HISTORY, protection.Repository.Name, protection.Pattern, d.Id())
}

approvingReviews := setApprovingReviews(protection)
err = d.Set(PROTECTION_REQUIRES_APPROVING_REVIEWS, approvingReviews)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type BranchProtectionRule struct {
RequiresApprovingReviews githubv4.Boolean
RequiresCodeOwnerReviews githubv4.Boolean
RequiresCommitSignatures githubv4.Boolean
RequiresLinearHistory githubv4.Boolean
RequiresStatusChecks githubv4.Boolean
RequiresStrictStatusChecks githubv4.Boolean
RestrictsPushes githubv4.Boolean
Expand All @@ -70,6 +71,7 @@ type BranchProtectionResourceData struct {
RequiresApprovingReviews bool
RequiresCodeOwnerReviews bool
RequiresCommitSignatures bool
RequiresLinearHistory bool
RequiresStatusChecks bool
RequiresStrictStatusChecks bool
RestrictsPushes bool
Expand Down Expand Up @@ -108,6 +110,10 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra
data.RequiresCommitSignatures = v.(bool)
}

if v, ok := d.GetOk(PROTECTION_REQUIRES_LINEAR_HISTORY); ok {
data.RequiresLinearHistory = v.(bool)
}

if v, ok := d.GetOk(PROTECTION_REQUIRES_APPROVING_REVIEWS); ok {
vL := v.([]interface{})
if len(vL) > 1 {
Expand Down
1 change: 1 addition & 0 deletions github/util_v4_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const (
PROTECTION_REQUIRES_APPROVING_REVIEWS = "required_pull_request_reviews"
PROTECTION_REQUIRES_CODE_OWNER_REVIEWS = "require_code_owner_reviews"
PROTECTION_REQUIRES_COMMIT_SIGNATURES = "require_signed_commits"
PROTECTION_REQUIRES_LINEAR_HISTORY = "required_linear_history"
PROTECTION_REQUIRES_STATUS_CHECKS = "required_status_checks"
PROTECTION_REQUIRES_STRICT_STATUS_CHECKS = "strict"
PROTECTION_RESTRICTS_PUSHES = "push_restrictions"
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/branch_protection_v3.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The following arguments are supported:
* `branch` - (Required) The Git branch to protect.
* `enforce_admins` - (Optional) Boolean, setting this to `true` enforces status checks for repository administrators.
* `require_signed_commits` - (Optional) Boolean, setting this to `true` requires all commits to be signed with GPG.
* `required_linear_history` - (Optional) Boolean, setting this to `true` enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch
charlie-collard marked this conversation as resolved.
Show resolved Hide resolved
* `required_status_checks` - (Optional) Enforce restrictions for required status checks. See [Required Status Checks](#required-status-checks) below for details.
* `required_pull_request_reviews` - (Optional) Enforce restrictions for pull request reviews. See [Required Pull Request Reviews](#required-pull-request-reviews) below for details.
* `restrictions` - (Optional) Enforce restrictions for the users and teams that may push to the branch. See [Restrictions](#restrictions) below for details.
Expand Down