Skip to content

Commit 83893b2

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(selectors): normalize Bitbucket workspace UUIDs
1 parent d8a6b6b commit 83893b2

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

apps/sim/lib/selectors/server/providers/bitbucket.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,14 @@ describe('Bitbucket server selector adapters', () => {
150150
expect(mockFetch).toHaveBeenCalledTimes(1)
151151
})
152152

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

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

169172
expect(new URL(String(mockFetch.mock.calls[0]?.[0])).pathname).toBe(
170-
`/2.0/workspaces/${encodeURIComponent(workspaceUuid)}`
173+
`/2.0/workspaces/${encodeURIComponent(providerUuid)}`
171174
)
172175
expect(new URL(String(mockFetch.mock.calls[1]?.[0])).pathname).toBe(
173176
'/2.0/repositories/acme-platform'

apps/sim/lib/selectors/server/providers/bitbucket.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ function normalizeBitbucketUuid(value: string): string {
106106
return value.replace(/^\{?|\}?$/g, '').toLowerCase()
107107
}
108108

109+
function formatBitbucketUuid(value: string): string {
110+
return `{${normalizeBitbucketUuid(value)}}`
111+
}
112+
109113
function requireCursorParams(cursor: string): URLSearchParams {
110114
if (!cursor || cursor.length > BITBUCKET_CURSOR_MAX_LENGTH) {
111115
throw new SelectorContextUnavailableError()
@@ -193,7 +197,13 @@ async function getWorkspace(
193197
identifier: string,
194198
accessToken: string
195199
): Promise<z.infer<typeof workspaceDetailSchema>> {
196-
const url = new URL(`/2.0/workspaces/${encodeURIComponent(identifier)}`, BITBUCKET_API_ORIGIN)
200+
const providerIdentifier = isBitbucketUuid(identifier)
201+
? formatBitbucketUuid(identifier)
202+
: identifier
203+
const url = new URL(
204+
`/2.0/workspaces/${encodeURIComponent(providerIdentifier)}`,
205+
BITBUCKET_API_ORIGIN
206+
)
197207
url.searchParams.set('fields', 'slug,uuid,name')
198208
const body = await fetchProviderJson<unknown>(url, {
199209
headers: { Authorization: `Bearer ${accessToken}`, Accept: 'application/json' },

0 commit comments

Comments
 (0)