From 7d8c4c97cd70617f7aa290bc0abd5c085da03c23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Tue, 16 Mar 2021 15:32:24 +0100 Subject: [PATCH] Update the wording for unknown URLs in the import flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/forty-dancers-argue.md | 5 +++ .../src/api/CatalogImportClient.test.ts | 6 ++- .../src/api/CatalogImportClient.ts | 41 ++++++++++--------- 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 .changeset/forty-dancers-argue.md diff --git a/.changeset/forty-dancers-argue.md b/.changeset/forty-dancers-argue.md new file mode 100644 index 0000000000..0b30189e88 --- /dev/null +++ b/.changeset/forty-dancers-argue.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-import': patch +--- + +Update the wording for unknown URLs in the import flow diff --git a/plugins/catalog-import/src/api/CatalogImportClient.test.ts b/plugins/catalog-import/src/api/CatalogImportClient.test.ts index c81adfa68e..5187ffab52 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.test.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.test.ts @@ -167,7 +167,11 @@ describe('CatalogImportClient', () => { catalogImportClient.analyzeUrl( 'https://github.com/backstage/backstage', ), - ).rejects.toThrow(new Error('Invalid url')); + ).rejects.toThrow( + new Error( + 'This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a catalog-info.yaml file instead.', + ), + ); }); it('should find locations from github', async () => { diff --git a/plugins/catalog-import/src/api/CatalogImportClient.ts b/plugins/catalog-import/src/api/CatalogImportClient.ts index c4f50efbd4..ccf16e00f1 100644 --- a/plugins/catalog-import/src/api/CatalogImportClient.ts +++ b/plugins/catalog-import/src/api/CatalogImportClient.ts @@ -73,32 +73,33 @@ export class CatalogImportClient implements CatalogImportApi { } const ghConfig = getGithubIntegrationConfig(this.configApi, url); + if (!ghConfig) { + throw new Error( + 'This URL was not recognized as a valid GitHub URL because there was no configured integration that matched the given host name. You could try to paste the full URL to a catalog-info.yaml file instead.', + ); + } - if (ghConfig) { - // TODO: this could be part of the analyze-location endpoint - const locations = await this.checkGitHubForExistingCatalogInfo({ - ...ghConfig, - url, - }); - - if (locations.length > 0) { - return { - type: 'locations', - locations, - }; - } + // TODO: this could be part of the analyze-location endpoint + const locations = await this.checkGitHubForExistingCatalogInfo({ + ...ghConfig, + url, + }); + if (locations.length > 0) { return { - type: 'repository', - integrationType: 'github', - url: url, - generatedEntities: await this.generateEntityDefinitions({ - repo: url, - }), + type: 'locations', + locations, }; } - throw new Error('Invalid url'); + return { + type: 'repository', + integrationType: 'github', + url: url, + generatedEntities: await this.generateEntityDefinitions({ + repo: url, + }), + }; } async submitPullRequest({