From a18c07d308616660bea9b38a53aa5fec0021dc11 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Mon, 3 Oct 2022 19:24:36 +0200 Subject: [PATCH] make the return of analyze an object Signed-off-by: Kiss Miklos --- .../src/analyzers/GitHubLocationAnalyzer.test.ts | 6 +++--- .../src/analyzers/GitHubLocationAnalyzer.ts | 9 +++------ .../catalog-backend/src/ingestion/LocationAnalyzer.ts | 6 +++--- plugins/catalog-backend/src/ingestion/types.ts | 6 ++++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts b/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts index 9502c47c6e..0dcc131502 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.test.ts @@ -122,8 +122,8 @@ describe('GitHubLocationAnalyzer', () => { url: 'https://github.com/foo/bar', }); - expect(result[0].isRegistered).toBeFalsy(); - expect(result[0].location).toEqual({ + expect(result.existing[0].isRegistered).toBeFalsy(); + expect(result.existing[0].location).toEqual({ type: 'url', target: 'https://github.com/foo/bar/blob/my_default_branch/catalog-info.yaml', @@ -148,7 +148,7 @@ describe('GitHubLocationAnalyzer', () => { catalogFilename: 'anvil.yaml', }); - expect(result[0].location).toEqual({ + expect(result.existing[0].location).toEqual({ type: 'url', target: 'https://github.com/foo/bar/blob/my_default_branch/anvil.yaml', }); diff --git a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts b/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts index a043b894cd..085f82de49 100644 --- a/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts +++ b/plugins/catalog-backend-module-github/src/analyzers/GitHubLocationAnalyzer.ts @@ -44,10 +44,7 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer { getIntegrationType() { return 'github'; } - async analyze({ - url, - catalogFilename, - }: AnalyzeOptions): Promise { + async analyze({ url, catalogFilename }: AnalyzeOptions) { const { owner, name: repo } = parseGitUrl(url); const catalogFile = catalogFilename || 'catalog-info.yaml'; @@ -98,8 +95,8 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer { }), ); - return result.flat(); + return { existing: result.flat() }; } - return []; + return { existing: [] }; } } diff --git a/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts b/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts index 11f9799759..b863f00f2c 100644 --- a/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts +++ b/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts @@ -67,15 +67,15 @@ export class RepoLocationAnalyzer implements LocationAnalyzer { a => a.getIntegrationType() === integration?.type, ); if (analyzer) { - const existingEntityFiles = await analyzer.analyze({ + const analyzerResult = await analyzer.analyze({ url: request.location.target, }); - if (existingEntityFiles.length > 0) { + if (analyzerResult.existing.length > 0) { this.logger.debug( `entity for ${request.location.target} already exists.`, ); return { - existingEntityFiles, + existingEntityFiles: analyzerResult.existing, generateEntities: [], }; } diff --git a/plugins/catalog-backend/src/ingestion/types.ts b/plugins/catalog-backend/src/ingestion/types.ts index b68a4681b1..40b4574f78 100644 --- a/plugins/catalog-backend/src/ingestion/types.ts +++ b/plugins/catalog-backend/src/ingestion/types.ts @@ -110,6 +110,8 @@ export type AnalyzeOptions = { export type ScmLocationAnalyzer = { /** The integration type this location analyzer can work with */ getIntegrationType(): string; - /** This function is responsible to figure out if the catalog file is already present in the repository */ - analyze(options: AnalyzeOptions): Promise; + /** This function can return an array of already existing entities */ + analyze(options: AnalyzeOptions): Promise<{ + existing: AnalyzeLocationExistingEntity[]; + }>; };