Fix catalog import not detecting yaml files correctly if query parameters are used
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-import': patch
|
||||
---
|
||||
|
||||
Fix importing yaml files from URLs with trailing query parameters.
|
||||
@@ -171,6 +171,53 @@ describe('CatalogImportClient', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should add yaml location, if url includes query parameters', async () => {
|
||||
catalogApi.addLocation.mockResolvedValueOnce({
|
||||
location: {
|
||||
id: 'id-0',
|
||||
type: 'url',
|
||||
target: 'http://example.com/folder/catalog-info.yaml?branch=test',
|
||||
},
|
||||
entities: [
|
||||
{
|
||||
apiVersion: '1',
|
||||
kind: 'Component',
|
||||
metadata: {
|
||||
name: 'my-entity',
|
||||
namespace: 'my-namespace',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await expect(
|
||||
catalogImportClient.analyzeUrl(
|
||||
'http://example.com/folder/catalog-info.yaml?branch=test',
|
||||
),
|
||||
).resolves.toEqual({
|
||||
locations: [
|
||||
{
|
||||
entities: [
|
||||
{
|
||||
kind: 'Component',
|
||||
name: 'my-entity',
|
||||
namespace: 'my-namespace',
|
||||
},
|
||||
],
|
||||
target: 'http://example.com/folder/catalog-info.yaml?branch=test',
|
||||
},
|
||||
],
|
||||
type: 'locations',
|
||||
});
|
||||
|
||||
expect(catalogApi.addLocation).toBeCalledTimes(1);
|
||||
expect(catalogApi.addLocation.mock.calls[0][0]).toEqual({
|
||||
type: 'url',
|
||||
target: 'http://example.com/folder/catalog-info.yaml?branch=test',
|
||||
dryRun: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('should reject for integrations that are not github ones', async () => {
|
||||
await expect(
|
||||
catalogImportClient.analyzeUrl(
|
||||
|
||||
@@ -16,20 +16,20 @@
|
||||
|
||||
import { CatalogApi } from '@backstage/catalog-client';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import {
|
||||
GitHubIntegrationConfig,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { PartialEntity } from '../types';
|
||||
import { AnalyzeResult, CatalogImportApi } from './CatalogImportApi';
|
||||
import { getGithubIntegrationConfig } from './GitHub';
|
||||
import {
|
||||
DiscoveryApi,
|
||||
IdentityApi,
|
||||
OAuthApi,
|
||||
} from '@backstage/core-plugin-api';
|
||||
import {
|
||||
GitHubIntegrationConfig,
|
||||
ScmIntegrationRegistry,
|
||||
} from '@backstage/integration';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
import { Base64 } from 'js-base64';
|
||||
import { PartialEntity } from '../types';
|
||||
import { AnalyzeResult, CatalogImportApi } from './CatalogImportApi';
|
||||
import { getGithubIntegrationConfig } from './GitHub';
|
||||
|
||||
export class CatalogImportClient implements CatalogImportApi {
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
@@ -53,7 +53,7 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
}
|
||||
|
||||
async analyzeUrl(url: string): Promise<AnalyzeResult> {
|
||||
if (url.match(/\.ya?ml$/)) {
|
||||
if (new URL(url).pathname.match(/\.ya?ml$/)) {
|
||||
const location = await this.catalogApi.addLocation({
|
||||
type: 'url',
|
||||
target: url,
|
||||
@@ -340,7 +340,6 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
link: pullRequestResponse.data.html_url,
|
||||
location: `https://${githubIntegrationConfig.host}/${owner}/${repo}/blob/${repoData.data.default_branch}/${fileName}`,
|
||||
|
||||
Reference in New Issue
Block a user