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 Nov 3, 2023
1 parent 1741133 commit 0428f3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 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 @@ -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,
Expand Down Expand Up @@ -162,6 +167,8 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf
"users": users,
},
})

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

Check failure on line 171 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / ci

pr.PreventSelfReview undefined (type *"github.com/google/go-github/v55/github".ProtectionRule has no field or method PreventSelfReview)

Check failure on line 171 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / ci

pr.PreventSelfReview undefined (type *"github.com/google/go-github/v55/github".ProtectionRule has no field or method PreventSelfReview)

Check failure on line 171 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

pr.PreventSelfReview undefined (type *"github.com/google/go-github/v55/github".ProtectionRule has no field or method PreventSelfReview)
}
}

Expand Down Expand Up @@ -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))

Check failure on line 234 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / ci

data.PreventSelfReview undefined (type "github.com/google/go-github/v55/github".CreateUpdateEnvironment has no field or method PreventSelfReview)) (typecheck)

Check failure on line 234 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / ci

data.PreventSelfReview undefined (type "github.com/google/go-github/v55/github".CreateUpdateEnvironment has no field or method PreventSelfReview) (typecheck)

Check failure on line 234 in github/resource_github_repository_environment.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

data.PreventSelfReview undefined (type "github.com/google/go-github/v55/github".CreateUpdateEnvironment has no field or method PreventSelfReview)
}

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

Expand Down
7 changes: 4 additions & 3 deletions github/resource_github_repository_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
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 @@ -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:
Expand Down

0 comments on commit 0428f3b

Please sign in to comment.