Skip to content

Commit 7ddbf35

Browse files
authored
fix: guard nil invitation from AddCollaborator for org members (#3371)
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>
1 parent 18178b1 commit 7ddbf35

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

github/resource_github_repository_collaborators.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,13 @@ func updateUserCollaboratorsAndInvites(ctx context.Context, client *github.Clien
691691
if err != nil {
692692
return nil, err
693693
}
694-
inUser.invitationID = inv.ID
695-
ghInvites = append(ghInvites, inUser)
694+
// AddCollaborator returns 204 No Content (inv == nil) when the invitee
695+
// is an organization member gaining direct access without an
696+
// invitation. In that case there is no invitation ID to record.
697+
if inv != nil {
698+
inUser.invitationID = inv.ID
699+
ghInvites = append(ghInvites, inUser)
700+
}
696701
}
697702

698703
for _, l := range remove {

0 commit comments

Comments
 (0)