Skip to content

Commit 638bd45

Browse files
committed
refactor: improve UX by accepting usernames instead of node IDs
- Change excluded_team_member_node_ids to excluded_team_members - Accept GitHub usernames instead of GraphQL node IDs - Add getUserNodeId helper function to lookup node IDs automatically - Update tests to use friendly usernames like 'octocat', 'defunkt' - Update documentation with simpler examples - Makes configuration much more user-friendly and intuitive
1 parent c7bc8af commit 638bd45

3 files changed

Lines changed: 36 additions & 9 deletions

File tree

github/resource_github_team_settings.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ import (
1010
"github.com/shurcooL/githubv4"
1111
)
1212

13+
// getUserNodeId retrieves the GraphQL node ID for a given username
14+
func getUserNodeId(ctx context.Context, meta interface{}, username string) (string, error) {
15+
client := meta.(*Owner).v4client
16+
17+
var query struct {
18+
User struct {
19+
ID githubv4.ID `graphql:"id"`
20+
} `graphql:"user(login: $username)"`
21+
}
22+
23+
variables := map[string]interface{}{
24+
"username": githubv4.String(username),
25+
}
26+
27+
err := client.Query(ctx, &query, variables)
28+
if err != nil {
29+
return "", fmt.Errorf("failed to query user %s: %v", username, err)
30+
}
31+
32+
return string(query.User.ID.(githubv4.String)), nil
33+
}
34+
1335
func resourceGithubTeamSettings() *schema.Resource {
1436
return &schema.Resource{
1537
Create: resourceGithubTeamSettingsCreate,
@@ -83,10 +105,10 @@ func resourceGithubTeamSettings() *schema.Resource {
83105
Default: false,
84106
Description: "whether to notify the entire team when at least one member is also assigned to the pull request.",
85107
},
86-
"excluded_team_member_node_ids": {
108+
"excluded_team_members": {
87109
Type: schema.TypeSet,
88110
Optional: true,
89-
Description: "A list of team member node IDs to exclude from the PR review process.",
111+
Description: "A list of team member usernames to exclude from the PR review process.",
90112
Elem: &schema.Schema{
91113
Type: schema.TypeString,
92114
},
@@ -189,10 +211,15 @@ func resourceGithubTeamSettingsUpdate(d *schema.ResourceData, meta any) error {
189211
}
190212

191213
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() {
214+
if excludedMembers, ok := settings["excluded_team_members"]; ok && excludedMembers != nil {
215+
for _, v := range excludedMembers.(*schema.Set).List() {
194216
if v != nil {
195-
exclusionList = append(exclusionList, v.(string))
217+
username := v.(string)
218+
nodeId, err := getUserNodeId(ctx, meta, username)
219+
if err != nil {
220+
return fmt.Errorf("failed to get node ID for user %s: %v", username, err)
221+
}
222+
exclusionList = append(exclusionList, nodeId)
196223
}
197224
}
198225
}

github/resource_github_team_settings_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
138138
algorithm = "ROUND_ROBIN"
139139
member_count = 1
140140
notify = true
141-
excluded_team_member_node_ids = ["MDQ6VXNlcjU4MzIzMQ==", "MDQ6VXNlcjU4MzIzMg=="]
141+
excluded_team_members = ["octocat", "defunkt"]
142142
}
143143
}
144144
`, teamName)
@@ -149,7 +149,7 @@ func TestAccGithubTeamSettings(t *testing.T) {
149149
"ROUND_ROBIN",
150150
),
151151
resource.TestCheckResourceAttr(
152-
"github_team_settings.test", "review_request_delegation.0.excluded_team_member_node_ids.#",
152+
"github_team_settings.test", "review_request_delegation.0.excluded_team_members.#",
153153
"2",
154154
),
155155
)

website/docs/r/team_settings.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +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=="]
33+
excluded_team_members = ["octocat", "defunkt"]
3434
}
3535
}
3636
```
@@ -49,7 +49,7 @@ The following arguments are supported:
4949
* `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`
5050
* `member_count` - (Optional) The number of team members to assign to a pull request
5151
* `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.
52+
* `excluded_team_members` - (Optional) A list of team member usernames to exclude from the PR review process.
5353

5454

5555
## Import

0 commit comments

Comments
 (0)