Skip to content

Commit

Permalink
feat: Also list repos without admin access
Browse files Browse the repository at this point in the history
  • Loading branch information
langecode committed Sep 25, 2023
1 parent 30bdca8 commit 3ffd16c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions server/forge/bitbucketserver/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,15 @@ func (c *client) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
return nil, fmt.Errorf("unable to create bitbucket client: %w", err)
}

opts := &bb.RepositorySearchOptions{Permission: bb.PermissionRepoAdmin, ListOptions: bb.ListOptions{Limit: 250}}
opts := &bb.RepositorySearchOptions{Permission: bb.PermissionRepoRead, ListOptions: bb.ListOptions{Limit: 250}}
var all []*model.Repo
for {
repos, resp, err := bc.Projects.SearchRepositories(ctx, opts)
if err != nil {
return nil, fmt.Errorf("unable to search repositories: %w", err)
}
for _, r := range repos {
perms := &model.Perm{Pull: true, Push: true, Admin: true}
perms := &model.Perm{Pull: true, Push: false, Admin: false}
all = append(all, convertRepo(r, perms, ""))
}
if resp.LastPage {
Expand All @@ -212,6 +212,27 @@ func (c *client) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error
opts.Start = resp.NextPageStart
}

// Add admin permissions to relevant repositories
opts = &bb.RepositorySearchOptions{Permission: bb.PermissionRepoAdmin, ListOptions: bb.ListOptions{Limit: 250}}
for {
repos, resp, err := bc.Projects.SearchRepositories(ctx, opts)
if err != nil {
return nil, fmt.Errorf("unable to search repositories: %w", err)
}
for _, r := range repos {
for i, c := range all {
if c.ForgeRemoteID == model.ForgeRemoteID(fmt.Sprintf("%d", r.ID)) {
all[i].Perm = &model.Perm{Pull: true, Push: true, Admin: true}
break
}
}
}
if resp.LastPage {
break
}
opts.Start = resp.NextPageStart
}

return all, nil
}

Expand Down

0 comments on commit 3ffd16c

Please sign in to comment.