Skip to content

Commit 5263dc0

Browse files
committed
Add User as repository ruleset bypass actor
1 parent 23f7983 commit 5263dc0

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

docs/resources/repository_ruleset.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ The `rules` block supports the following:
296296

297297
#### bypass_actors
298298

299-
- `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.
299+
- `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.
300300

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

303303
- `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`.
304304

@@ -309,6 +309,7 @@ The `rules` block supports the following:
309309
- `maintain` -> `2`
310310
- `write` -> `4`
311311
- `admin` -> `5`
312+
- `User` -> the numeric GitHub user ID
312313

313314
#### conditions
314315

github/resource_github_repository_ruleset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ func resourceGithubRepositoryRuleset() *schema.Resource {
6868
Type: schema.TypeInt,
6969
Optional: true,
7070
Default: nil,
71-
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.",
71+
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.",
7272
},
7373
"actor_type": {
7474
Type: schema.TypeString,
7575
Required: true,
76-
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey"}, false)),
77-
Description: "The type of actor that can bypass a ruleset. See https://docs.github.com/en/rest/repos/rules for more information.",
76+
ValidateDiagFunc: validation.ToDiagFunc(validation.StringInSlice([]string{"RepositoryRole", "Team", "Integration", "OrganizationAdmin", "DeployKey", "User"}, false)),
77+
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.",
7878
},
7979
"bypass_mode": {
8080
Type: schema.TypeString,

github/resource_github_repository_ruleset_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ resource "github_repository_environment" "example" {
2929
repository = github_repository.test.name
3030
}
3131
32+
data "github_user" "current" {
33+
username = "%[3]s"
34+
}
35+
3236
resource "github_repository_ruleset" "test" {
3337
name = "test"
3438
repository = github_repository.test.id
@@ -46,6 +50,12 @@ resource "github_repository_ruleset" "test" {
4650
bypass_mode = "always"
4751
}
4852
53+
bypass_actors {
54+
actor_id = tonumber(data.github_user.current.id)
55+
actor_type = "User"
56+
bypass_mode = "always"
57+
}
58+
4959
conditions {
5060
ref_name {
5161
include = ["refs/heads/main"]
@@ -113,7 +123,7 @@ resource "github_repository_ruleset" "test" {
113123
non_fast_forward = true
114124
}
115125
}
116-
`, repoName, testAccConf.testRepositoryVisibility)
126+
`, repoName, testAccConf.testRepositoryVisibility, testAccConf.username)
117127

118128
resource.Test(t, resource.TestCase{
119129
PreCheck: func() { skipUnauthenticated(t) },
@@ -125,12 +135,15 @@ resource "github_repository_ruleset" "test" {
125135
resource.TestCheckResourceAttr("github_repository_ruleset.test", "name", "test"),
126136
resource.TestCheckResourceAttr("github_repository_ruleset.test", "target", "branch"),
127137
resource.TestCheckResourceAttr("github_repository_ruleset.test", "enforcement", "active"),
128-
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.#", "2"),
138+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.#", "3"),
129139
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.actor_type", "DeployKey"),
130140
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.0.bypass_mode", "always"),
131141
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_id", "5"),
132142
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.actor_type", "RepositoryRole"),
133143
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.1.bypass_mode", "always"),
144+
resource.TestCheckResourceAttrPair("github_repository_ruleset.test", "bypass_actors.2.actor_id", "data.github_user.current", "id"),
145+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.2.actor_type", "User"),
146+
resource.TestCheckResourceAttr("github_repository_ruleset.test", "bypass_actors.2.bypass_mode", "always"),
134147
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.pull_request.0.allowed_merge_methods.#", "2"),
135148
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.required_code_scanning.0.required_code_scanning_tool.0.alerts_threshold", "errors"),
136149
resource.TestCheckResourceAttr("github_repository_ruleset.test", "rules.0.required_code_scanning.0.required_code_scanning_tool.0.security_alerts_threshold", "high_or_higher"),

templates/resources/repository_ruleset.md.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ The `rules` block supports the following:
225225

226226
#### bypass_actors
227227

228-
- `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.
228+
- `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.
229229

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

232232
- `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`.
233233

@@ -238,6 +238,7 @@ The `rules` block supports the following:
238238
- `maintain` -> `2`
239239
- `write` -> `4`
240240
- `admin` -> `5`
241+
- `User` -> the numeric GitHub user ID
241242

242243
#### conditions
243244

0 commit comments

Comments
 (0)