Skip to content

Commit 039600c

Browse files
committed
sync outside collaborators as part of user List
1 parent 8077bc3 commit 039600c

13 files changed

Lines changed: 353 additions & 112 deletions

File tree

pkg/connector/helpers.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,30 @@ func parsePageToken(i string, resourceID *v2.ResourceId) (*pagination.Bag, int,
114114
return b, page, nil
115115
}
116116

117+
// isOutsideCollaboratorPhase reports whether the pagination bag is in the
118+
// outside-collaborator phase (phase 2 of the user List).
119+
func isOutsideCollaboratorPhase(bag *pagination.Bag) bool {
120+
return bag.Current().ResourceTypeID == outsideCollaboratorPhase
121+
}
122+
123+
// membersNextPageToken advances the pagination bag for the org-members phase.
124+
// When there are no more member pages (nextPage == ""), it transitions the bag
125+
// to the outside-collaborator phase so the next List call fetches phase 2.
126+
// Precondition: parentID must not be nil (callers must guard this before calling).
127+
func membersNextPageToken(bag *pagination.Bag, nextPage string, parentID *v2.ResourceId) (string, error) {
128+
if nextPage == "" {
129+
// bag.Current() is always the members-phase state here; Pop removes it
130+
// before pushing the outside-collaborator phase.
131+
bag.Pop()
132+
bag.Push(pagination.PageState{
133+
ResourceTypeID: outsideCollaboratorPhase,
134+
ResourceID: parentID.Resource,
135+
})
136+
return bag.Marshal()
137+
}
138+
return bag.NextToken(nextPage)
139+
}
140+
117141
// convertPageToken converts a string token into an int.
118142
func convertPageToken(token string) (int, error) {
119143
if token == "" {

pkg/connector/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func (o *orgResourceType) Grants(
241241
}
242242

243243
for _, user := range users {
244-
ur, err := userResource(ctx, user, user.GetEmail(), nil)
244+
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
245245
if err != nil {
246246
return nil, nil, err
247247
}

pkg/connector/org_role.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (o *orgRoleResourceType) Grants(
190190

191191
// Create regular grants for direct user assignments.
192192
for _, user := range users {
193-
userResource, err := userResource(ctx, user, user.GetEmail(), nil)
193+
userResource, err := userResource(ctx, user, user.GetEmail(), nil, false)
194194
if err != nil {
195195
return nil, nil, err
196196
}

pkg/connector/org_role_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestOrgRole(t *testing.T) {
3333
Name: orgRole.Name,
3434
Description: orgRole.Description,
3535
}, organization)
36-
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
36+
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)
3737

3838
entitlement := v2.Entitlement{
3939
Id: entitlement2.NewEntitlementID(roleResource, "assigned"),

pkg/connector/org_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestOrganization(t *testing.T) {
2727
client := orgBuilder(githubClient, nil, cache, nil, false)
2828

2929
organization, _ := organizationResource(ctx, githubOrganization, nil, false)
30-
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
30+
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)
3131

3232
entitlement := v2.Entitlement{
3333
Id: entitlement.NewEntitlementID(organization, orgRoleMember),

pkg/connector/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (o *repositoryResourceType) Grants(
208208
continue
209209
}
210210

211-
ur, err := userResource(ctx, user, user.GetEmail(), nil)
211+
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
212212
if err != nil {
213213
return nil, nil, err
214214
}

pkg/connector/repository_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestRepository(t *testing.T) {
2929

3030
organization, _ := organizationResource(ctx, githubOrganization, nil, false)
3131
repository, _ := repositoryResource(ctx, githubRepository, organization.Id)
32-
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
32+
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)
3333

3434
entitlement := v2.Entitlement{
3535
Id: entitlement2.NewEntitlementID(repository, "admin"),

pkg/connector/team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, op
220220
}
221221

222222
for _, user := range users {
223-
ur, err := userResource(ctx, user, user.GetEmail(), nil)
223+
ur, err := userResource(ctx, user, user.GetEmail(), nil, false)
224224
if err != nil {
225225
return nil, nil, err
226226
}

pkg/connector/team_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestTeam(t *testing.T) {
2929

3030
organization, _ := organizationResource(ctx, githubOrganization, nil, false)
3131
team, _ := teamResource(githubTeam, organization.Id)
32-
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil)
32+
user, _ := userResource(ctx, githubUser, *githubUser.Email, nil, false)
3333

3434
entitlement := v2.Entitlement{
3535
Id: entitlement2.NewEntitlementID(team, "member"),

0 commit comments

Comments
 (0)