Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/resources/repository_ruleset.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,9 @@ The `rules` block supports the following:

#### bypass_actors

- `actor_id` - (Optional) (Number) The ID of the actor that can bypass a ruleset. If `actor_type` is `Integration`, `actor_id` is a GitHub App ID. App ID can be obtained by following instructions from the [Get an App API docs](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-app). Some actor types such as `DeployKey` do not have an ID.
- `actor_id` - (Optional) (Number) The ID of the actor that can bypass a ruleset. If `actor_type` is `Integration`, `actor_id` is a GitHub App ID. App ID can be obtained by following instructions from the [Get an App API docs](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-app). If `actor_type` is `User`, `actor_id` is the numeric GitHub user ID. Some actor types such as `DeployKey` do not have an ID.

- `actor_type` (String) The type of actor that can bypass a ruleset. Can be one of: `RepositoryRole`, `Team`, `Integration`, `OrganizationAdmin`, `DeployKey`.
- `actor_type` (String) The type of actor that can bypass a ruleset. Can be one of: `RepositoryRole`, `Team`, `Integration`, `OrganizationAdmin`, `DeployKey`, `User`.

- `bypass_mode` - (Optional) (String) When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. Can be one of: `always`, `pull_request`, `exempt`.

Expand All @@ -309,6 +309,7 @@ The `rules` block supports the following:
- `maintain` -> `2`
- `write` -> `4`
- `admin` -> `5`
- `User` -> the numeric GitHub user ID

#### conditions

Expand Down
6 changes: 3 additions & 3 deletions github/resource_github_repository_ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Default: nil,
Description: "The ID of the actor that can bypass a ruleset. When `actor_type` is `OrganizationAdmin`, this should be set to `1`. Some resources such as DeployKey do not have an ID and this should be omitted.",
Description: "The ID of the actor that can bypass a ruleset. When `actor_type` is `OrganizationAdmin`, this should be set to `1`. When `actor_type` is `User`, this should be set to the numeric GitHub user ID. Some resources such as DeployKey do not have an ID and this should be omitted.",
},
"actor_type": {
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey"}, false)),
Description: "The type of actor that can bypass a ruleset. See https://docs.github.com/en/rest/repos/rules for more information.",
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey", "User"}, false)),
Description: "The type of actor that can bypass a ruleset. Can be one of: `RepositoryRole`, `Team`, `Integration`, `OrganizationAdmin`, `DeployKey`, or `User`. See https://docs.github.com/en/rest/repos/rules for more information.",
},
"bypass_mode": {
Type: schema.TypeString,
Expand Down
17 changes: 15 additions & 2 deletions github/resource_github_repository_ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ resource "github_repository_environment" "example" {
repository = github_repository.test.name
}

data "github_user" "current" {
username = "%[3]s"
}

resource "github_repository_ruleset" "test" {
name = "test"
repository = github_repository.test.id
Expand All @@ -46,6 +50,12 @@ resource "github_repository_ruleset" "test" {
bypass_mode = "always"
}

bypass_actors {
actor_id = tonumber(data.github_user.current.id)
actor_type = "User"
bypass_mode = "always"
}

conditions {
ref_name {
include = ["refs/heads/main"]
Expand Down Expand Up @@ -113,7 +123,7 @@ resource "github_repository_ruleset" "test" {
non_fast_forward = true
}
}
`, repoName, testAccConf.testRepositoryVisibility)
`, repoName, testAccConf.testRepositoryVisibility, testAccConf.username)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnauthenticated(t) },
Expand All @@ -125,12 +135,15 @@ resource "github_repository_ruleset" "test" {
resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", "test"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "target", "branch"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "enforcement", "active"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.#", "2"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.#", "3"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.actor_type", "DeployKey"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", "always"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_id", "5"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_type", "RepositoryRole"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.bypass_mode", "always"),
resource.TestCheckResourceAttrPair("github_repository_ruleset.test", "bypass_actors.2.actor_id", "data.github_user.current", "id"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.2.actor_type", "User"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.2.bypass_mode", "always"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.pull_request.0.allowed_merge_methods.#", "2"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.required_code_scanning.0.required_code_scanning_tool.0.alerts_threshold", "errors"),
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.required_code_scanning.0.required_code_scanning_tool.0.security_alerts_threshold", "high_or_higher"),
Expand Down
5 changes: 3 additions & 2 deletions templates/resources/repository_ruleset.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ The `rules` block supports the following:

#### bypass_actors

- `actor_id` - (Optional) (Number) The ID of the actor that can bypass a ruleset. If `actor_type` is `Integration`, `actor_id` is a GitHub App ID. App ID can be obtained by following instructions from the [Get an App API docs](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-app). Some actor types such as `DeployKey` do not have an ID.
- `actor_id` - (Optional) (Number) The ID of the actor that can bypass a ruleset. If `actor_type` is `Integration`, `actor_id` is a GitHub App ID. App ID can be obtained by following instructions from the [Get an App API docs](https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-app). If `actor_type` is `User`, `actor_id` is the numeric GitHub user ID. Some actor types such as `DeployKey` do not have an ID.

- `actor_type` (String) The type of actor that can bypass a ruleset. Can be one of: `RepositoryRole`, `Team`, `Integration`, `OrganizationAdmin`, `DeployKey`.
- `actor_type` (String) The type of actor that can bypass a ruleset. Can be one of: `RepositoryRole`, `Team`, `Integration`, `OrganizationAdmin`, `DeployKey`, `User`.

- `bypass_mode` - (Optional) (String) When the specified actor can bypass the ruleset. pull_request means that an actor can only bypass rules on pull requests. Can be one of: `always`, `pull_request`, `exempt`.

Expand All @@ -238,6 +238,7 @@ The `rules` block supports the following:
- `maintain` -> `2`
- `write` -> `4`
- `admin` -> `5`
- `User` -> the numeric GitHub user ID

#### conditions

Expand Down