Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 24 additions & 0 deletions pkg/connector/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,30 @@ func parsePageToken(i string, resourceID *v2.ResourceId) (*pagination.Bag, int,
return b, page, nil
}

// isOutsideCollaboratorPhase reports whether the pagination bag is in the
// outside-collaborator phase (phase 2 of the user List).
func isOutsideCollaboratorPhase(bag *pagination.Bag) bool {
return bag.Current().ResourceTypeID == outsideCollaboratorPhase
}
Comment on lines +119 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: bag.Current() is called without a nil guard. This is safe today because parsePageToken always pushes a state when bag.Current() is nil, but it's a subtle precondition. A defensive nil check (or a comment documenting the precondition) would make this less fragile if the call chain ever changes.

Suggested change
func isOutsideCollaboratorPhase(bag *pagination.Bag) bool {
return bag.Current().ResourceTypeID == outsideCollaboratorPhase
}
func isOutsideCollaboratorPhase(bag *pagination.Bag) bool {
current := bag.Current()
return current != nil && current.ResourceTypeID == outsideCollaboratorPhase
}


// membersNextPageToken advances the pagination bag for the org-members phase.
// When there are no more member pages (nextPage == ""), it transitions the bag
// to the outside-collaborator phase so the next List call fetches phase 2.
// Precondition: parentID must not be nil (callers must guard this before calling).
func membersNextPageToken(bag *pagination.Bag, nextPage string, parentID *v2.ResourceId) (string, error) {
if nextPage == "" {
// bag.Current() is always the members-phase state here; Pop removes it
// before pushing the outside-collaborator phase.
bag.Pop()
bag.Push(pagination.PageState{
ResourceTypeID: outsideCollaboratorPhase,
ResourceID: parentID.Resource,
})
return bag.Marshal()
}
return bag.NextToken(nextPage)
}

// convertPageToken converts a string token into an int.
func convertPageToken(token string) (int, error) {
if token == "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (o *orgResourceType) Grants(
}

for _, user := range users {
ur, err := userResource(ctx, user, user.GetEmail(), nil)
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/org_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (o *orgRoleResourceType) Grants(

// Create regular grants for direct user assignments.
for _, user := range users {
userResource, err := userResource(ctx, user, user.GetEmail(), nil)
userResource, err := userResource(ctx, user, user.GetEmail(), nil, false)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/org_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestOrgRole(t *testing.T) {
Name: orgRole.Name,
Description: orgRole.Description,
}, organization)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)

entitlement := v2.Entitlement{
Id: entitlement2.NewEntitlementID(roleResource, "assigned"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestOrganization(t *testing.T) {
client := orgBuilder(githubClient, nil, cache, nil, false)

organization, _ := organizationResource(ctx, githubOrganization, nil, false)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)

entitlement := v2.Entitlement{
Id: entitlement.NewEntitlementID(organization, orgRoleMember),
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (o *repositoryResourceType) Grants(
continue
}

ur, err := userResource(ctx, user, user.GetEmail(), nil)
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestRepository(t *testing.T) {

organization, _ := organizationResource(ctx, githubOrganization, nil, false)
repository, _ := repositoryResource(ctx, githubRepository, organization.Id)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)

entitlement := v2.Entitlement{
Id: entitlement2.NewEntitlementID(repository, "admin"),
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, op
}

for _, user := range users {
ur, err := userResource(ctx, user, user.GetEmail(), nil)
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/connector/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestTeam(t *testing.T) {

organization, _ := organizationResource(ctx, githubOrganization, nil, false)
team, _ := teamResource(githubTeam, organization.Id)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)

entitlement := v2.Entitlement{
Id: entitlement2.NewEntitlementID(team, "member"),
Expand Down
Loading
Loading