Merge pull request #6926 from defaultbr/fix-azure-devops-url-path
Handle Azure DevOps (or other provider) that use query parameter named PATH to refer to files
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-import': patch
|
||||
---
|
||||
|
||||
handle azure devops url query parameter for importing .yaml
|
||||
@@ -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: {
|
||||
|
||||
@@ -53,7 +53,10 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
}
|
||||
|
||||
async analyzeUrl(url: string): Promise<AnalyzeResult> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user