Repository navigation
fix: read immediate github_team_members only, not child-team members - #3498
Conversation
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
|
@robert-crandall I think the first thing to do here is to add a test for the regression, I'll take a look at the tests and open a PR to modernize the existing ones and add a test for ignoring child team members. |
deiga
left a comment
There was a problem hiding this comment.
Good catch! Do we have a regression test for this?
|
@robert-crandall you should be able to rebase this onto |
90f1cc9 to
36608aa
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes #3497: after #3499 refactored github_team_members, its Read path used the REST list-team-members endpoint, which always includes members inherited from child teams (it has no immediate-only option). For organizations with nested teams this surfaced inherited members as drift on a resource that manages membership authoritatively. The fix moves the Read path back to the GraphQL API with membership: IMMEDIATE, restoring the pre-#3461 immediate-only semantics while keeping #3461's clean 404 handling.
Changes:
getTeamMembersnow queries the v4 (GraphQL) client withmembers(membership: IMMEDIATE, ...)and paginates viaPageInfo, returning only direct team members.- A null
teamnode (team deleted out-of-band) is mapped to a 404github.ErrorResponse, preserving the existing Read "remove from state" and Delete "already gone" behavior. getTeamMembersandupdateTeamMembersnow accept*Owner(so Read can reachv4clientwhile add/remove keep using the v3 REST client); all call sites updated consistently.
Show a summary per file
| File | Description |
|---|---|
| github/resource_github_team_members.go | Switches the member-read path to GraphQL IMMEDIATE membership with pagination and null-team→404 mapping; threads *Owner through getTeamMembers/updateTeamMembers and updates all callers. |
Verification notes: The GraphQL query shape, cursor pattern ((*githubv4.String)(nil) initial cursor, looping on PageInfo.HasNextPage), and the role lowercasing all match existing conventions (e.g., data_source_github_team.go uses the same membership: IMMEDIATE query). The IMMEDIATE role enum values map cleanly to the schema's member/maintainer values, and the team_with_child_team / team_delete_handled acceptance tests cover the changed behavior. No schema/state shape changes, so this is a backward-compatible bug fix. No blocking findings found.
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
@stevehipwell Done! |
|
@robert-crandall please could you rebase so this can be merged. |
The Read path (getTeamMembers) used the REST list-team-members endpoint, which always includes members inherited from child teams and has no immediate-only option. For organizations with nested teams this surfaced inherited members as drift, and broke the github_team_members member set that is meant to be authoritative. Switch getTeamMembers to the GraphQL API with membership:IMMEDIATE so only direct members are returned. A null team node is mapped to a 404 github.ErrorResponse so the existing Read/Delete handling still removes the resource from state when the team is deleted out-of-band. getTeamMembers and updateTeamMembers now take *Owner so they can reach the v4 (GraphQL) client for reads while still using the v3 client for membership add/remove. Fixes the team_with_child_team regression test added in #3499. Co-authored-by: Copilot <[email protected]>
36608aa to
087a76d
Compare
Resolves #3497
Before the change?
#3499 refactored
github_team_membersand added ateam_with_child_teamregression test, but its Read path (getTeamMembers) still uses the REST list-team-members endpoint. That endpoint always includes members inherited from child teams and has no immediate-only option (the go-githubTeamListTeamMembersOptionsonly exposes arolefilter). So for organizations with nested teams, Read pulls in inherited members the user never configured, breaking the authoritative member set and surfacing drift. Theteam_with_child_teamtest currently fails onmainfor this reason.After the change?
getTeamMembersnow uses the GraphQL API withmembership: IMMEDIATE, which returns only the team's direct members. A nullteamnode (team deleted out-of-band) is mapped to a 404github.ErrorResponse, so the existing Read/Delete handling still removes the resource from state - preserving theteam_delete_handledbehaviour.getTeamMembersandupdateTeamMembersnow take*Ownerso the read path can reach the v4 (GraphQL) client while membership add/remove keep using the v3 (REST) client.This is rebased onto
main(post-#3499). Because #3499 rewrote the resource, this is now a single focused commit re-deriving the fix against the newgetTeamMembersstructure rather than the original pre-#3499 diff.How I verified it
I exercised the real
getTeamMembersfunction (not a copy) against a live nested team (integrations/hubbers) by temporarily wiring it throughgetTestMeta:getTeamMembers(new GraphQLIMMEDIATEpath) returned 14 members (immediate only).team_with_child_team'sSetSizeExactassertion onmain.github.ErrorResponse, confirming the GraphQL null-node -> 404 mapping that keepsteam_delete_handledworking (Read removes from state).Static checks:
go build,go vet,gofmt -l,go test -run TestAccGithubTeamMembers(compiles + skips without creds),golangci-lint run ./github/(0 issues), and the repo's strict linter (forcetypeassert) against the changed code (0 issues).What I did NOT verify
TF_ACCacceptance suite end-to-end (no org-write credentials here;team_with_child_teamneeds two org members + a child team). My verification drives the realgetTeamMembersagainst a live nested team, which proves the immediate-vs-all behaviour and the 404 mapping, but it is not the literal Terraform acceptance run.Does this introduce a breaking change?