Skip to content

Commit

Permalink
Add prevent_self_review parameter to the github_repository_environmen…
Browse files Browse the repository at this point in the history
…t resource
  • Loading branch information
Nmishin committed Jan 9, 2024
1 parent 5752b25 commit baa92ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions github/resource_github_repository_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func resourceGithubRepositoryEnvironment() *schema.Resource {
Default: true,
Description: "Can Admins bypass deployment protections",
},
"prevent_self_review": {
Type: schema.TypeBool,
Optional: true,
Description: "Prevent users from approving workflows runs that they triggered.",
},
"wait_timer": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -170,6 +175,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf
"users": users,
},
})

d.Set("prevent_self_review", pr.PreventSelfReview)
}
}

Expand Down Expand Up @@ -233,6 +240,10 @@ func createUpdateEnvironmentData(d *schema.ResourceData, meta interface{}) githu

data.CanAdminsBypass = github.Bool(d.Get("can_admins_bypass").(bool))

if v, ok := d.GetOkExists("prevent_self_review"); ok {

Check failure on line 243 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / ci

SA1019: d.GetOkExists is deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK (staticcheck)
data.PreventSelfReview = github.Bool(v.(bool))
}

if v, ok := d.GetOk("reviewers"); ok {
envReviewers := make([]*github.EnvReviewers, 0)

Expand Down
2 changes: 2 additions & 0 deletions github/resource_github_repository_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
environment = "environment / test"
can_admins_bypass = false
wait_timer = 10000
prevent_self_review = true
reviewers {
users = [data.github_user.current.id]
}
Expand All @@ -44,6 +45,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment / test"),
resource.TestCheckResourceAttr("github_repository_environment.test", "can_admins_bypass", "false"),
resource.TestCheckResourceAttr("github_repository_environment.test", "prevent_self_review", "true"),
resource.TestCheckResourceAttr("github_repository_environment.test", "wait_timer", "10000"),
)

Expand Down
13 changes: 8 additions & 5 deletions website/docs/r/repository_environment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ data "github_user" "current" {
}
resource "github_repository" "example" {
name = "A Repository Project"
description = "My awesome codebase"
name = "A Repository Project"
description = "My awesome codebase"
}
resource "github_repository_environment" "example" {
environment = "example"
repository = github_repository.example.name
environment = "example"
repository = github_repository.example.name
prevent_self_review = true
reviewers {
users = [data.github_user.current.id]
}
deployment_branch_policy {
protected_branches = true
protected_branches = true
custom_branch_policies = false
}
}
Expand All @@ -46,6 +47,8 @@ The following arguments are supported:

* `can_admins_bypass` - (Optional) Can repository admins bypass the environment protections. Defaults to `true`.

* `prevent_self_review` - (Optional) Whether or not a user who created the job is prevented from approving their own job. Defaults to `false`.

### Reviewers

The `reviewers` block supports the following:
Expand Down

0 comments on commit baa92ae

Please sign in to comment.