From f63aae6f39231cc0ad93b39a7a850eebe4034425 Mon Sep 17 00:00:00 2001 From: bofus10 <33520078+bofus10@users.noreply.github.com> Date: Fri, 24 Apr 2026 17:44:43 +0200 Subject: [PATCH] fix: guard nil invitation from AddCollaborator for org members When the invitee of `github_repository_collaborators` is an organization member who is not yet a direct collaborator, GitHub's REST API returns `204 No Content` from `PUT /repos/{owner}/{repo}/collaborators/{username}` (the user is promoted to direct collaborator immediately, no invitation is issued). The Go client surfaces this as `inv == nil, err == nil`. Since #3233 the create/update path in `updateUserCollaboratorsAndInvites` unconditionally dereferences `inv.ID`, causing a nil pointer panic for any configuration that adds an org member as a direct collaborator for the first time. Guard the invitation-tracking branch on `inv != nil`. On the 204 path there is no invitation to record; the user is a direct collaborator already and will be picked up by the next `listUserCollaborators` call. Signed-off-by: bofus10 <33520078+bofus10@users.noreply.github.com> --- github/resource_github_repository_collaborators.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/github/resource_github_repository_collaborators.go b/github/resource_github_repository_collaborators.go index ece5141927..51a389a852 100644 --- a/github/resource_github_repository_collaborators.go +++ b/github/resource_github_repository_collaborators.go @@ -691,8 +691,13 @@ func updateUserCollaboratorsAndInvites(ctx context.Context, client *github.Clien if err != nil { return nil, err } - inUser.invitationID = inv.ID - ghInvites = append(ghInvites, inUser) + // AddCollaborator returns 204 No Content (inv == nil) when the invitee + // is an organization member gaining direct access without an + // invitation. In that case there is no invitation ID to record. + if inv != nil { + inUser.invitationID = inv.ID + ghInvites = append(ghInvites, inUser) + } } for _, l := range remove {