Skip to content

Commit

Permalink
Added allowsDeletionsand allowsForcePushessettings https://develo…
Browse files Browse the repository at this point in the history
  • Loading branch information
frbayart committed Dec 6, 2020
1 parent f6add3e commit cad2db0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
24 changes: 24 additions & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)),
Expand Down
12 changes: 12 additions & 0 deletions github/util_v4_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +49,8 @@ type BranchProtectionRule struct {
}

type BranchProtectionResourceData struct {
AllowsDeletions bool
AllowsForcePushes bool
BranchProtectionRuleID string
DismissesStaleReviews bool
IsAdminEnforced bool
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions github/util_v4_consts.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit cad2db0

Please sign in to comment.