make the return of analyze an object
Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
@@ -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',
|
||||
});
|
||||
|
||||
@@ -44,10 +44,7 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer {
|
||||
getIntegrationType() {
|
||||
return 'github';
|
||||
}
|
||||
async analyze({
|
||||
url,
|
||||
catalogFilename,
|
||||
}: AnalyzeOptions): Promise<AnalyzeLocationExistingEntity[]> {
|
||||
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: [] };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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<AnalyzeLocationExistingEntity[]>;
|
||||
/** This function can return an array of already existing entities */
|
||||
analyze(options: AnalyzeOptions): Promise<{
|
||||
existing: AnalyzeLocationExistingEntity[];
|
||||
}>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user