Skip to content

Commit c7bc8af

Browse files
committed
feat: add excluded_team_member_node_ids support to team settings
- Add excluded_team_member_node_ids field to review_request_delegation - Allow teams to exclude specific members from PR review assignments - Update schema with proper validation and documentation - Add comprehensive test coverage for the new functionality - Update documentation with usage examples Resolves #1972
1 parent 8359c39 commit c7bc8af

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

github/resource_github_team_settings.go

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ func resourceGithubTeamSettings() *schema.Resource {
8383
Default: false,
8484
Description: "whether to notify the entire team when at least one member is also assigned to the pull request.",
8585
},
86+
"excluded_team_member_node_ids": {
87+
Type: schema.TypeSet,
88+
Optional: true,
89+
Description: "A list of team member node IDs to exclude from the PR review process.",
90+
Elem: &schema.Schema{
91+
Type: schema.TypeString,
92+
},
93+
},
8694
},
8795
},
8896
},
@@ -151,6 +159,9 @@ func resourceGithubTeamSettingsRead(d *schema.ResourceData, meta any) error {
151159
return err
152160
}
153161
}
162+
// NOTE: The exclusion list is not available via the GraphQL read query yet.
163+
// The excluded_team_member_node_ids field can be set but cannot be read back from the GitHub API.
164+
// This is because the GraphQL API for team review assignments is currently in preview.
154165

155166
return nil
156167
}
@@ -177,12 +188,22 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta any) error {
177188
} `graphql:"updateTeamReviewAssignment(input:$input)"`
178189
}
179190

191+
exclusionList := make([]string, 0)
192+
if excludedIDs, ok := settings["excluded_team_member_node_ids"]; ok && excludedIDs != nil {
193+
for _, v := range excludedIDs.(*schema.Set).List() {
194+
if v != nil {
195+
exclusionList = append(exclusionList, v.(string))
196+
}
197+
}
198+
}
199+
180200
return graphql.Mutate(ctx, &mutation, UpdateTeamReviewAssignmentInput{
181201
TeamID: d.Id(),
182202
ReviewRequestDelegation: true,
183203
ReviewRequestDelegationAlgorithm: settings["algorithm"].(string),
184204
ReviewRequestDelegationCount: settings["member_count"].(int),
185205
ReviewRequestDelegationNotifyAll: settings["notify"].(bool),
206+
ExcludedTeamMemberIds: exclusionList,
186207
}, nil)
187208
}
188209
}
@@ -252,12 +273,13 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId,
252273
}
253274

254275
type UpdateTeamReviewAssignmentInput struct {
255-
ClientMutationID string `json:"clientMutationId,omitempty"`
256-
TeamID string `graphql:"id" json:"id"`
257-
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
258-
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
259-
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
260-
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
276+
ClientMutationID string `json:"clientMutationId,omitempty"`
277+
TeamID string `graphql:"id" json:"id"`
278+
ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"`
279+
ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"`
280+
ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"`
281+
ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"`
282+
ExcludedTeamMemberIds []string `graphql:"excludedTeamMemberIds" json:"excludedTeamMemberIds"`
261283
}
262284

263285
func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput {

github/resource_github_team_settings_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,49 @@ func TestAccGithubTeamSettings(t *testing.T) {
123123
})
124124
})
125125

126+
t.Run("manages team code review settings with excluded members", func(t *testing.T) {
127+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
128+
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
129+
config := fmt.Sprintf(`
130+
resource "github_team" "test" {
131+
name = "%s"
132+
description = "generated by terraform provider automated testing"
133+
}
134+
135+
resource "github_team_settings" "test" {
136+
team_id = "${github_team.test.id}"
137+
review_request_delegation {
138+
algorithm = "ROUND_ROBIN"
139+
member_count = 1
140+
notify = true
141+
excluded_team_member_node_ids = ["MDQ6VXNlcjU4MzIzMQ==", "MDQ6VXNlcjU4MzIzMg=="]
142+
}
143+
}
144+
`, teamName)
145+
146+
check := resource.ComposeTestCheckFunc(
147+
resource.TestCheckResourceAttr(
148+
"github_team_settings.test", "review_request_delegation.0.algorithm",
149+
"ROUND_ROBIN",
150+
),
151+
resource.TestCheckResourceAttr(
152+
"github_team_settings.test", "review_request_delegation.0.excluded_team_member_node_ids.#",
153+
"2",
154+
),
155+
)
156+
157+
resource.Test(t, resource.TestCase{
158+
PreCheck: func() { skipUnlessHasOrgs(t) },
159+
ProviderFactories: providerFactories,
160+
Steps: []resource.TestStep{
161+
{
162+
Config: config,
163+
Check: check,
164+
},
165+
},
166+
})
167+
})
168+
126169
t.Run("cannot manage team code review settings if disabled", func(t *testing.T) {
127170
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
128171
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)

website/docs/r/team_settings.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ resource "github_team_settings" "code_review_settings" {
3030
algorithm = "ROUND_ROBIN"
3131
member_count = 1
3232
notify = true
33+
excluded_team_member_node_ids = ["MDQ6VXNlcjU4MzIzMQ=="]
3334
}
3435
}
3536
```
@@ -48,6 +49,7 @@ The following arguments are supported:
4849
* `algorithm` - (Optional) The algorithm to use when assigning pull requests to team members. Supported values are `ROUND_ROBIN` and `LOAD_BALANCE`. Default value is `ROUND_ROBIN`
4950
* `member_count` - (Optional) The number of team members to assign to a pull request
5051
* `notify` - (Optional) whether to notify the entire team when at least one member is also assigned to the pull request
52+
* `excluded_team_member_node_ids` - (Optional) A list of team member node IDs to exclude from the PR review process. These are GitHub user node IDs that can be obtained from the GitHub GraphQL API.
5153

5254

5355
## Import

0 commit comments

Comments
 (0)