invert the control on the analyzer support

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2022-10-03 19:55:50 +02:00
parent a18c07d308
commit ce865b69cf
3 changed files with 8 additions and 7 deletions
@@ -20,7 +20,6 @@ import { Octokit } from '@octokit/rest';
import { trimEnd } from 'lodash';
import parseGitUrl from 'git-url-parse';
import {
AnalyzeLocationExistingEntity,
AnalyzeOptions,
ScmLocationAnalyzer,
} from '@backstage/plugin-catalog-backend';
@@ -41,8 +40,10 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer {
this.config = options.config;
this.catalogClient = new CatalogClient({ discoveryApi: options.discovery });
}
getIntegrationType() {
return 'github';
supports(url: string) {
const integrations = ScmIntegrations.fromConfig(this.config);
const integration = integrations.byUrl(url);
return integration?.type === 'github';
}
async analyze({ url, catalogFilename }: AnalyzeOptions) {
const { owner, name: repo } = parseGitUrl(url);
@@ -63,8 +63,8 @@ export class RepoLocationAnalyzer implements LocationAnalyzer {
break;
}
const analyzer = this.analyzers.find(
a => a.getIntegrationType() === integration?.type,
const analyzer = this.analyzers.find(a =>
a.supports(request.location.target),
);
if (analyzer) {
const analyzerResult = await analyzer.analyze({
@@ -108,8 +108,8 @@ export type AnalyzeOptions = {
/** @public */
export type ScmLocationAnalyzer = {
/** The integration type this location analyzer can work with */
getIntegrationType(): string;
/** The method that decides if this analyzer can work with the provided url */
supports(url: string): boolean;
/** This function can return an array of already existing entities */
analyze(options: AnalyzeOptions): Promise<{
existing: AnalyzeLocationExistingEntity[];