Skip to content
Merged
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
11 changes: 7 additions & 4 deletions apps/sim/lib/selectors/server/providers/bitbucket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ describe('Bitbucket server selector adapters', () => {
expect(mockFetch).toHaveBeenCalledTimes(1)
})

it('resolves a workspace UUID before listing its repositories', async () => {
const workspaceUuid = '{a15fb181-db1f-48f7-b41f-e1eff06929d6}'
it.each([
['braced', '{a15fb181-db1f-48f7-b41f-e1eff06929d6}'],
['unbraced', 'a15fb181-db1f-48f7-b41f-e1eff06929d6'],
])('resolves a %s workspace UUID before listing its repositories', async (_, workspaceUuid) => {
const providerUuid = '{a15fb181-db1f-48f7-b41f-e1eff06929d6}'
mockFetch
.mockResolvedValueOnce(
providerResponse({ slug: 'acme-platform', uuid: workspaceUuid, name: 'Acme' })
providerResponse({ slug: 'acme-platform', uuid: providerUuid, name: 'Acme' })
)
.mockResolvedValueOnce(providerResponse({ values: [] }))

Expand All @@ -167,7 +170,7 @@ describe('Bitbucket server selector adapters', () => {
).resolves.toEqual({ kind: 'list', items: [] })

expect(new URL(String(mockFetch.mock.calls[0]?.[0])).pathname).toBe(
`/2.0/workspaces/${encodeURIComponent(workspaceUuid)}`
`/2.0/workspaces/${encodeURIComponent(providerUuid)}`
)
expect(new URL(String(mockFetch.mock.calls[1]?.[0])).pathname).toBe(
'/2.0/repositories/acme-platform'
Expand Down
12 changes: 11 additions & 1 deletion apps/sim/lib/selectors/server/providers/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ function normalizeBitbucketUuid(value: string): string {
return value.replace(/^\{?|\}?$/g, '').toLowerCase()
}

function formatBitbucketUuid(value: string): string {
return `{${normalizeBitbucketUuid(value)}}`
}

function requireCursorParams(cursor: string): URLSearchParams {
if (!cursor || cursor.length > BITBUCKET_CURSOR_MAX_LENGTH) {
throw new SelectorContextUnavailableError()
Expand Down Expand Up @@ -193,7 +197,13 @@ async function getWorkspace(
identifier: string,
accessToken: string
): Promise<z.infer<typeof workspaceDetailSchema>> {
const url = new URL(`/2.0/workspaces/${encodeURIComponent(identifier)}`, BITBUCKET_API_ORIGIN)
const providerIdentifier = isBitbucketUuid(identifier)
? formatBitbucketUuid(identifier)
: identifier
const url = new URL(
`/2.0/workspaces/${encodeURIComponent(providerIdentifier)}`,
BITBUCKET_API_ORIGIN
)
url.searchParams.set('fields', 'slug,uuid,name')
const body = await fetchProviderJson<unknown>(url, {
headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },
Expand Down
Loading