diff --git a/.changeset/wise-teeth-study.md b/.changeset/wise-teeth-study.md new file mode 100644 index 0000000000..0695f98335 --- /dev/null +++ b/.changeset/wise-teeth-study.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend-module-azure': patch +--- + +visualstudio.com domains are now supported along with dev.azure.com diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.test.ts b/plugins/catalog-backend-module-azure/src/lib/azure.test.ts index 4839b625d2..f033a85113 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.test.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.test.ts @@ -392,4 +392,97 @@ describe('azure', () => { ), ).resolves.toHaveLength(totalCount); }); + + it('can search using visualstudio.com domain', async () => { + const response: CodeSearchResponse = { + count: 1, + results: [ + { + fileName: 'catalog-info.yaml', + path: '/catalog-info.yaml', + repository: { + name: 'backstage', + }, + project: { + name: '*', + }, + }, + ], + }; + + server.use( + rest.post( + `https://almsearch.dev.azure.com/shopify/_apis/search/codesearchresults`, + (req, res, ctx) => { + expect(req.headers.get('Authorization')).toBe('Basic OkFCQw=='); + expect(req.body).toEqual({ + searchText: 'path:/catalog-info.yaml repo:* proj:engineering', + $orderBy: [ + { + field: 'path', + sortOrder: 'ASC', + }, + ], + $skip: 0, + $top: 1000, + }); + return res(ctx.json(response)); + }, + ), + ); + + const { credentialsProvider, azureConfig } = createFixture( + 'backstage.visualstudio.com', + 'ABC', + ); + + await expect( + codeSearch( + credentialsProvider, + azureConfig, + 'shopify', + 'engineering', + '', + '/catalog-info.yaml', + '', + ), + ).resolves.toEqual(response.results); + }); + + it('identifies both dev.azure.com and visualstudio.com domains as cloud', async () => { + const domains = [ + { host: 'dev.azure.com', expectedCloud: true }, + { host: 'example.visualstudio.com', expectedCloud: true }, + { host: 'on-premise.company.com', expectedCloud: false }, + ]; + + for (const { host, expectedCloud } of domains) { + const mockResponse = { count: 0, results: [] }; + + const expectedBaseUrl = expectedCloud + ? 'https://almsearch.dev.azure.com' + : `https://${host}`; + + server.use( + rest.post( + `${expectedBaseUrl}/test-org/_apis/search/codesearchresults`, + (_req, res, ctx) => { + return res(ctx.json(mockResponse)); + }, + ), + ); + + const { credentialsProvider, azureConfig } = createFixture(host, 'TOKEN'); + + await codeSearch( + credentialsProvider, + azureConfig, + 'test-org', + 'test-project', + '', + '/test-path', + '', + ); + } + }); }); diff --git a/plugins/catalog-backend-module-azure/src/lib/azure.ts b/plugins/catalog-backend-module-azure/src/lib/azure.ts index 0b0d89c15b..7e9bf203ea 100644 --- a/plugins/catalog-backend-module-azure/src/lib/azure.ts +++ b/plugins/catalog-backend-module-azure/src/lib/azure.ts @@ -46,7 +46,18 @@ interface CodeSearchRequest { }; } -const isCloud = (host: string) => host === 'dev.azure.com'; +const isCloud = (host: string) => { + if (host === 'dev.azure.com') { + return true; + } + + if (host.endsWith('.visualstudio.com')) { + return true; + } + + return false; +}; + const PAGE_SIZE = 1000; // codeSearch returns all files that matches the given search path.