diff --git a/github/resource_github_branch_protection.go b/github/resource_github_branch_protection.go index f5b784fe62..8d59ebce23 100644 --- a/github/resource_github_branch_protection.go +++ b/github/resource_github_branch_protection.go @@ -28,6 +28,16 @@ func resourceGithubBranchProtection() *schema.Resource { Required: true, Description: "", }, + PROTECTION_ALLOWS_DELETIONS: { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + PROTECTION_ALLOWS_FORCE_PUSHES: { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, PROTECTION_IS_ADMIN_ENFORCED: { Type: schema.TypeBool, Optional: true, @@ -121,6 +131,8 @@ func resourceGithubBranchProtectionCreate(d *schema.ResourceData, meta interface return err } input := githubv4.CreateBranchProtectionRuleInput{ + AllowsDeletions: githubv4.NewBoolean(githubv4.Boolean(data.AllowsDeletions)), + AllowsForcePushes: githubv4.NewBoolean(githubv4.Boolean(data.AllowsForcePushes)), DismissesStaleReviews: githubv4.NewBoolean(githubv4.Boolean(data.DismissesStaleReviews)), IsAdminEnforced: githubv4.NewBoolean(githubv4.Boolean(data.IsAdminEnforced)), Pattern: githubv4.String(data.Pattern), @@ -180,6 +192,16 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{} log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_PATTERN, protection.Repository.Name, protection.Pattern, d.Id()) } + err = d.Set(PROTECTION_ALLOWS_DELETIONS, protection.AllowsDeletions) + if err != nil { + log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_ALLOWS_DELETIONS, protection.Repository.Name, protection.Pattern, d.Id()) + } + + err = d.Set(PROTECTION_ALLOWS_FORCE_PUSHES, protection.AllowsForcePushes) + if err != nil { + log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_ALLOWS_FORCE_PUSHES, protection.Repository.Name, protection.Pattern, d.Id()) + } + err = d.Set(PROTECTION_IS_ADMIN_ENFORCED, protection.IsAdminEnforced) if err != nil { log.Printf("[WARN] Problem setting '%s' in %s %s branch protection (%s)", PROTECTION_IS_ADMIN_ENFORCED, protection.Repository.Name, protection.Pattern, d.Id()) @@ -225,6 +247,8 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta interface } input := githubv4.UpdateBranchProtectionRuleInput{ BranchProtectionRuleID: d.Id(), + AllowsDeletions: githubv4.NewBoolean(githubv4.Boolean(data.AllowsDeletions)), + AllowsForcePushes: githubv4.NewBoolean(githubv4.Boolean(data.AllowsForcePushes)), DismissesStaleReviews: githubv4.NewBoolean(githubv4.Boolean(data.DismissesStaleReviews)), IsAdminEnforced: githubv4.NewBoolean(githubv4.Boolean(data.IsAdminEnforced)), Pattern: githubv4.NewString(githubv4.String(data.Pattern)), diff --git a/github/util_v4_branch_protection.go b/github/util_v4_branch_protection.go index 55e7fed398..44cf114da7 100644 --- a/github/util_v4_branch_protection.go +++ b/github/util_v4_branch_protection.go @@ -31,6 +31,8 @@ type BranchProtectionRule struct { ReviewDismissalAllowances struct { Nodes []ActorTypes } `graphql:"reviewDismissalAllowances(first: 100)"` + AllowsDeletions githubv4.Boolean + AllowsForcePushes githubv4.Boolean DismissesStaleReviews githubv4.Boolean ID githubv4.ID IsAdminEnforced githubv4.Boolean @@ -47,6 +49,8 @@ type BranchProtectionRule struct { } type BranchProtectionResourceData struct { + AllowsDeletions bool + AllowsForcePushes bool BranchProtectionRuleID string DismissesStaleReviews bool IsAdminEnforced bool @@ -80,6 +84,14 @@ func branchProtectionResourceData(d *schema.ResourceData, meta interface{}) (Bra data.Pattern = v.(string) } + if v, ok := d.GetOk(PROTECTION_ALLOWS_DELETIONS); ok { + data.AllowsDeletions = v.(bool) + } + + if v, ok := d.GetOk(PROTECTION_ALLOWS_FORCE_PUSHES); ok { + data.AllowsForcePushes = v.(bool) + } + if v, ok := d.GetOk(PROTECTION_IS_ADMIN_ENFORCED); ok { data.IsAdminEnforced = v.(bool) } diff --git a/github/util_v4_consts.go b/github/util_v4_consts.go index adfe74585c..fc8a967b2f 100644 --- a/github/util_v4_consts.go +++ b/github/util_v4_consts.go @@ -1,6 +1,8 @@ package github const ( + PROTECTION_ALLOWS_DELETIONS = "allows_deletions" + PROTECTION_ALLOWS_FORCE_PUSHES = "allows_force_pushes" PROTECTION_DISMISSES_STALE_REVIEWS = "dismiss_stale_reviews" PROTECTION_IS_ADMIN_ENFORCED = "enforce_admins" PROTECTION_PATTERN = "pattern"