Skip to content

Commit 2d31318

Browse files
authored
docs: Clarify how allows_force_pushes works
fix doc for #2054: Clarify how allows_force_pushes is working
2 parents 3eb0fbd + 7be79c4 commit 2d31318

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

github/resource_github_branch_protection_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,65 @@ func TestAccGithubBranchProtection(t *testing.T) {
615615

616616
})
617617

618+
t.Run("configures allow force push with a team as bypasser", func(t *testing.T) {
619+
620+
config := fmt.Sprintf(`
621+
622+
resource "github_repository" "test" {
623+
name = "tf-acc-test-%s"
624+
auto_init = true
625+
}
626+
627+
resource "github_team" "test" {
628+
name = "tf-acc-test-%s"
629+
}
630+
631+
resource "github_team_repository" "test" {
632+
team_id = github_team.test.id
633+
repository = github_repository.test.name
634+
permission = "admin"
635+
}
636+
637+
resource "github_branch_protection" "test" {
638+
repository_id = github_repository.test.node_id
639+
pattern = "main"
640+
641+
force_push_bypassers = [
642+
"%s/${github_team.test.slug}"
643+
]
644+
}
645+
646+
`, randomID, randomID, testOrganization)
647+
648+
check := resource.ComposeAggregateTestCheckFunc(
649+
resource.TestCheckResourceAttr(
650+
"github_branch_protection.test", "force_push_bypassers.#", "1",
651+
),
652+
resource.TestCheckResourceAttr(
653+
"github_branch_protection.test", "allows_force_pushes", "false",
654+
),
655+
)
656+
657+
testCase := func(t *testing.T, mode string) {
658+
resource.Test(t, resource.TestCase{
659+
PreCheck: func() { skipUnlessMode(t, mode) },
660+
Providers: testAccProviders,
661+
Steps: []resource.TestStep{
662+
{
663+
Config: config,
664+
Check: check,
665+
},
666+
},
667+
})
668+
}
669+
670+
// This test only works with an organization account
671+
t.Run("with an organization account", func(t *testing.T) {
672+
testCase(t, organization)
673+
})
674+
675+
})
676+
618677
t.Run("configures empty list of force push bypassers", func(t *testing.T) {
619678

620679
config := fmt.Sprintf(`

website/docs/r/branch_protection.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ The following arguments are supported:
9898
* `required_status_checks` - (Optional) Enforce restrictions for required status checks. See [Required Status Checks](#required-status-checks) below for details.
9999
* `required_pull_request_reviews` - (Optional) Enforce restrictions for pull request reviews. See [Required Pull Request Reviews](#required-pull-request-reviews) below for details.
100100
* `push_restrictions` - (Optional) The list of actor Names/IDs that may push to the branch. Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
101-
* `force_push_bypassers` - (Optional) The list of actor Names/IDs that are allowed to bypass force push restrictions. Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
101+
* `force_push_bypassers` - (Optional) The list of actor Names/IDs that are allowed to bypass force push restrictions. Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams. If the list is not empty, `allows_force_pushes` should be set to `false`.
102102
* `allows_deletions` - (Optional) Boolean, setting this to `true` to allow the branch to be deleted.
103-
* `allows_force_pushes` - (Optional) Boolean, setting this to `true` to allow force pushes on the branch.
103+
* `allows_force_pushes` - (Optional) Boolean, setting this to `true` to allow force pushes on the branch to everyone. Set it to `false` if you specify `force_push_bypassers`.
104104
* `blocks_creations` - (Optional) Boolean, setting this to `true` to block creating the branch.
105105
* `lock_branch` - (Optional) Boolean, Setting this to `true` will make the branch read-only and preventing any pushes to it. Defaults to `false`
106106

0 commit comments

Comments
 (0)