Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 28 additions & 6 deletions github/resource_github_team_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ 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.",
},
"excluded_team_member_node_ids": {
Type: schema.TypeSet,
Optional: true,
Description: "A list of team member node IDs to exclude from the PR review process.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
Expand Down Expand Up @@ -151,6 +159,9 @@ func resourceGithubTeamSettingsRead(d *schema.ResourceData, meta any) error {
return err
}
}
// NOTE: The exclusion list is not available via the GraphQL read query yet.
// The excluded_team_member_node_ids field can be set but cannot be read back from the GitHub API.
// This is because the GraphQL API for team review assignments is currently in preview.
Comment thread
janeklb marked this conversation as resolved.
Outdated

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

exclusionList := make([]string, 0)
if excludedIDs, ok := settings["excluded_team_member_node_ids"]; ok && excludedIDs != nil {
for _, v := range excludedIDs.(*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),
ExcludedTeamMemberIds: exclusionList,
}, nil)
}
}
Expand Down Expand Up @@ -252,12 +273,13 @@ func resolveTeamIDs(idOrSlug string, meta *Owner, ctx context.Context) (nodeId,
}

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"`
ExcludedTeamMemberIds []string `graphql:"excludedTeamMemberIds" json:"excludedTeamMemberIds"`
}

func defaultTeamReviewAssignmentSettings(id string) UpdateTeamReviewAssignmentInput {
Expand Down
43 changes: 43 additions & 0 deletions github/resource_github_team_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,49 @@ func TestAccGithubTeamSettings(t *testing.T) {
})
})

t.Run("manages team code review settings with excluded members", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
config := fmt.Sprintf(`
resource "github_team" "test" {
name = "%s"
description = "generated by terraform provider automated testing"
}

resource "github_team_settings" "test" {
team_id = "${github_team.test.id}"
review_request_delegation {
algorithm = "ROUND_ROBIN"
member_count = 1
notify = true
excluded_team_member_node_ids = ["MDQ6VXNlcjU4MzIzMQ==", "MDQ6VXNlcjU4MzIzMg=="]
}
}
`, teamName)

check := resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.algorithm",
"ROUND_ROBIN",
),
resource.TestCheckResourceAttr(
"github_team_settings.test", "review_request_delegation.0.excluded_team_member_node_ids.#",
"2",
),
)

resource.Test(t, resource.TestCase{
PreCheck: func() { skipUnlessHasOrgs(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: config,
Check: check,
},
},
})
})

t.Run("cannot manage team code review settings if disabled", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
teamName := fmt.Sprintf("%steam-settings-%s", testResourcePrefix, randomID)
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/team_settings.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ resource "github_team_settings" "code_review_settings" {
algorithm = "ROUND_ROBIN"
member_count = 1
notify = true
excluded_team_member_node_ids = ["MDQ6VXNlcjU4MzIzMQ=="]
}
}
```
Expand All @@ -48,6 +49,7 @@ The following arguments are supported:
* `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`
* `member_count` - (Optional) The number of team members to assign to a pull request
* `notify` - (Optional) whether to notify the entire team when at least one member is also assigned to the pull request
* `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.


## Import
Expand Down