diff --git a/.changeset/quick-fireants-approve.md b/.changeset/quick-fireants-approve.md new file mode 100644 index 0000000000..3b965c75ad --- /dev/null +++ b/.changeset/quick-fireants-approve.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-import': patch +--- + +handle azure devops url query parameter for importing .yaml diff --git a/plugins/catalog-import/src/api/CatalogImportClient.test.ts b/plugins/catalog-import/src/api/CatalogImportClient.test.ts index 44f33dc660..2936f956e4 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.test.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.test.ts @@ -171,6 +171,56 @@ describe('CatalogImportClient', () => { }); }); + it('should add yaml location, if url includes query parameter named path=', async () => { + catalogApi.addLocation.mockResolvedValueOnce({ + location: { + id: 'id-0', + type: 'url', + target: + 'https://dev.azure.com/any-org/any-project/_git/any-repository?path=%2Fcatalog-info.yaml', + }, + entities: [ + { + apiVersion: '1', + kind: 'Component', + metadata: { + name: 'my-entity-1', + namespace: 'my-namespace-1', + }, + }, + ], + }); + + await expect( + catalogImportClient.analyzeUrl( + 'https://dev.azure.com/any-org/any-project/_git/any-repository?path=%2Fcatalog-info.yaml', + ), + ).resolves.toEqual({ + locations: [ + { + entities: [ + { + kind: 'Component', + name: 'my-entity-1', + namespace: 'my-namespace-1', + }, + ], + target: + 'https://dev.azure.com/any-org/any-project/_git/any-repository?path=%2Fcatalog-info.yaml', + }, + ], + type: 'locations', + }); + + expect(catalogApi.addLocation).toBeCalledTimes(1); + expect(catalogApi.addLocation.mock.calls[0][0]).toEqual({ + type: 'url', + target: + 'https://dev.azure.com/any-org/any-project/_git/any-repository?path=%2Fcatalog-info.yaml', + dryRun: true, + }); + }); + it('should add yaml location, if url includes query parameters', async () => { catalogApi.addLocation.mockResolvedValueOnce({ location: { diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index d7a2028330..2497af99d8 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -53,7 +53,10 @@ export class CatalogImportClient implements CatalogImportApi { } async analyzeUrl(url: string): Promise { - if (new URL(url).pathname.match(/\.ya?ml$/)) { + if ( + new URL(url).pathname.match(/\.ya?ml$/) || + new URL(url).searchParams.get('path')?.match(/.ya?ml$/) + ) { const location = await this.catalogApi.addLocation({ type: 'url', target: url,