diff --git a/server/forge/bitbucket/bitbucket.go b/server/forge/bitbucket/bitbucket.go index 8d01df40b3..3105ddb960 100644 --- a/server/forge/bitbucket/bitbucket.go +++ b/server/forge/bitbucket/bitbucket.go @@ -160,7 +160,13 @@ func (c *config) Teams(ctx context.Context, u *model.User, p *model.ListOptions) if err != nil { return nil, err } - return convertWorkspaceList(resp.Values), nil + var workspaces []*internal.Workspace + for _, access := range resp.Values { + if access.Workspace != nil { + workspaces = append(workspaces, access.Workspace) + } + } + return convertWorkspaceList(workspaces), nil } // Repo returns the named Bitbucket repository. @@ -214,7 +220,12 @@ func (c *config) Repos(ctx context.Context, u *model.User, p *model.ListOptions) } var all []*model.Repo - for _, workspace := range resp.Values { + for _, access := range resp.Values { + if access.Workspace == nil { + continue + } + workspace := access.Workspace + repos, err := client.ListReposAll(workspace.Slug) if err != nil { return nil, err diff --git a/server/forge/bitbucket/fixtures/handler.go b/server/forge/bitbucket/fixtures/handler.go index e8bcfdea4e..52b39721d6 100644 --- a/server/forge/bitbucket/fixtures/handler.go +++ b/server/forge/bitbucket/fixtures/handler.go @@ -534,19 +534,19 @@ const workspacesPayload = ` "size": 1, "values": [ { - "type": "workspace", - "uuid": "{c7a04a76-fa20-43e4-dc42-a7506db4c95b}", - "name": "Ueber Dev", - "slug": "test_name", - "links": { - "avatar": { - "href": "https://bitbucket.org/workspaces/ueberdev42/avatar/?ts=1658761964" - }, - "html": { - "href": "https://bitbucket.org/ueberdev42/" - }, - "self": { - "href": "https://api.bitbucket.org/2.0/workspaces/ueberdev42" + "type": "workspace_access", + "administrator": true, + "workspace": { + "type": "workspace_base", + "uuid": "{c7a04a76-fa20-43e4-dc42-a7506db4c95b}", + "slug": "test_name", + "links": { + "avatar": { + "href": "https://bitbucket.org/workspaces/ueberdev42/avatar/?ts=1658761964" + }, + "self": { + "href": "https://api.bitbucket.org/2.0/workspaces/ueberdev42" + } } } } diff --git a/server/forge/bitbucket/internal/types.go b/server/forge/bitbucket/internal/types.go index d816ce81f7..ca38c0e988 100644 --- a/server/forge/bitbucket/internal/types.go +++ b/server/forge/bitbucket/internal/types.go @@ -33,17 +33,22 @@ type Account struct { type Workspace struct { UUID string `json:"uuid"` Slug string `json:"slug"` - Name string `json:"name"` Type string `json:"type"` Links Links `json:"links"` } +type WorkspaceAccess struct { + Type string `json:"type"` + Administrator bool `json:"administrator"` + Workspace *Workspace `json:"workspace"` +} + type WorkspacesResp struct { - Page int `json:"page"` - Pages int `json:"pagelen"` - Size int `json:"size"` - Next string `json:"next"` - Values []*Workspace `json:"values"` + Page int `json:"page"` + Pages int `json:"pagelen"` + Size int `json:"size"` + Next string `json:"next"` + Values []*WorkspaceAccess `json:"values"` } type PipelineStatus struct {