Skip to content

Commit 3b41f21

Browse files
committed
Add prevent_self_review parameter to the github_repository_environment resource
1 parent 5752b25 commit 3b41f21

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

github/resource_github_repository_environment.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func resourceGithubRepositoryEnvironment() *schema.Resource {
3939
Default: true,
4040
Description: "Can Admins bypass deployment protections",
4141
},
42+
"prevent_self_review": {
43+
Type: schema.TypeBool,
44+
Optional: true,
45+
Default: false,
46+
Description: "Prevent users from approving workflows runs that they triggered.",
47+
},
4248
"wait_timer": {
4349
Type: schema.TypeInt,
4450
Optional: true,
@@ -170,6 +176,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf
170176
"users": users,
171177
},
172178
})
179+
180+
d.Set("prevent_self_review", pr.PreventSelfReview)
173181
}
174182
}
175183

@@ -233,6 +241,8 @@ func createUpdateEnvironmentData(d *schema.ResourceData, meta interface{}) githu
233241

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

244+
data.PreventSelfReview = github.Bool(d.Get("prevent_self_review").(bool))
245+
236246
if v, ok := d.GetOk("reviewers"); ok {
237247
envReviewers := make([]*github.EnvReviewers, 0)
238248

github/resource_github_repository_environment_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
3030
environment = "environment / test"
3131
can_admins_bypass = false
3232
wait_timer = 10000
33+
prevent_self_review = true
3334
reviewers {
3435
users = [data.github_user.current.id]
3536
}
@@ -44,6 +45,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
4445
check := resource.ComposeAggregateTestCheckFunc(
4546
resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment / test"),
4647
resource.TestCheckResourceAttr("github_repository_environment.test", "can_admins_bypass", "false"),
48+
resource.TestCheckResourceAttr("github_repository_environment.test", "prevent_self_review", "true"),
4749
resource.TestCheckResourceAttr("github_repository_environment.test", "wait_timer", "10000"),
4850
)
4951

website/docs/r/repository_environment.html.markdown

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ data "github_user" "current" {
1717
}
1818
1919
resource "github_repository" "example" {
20-
name = "A Repository Project"
21-
description = "My awesome codebase"
20+
name = "A Repository Project"
21+
description = "My awesome codebase"
2222
}
2323
2424
resource "github_repository_environment" "example" {
25-
environment = "example"
26-
repository = github_repository.example.name
25+
environment = "example"
26+
repository = github_repository.example.name
27+
prevent_self_review = true
2728
reviewers {
2829
users = [data.github_user.current.id]
2930
}
3031
deployment_branch_policy {
31-
protected_branches = true
32+
protected_branches = true
3233
custom_branch_policies = false
3334
}
3435
}
@@ -46,6 +47,8 @@ The following arguments are supported:
4647

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

50+
* `prevent_self_review` - (Optional) Whether or not a user who created the job is prevented from approving their own job. Defaults to `false`.
51+
4952
### Reviewers
5053

5154
The `reviewers` block supports the following:

0 commit comments

Comments
 (0)