handle azure devops url path parameter for .yaml files

Signed-off-by: Tarcisio Ambrosio Wensing <tarcisio.wensing@midway.com.br>
This commit is contained in:
Tarcisio Ambrosio Wensing
2021-08-23 12:21:38 -03:00
parent 1d91d78490
commit b5a2896ed4
3 changed files with 59 additions and 1 deletions
+5
View File
@@ -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,