From 0428f3b67ea0a253365608803951366a7e133069 Mon Sep 17 00:00:00 2001 From: Nikolai Mishin Date: Fri, 3 Nov 2023 22:36:51 +0100 Subject: [PATCH] Add prevent_self_review parameter to the github_repository_environment resource --- github/resource_github_repository_environment.go | 11 +++++++++++ .../resource_github_repository_environment_test.go | 7 ++++--- website/docs/r/repository_environment.html.markdown | 13 ++++++++----- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/github/resource_github_repository_environment.go b/github/resource_github_repository_environment.go index dc8ba87069..52795de650 100644 --- a/github/resource_github_repository_environment.go +++ b/github/resource_github_repository_environment.go @@ -33,6 +33,11 @@ func resourceGithubRepositoryEnvironment() *schema.Resource { ForceNew: true, Description: "The name of the environment.", }, + "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, @@ -162,6 +167,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf "users": users, }, }) + + d.Set("prevent_self_review", pr.PreventSelfReview) } } @@ -223,6 +230,10 @@ func createUpdateEnvironmentData(d *schema.ResourceData, meta interface{}) githu data.WaitTimer = github.Int(v.(int)) } + if v, ok := d.GetOkExists("prevent_self_review"); ok { + data.PreventSelfReview = github.Bool(v.(bool)) + } + if v, ok := d.GetOk("reviewers"); ok { envReviewers := make([]*github.EnvReviewers, 0) diff --git a/github/resource_github_repository_environment_test.go b/github/resource_github_repository_environment_test.go index 69f5e3ed93..51921af694 100644 --- a/github/resource_github_repository_environment_test.go +++ b/github/resource_github_repository_environment_test.go @@ -25,9 +25,10 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) { } resource "github_repository_environment" "test" { - repository = github_repository.test.name - environment = "environment/test" - wait_timer = 10000 + repository = github_repository.test.name + environment = "environment/test" + wait_timer = 10000 + prevent_self_review = true reviewers { users = [data.github_user.current.id] } diff --git a/website/docs/r/repository_environment.html.markdown b/website/docs/r/repository_environment.html.markdown index 0cdd1e7e80..f95a426eaa 100644 --- a/website/docs/r/repository_environment.html.markdown +++ b/website/docs/r/repository_environment.html.markdown @@ -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 } } @@ -44,6 +45,8 @@ The following arguments are supported: * `wait_timer` - (Optional) Amount of time to delay a job after the job is initially triggered. +* `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: