From a09dbdf6147242ecc09d8a22b20f8d0c241486b9 Mon Sep 17 00:00:00 2001 From: felixlut Date: Sun, 15 Oct 2023 19:02:40 +0200 Subject: [PATCH 1/2] add option to exclude list of users from team PR reviews --- github/resource_github_team_settings.go | 41 ++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/github/resource_github_team_settings.go b/github/resource_github_team_settings.go index e92fc541de..a74c00a9d5 100644 --- a/github/resource_github_team_settings.go +++ b/github/resource_github_team_settings.go @@ -83,6 +83,15 @@ func resourceGithubTeamSettings() *schema.Resource { Default: false, Description: "whether to notify the entire team when at least one member is also assigned to the pull request.", }, + // TODO: The underlying graphql call is using memberIds. Might be better UX to use usernames, or add both as an option... + "excluded_team_member_ids": { + Type: schema.TypeSet, + Optional: true, + Description: "A list of users to exclude from the PR review process", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, }, }, }, @@ -144,6 +153,7 @@ func resourceGithubTeamSettingsRead(d *schema.ResourceData, meta interface{}) er } else { d.Set("review_request_delegation", []interface{}{}) } + // TODO: The exlusion list is not available via the GraphQL call yet (https://docs.github.com/en/enterprise-cloud@latest/graphql/overview/schema-previews#team-review-assignments-preview). Leaving that for future implementation return nil @@ -171,12 +181,20 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta interface{}) } `graphql:"updateTeamReviewAssignment(input:$input)"` } + exclusionList := make([]string, 0) + for _, v := range settings["excluded_team_member_ids"].(*schema.Set).List() { + if v != nil { + exclusionList = append(exclusionList, v.(string)) + } + } + return graphql.Mutate(ctx, &mutation, UpdateTeamReviewAssignmentInput{ - TeamID: d.Id(), - ReviewRequestDelegation: true, - ReviewRequestDelegationAlgorithm: settings["algorithm"].(string), - ReviewRequestDelegationCount: settings["member_count"].(int), - ReviewRequestDelegationNotifyAll: settings["notify"].(bool), + TeamID: d.Id(), + ReviewRequestDelegation: true, + ReviewRequestDelegationAlgorithm: settings["algorithm"].(string), + ReviewRequestDelegationCount: settings["member_count"].(int), + ReviewRequestDelegationNotifyAll: settings["notify"].(bool), + ReviewRequestexcludedTeamMemberIds: exclusionList, }, nil) } } @@ -242,12 +260,13 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId s } type UpdateTeamReviewAssignmentInput struct { - ClientMutationID string `json:"clientMutationId,omitempty"` - TeamID string `graphql:"id" json:"id"` - ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"` - ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"` - ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"` - ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"` + ClientMutationID string `json:"clientMutationId,omitempty"` + TeamID string `graphql:"id" json:"id"` + ReviewRequestDelegation bool `graphql:"enabled" json:"enabled"` + ReviewRequestDelegationAlgorithm string `graphql:"algorithm" json:"algorithm"` + ReviewRequestDelegationCount int `graphql:"teamMemberCount" json:"teamMemberCount"` + ReviewRequestDelegationNotifyAll bool `graphql:"notifyTeam" json:"notifyTeam"` + ReviewRequestexcludedTeamMemberIds []string `graphql:"excludedTeamMemberIds" json:"excludedTeamMemberIds"` } func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput { From bda8a7429a1b8ffee82519dd0301886c8ea52b84 Mon Sep 17 00:00:00 2001 From: felixlut Date: Tue, 17 Oct 2023 21:57:38 +0200 Subject: [PATCH 2/2] updateteamreviewassignmentinput takes the node_id, not the id --- github/resource_github_team_settings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/resource_github_team_settings.go b/github/resource_github_team_settings.go index a74c00a9d5..137fdd8317 100644 --- a/github/resource_github_team_settings.go +++ b/github/resource_github_team_settings.go @@ -84,7 +84,7 @@ func resourceGithubTeamSettings() *schema.Resource { Description: "whether to notify the entire team when at least one member is also assigned to the pull request.", }, // TODO: The underlying graphql call is using memberIds. Might be better UX to use usernames, or add both as an option... - "excluded_team_member_ids": { + "excluded_team_member_node_ids": { Type: schema.TypeSet, Optional: true, Description: "A list of users to exclude from the PR review process", @@ -182,7 +182,7 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta interface{}) } exclusionList := make([]string, 0) - for _, v := range settings["excluded_team_member_ids"].(*schema.Set).List() { + for _, v := range settings["excluded_team_member_node_ids"].(*schema.Set).List() { if v != nil { exclusionList = append(exclusionList, v.(string)) }