From 3ffd16c79a74f8b925236d6e22063fba260a61b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thor=20Anker=20Kvisg=C3=A5rd=20Lange?= Date: Mon, 25 Sep 2023 15:25:21 +0200 Subject: [PATCH] feat: Also list repos without admin access --- .../forge/bitbucketserver/bitbucketserver.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/server/forge/bitbucketserver/bitbucketserver.go b/server/forge/bitbucketserver/bitbucketserver.go index 3a8eb77911..cad83fd180 100644 --- a/server/forge/bitbucketserver/bitbucketserver.go +++ b/server/forge/bitbucketserver/bitbucketserver.go @@ -195,7 +195,7 @@ 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) @@ -203,7 +203,7 @@ func (c *client) Repos(ctx context.Context, u *model.User) ([]*model.Repo, error 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 { @@ -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 }