do not change public facing api
Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
@@ -18,7 +18,6 @@ import { CatalogProcessorParser } from '@backstage/plugin-catalog-node';
|
||||
import { CatalogProcessorRefreshKeysResult } from '@backstage/plugin-catalog-node';
|
||||
import { CatalogProcessorRelationResult } from '@backstage/plugin-catalog-node';
|
||||
import { CatalogProcessorResult } from '@backstage/plugin-catalog-node';
|
||||
import { CompoundEntityRef } from '@backstage/catalog-model';
|
||||
import { ConditionalPolicyDecision } from '@backstage/plugin-permission-common';
|
||||
import { Conditions } from '@backstage/plugin-permission-node';
|
||||
import { Config } from '@backstage/config';
|
||||
@@ -65,9 +64,9 @@ export type AnalyzeLocationEntityField = {
|
||||
|
||||
// @public
|
||||
export type AnalyzeLocationExistingEntity = {
|
||||
target: string;
|
||||
exists: boolean | undefined;
|
||||
entities: CompoundEntityRef[];
|
||||
location: LocationSpec;
|
||||
isRegistered: boolean;
|
||||
entity: Entity;
|
||||
};
|
||||
|
||||
// @public
|
||||
|
||||
@@ -24,7 +24,6 @@ import { AnalyzeLocationExistingEntity, ScmLocationAnalyzer } from './types';
|
||||
export type GitHubLocationAnalyzerOptions = {
|
||||
integration: GitHubIntegration;
|
||||
catalogFilename?: string;
|
||||
|
||||
discovery: DiscoveryApi;
|
||||
};
|
||||
export class GitHubLocationAnalyzer implements ScmLocationAnalyzer {
|
||||
@@ -62,26 +61,24 @@ export class GitHubLocationAnalyzer implements ScmLocationAnalyzer {
|
||||
});
|
||||
const defaultBranch = repoInformation.data.default_branch;
|
||||
|
||||
return await Promise.all(
|
||||
const result = await Promise.all(
|
||||
searchResult.data.items
|
||||
.map(i => `${trimEnd(url, '/')}/blob/${defaultBranch}/${i.path}`)
|
||||
.map(async target => {
|
||||
const result = await catalogClient.addLocation({
|
||||
const addLocationResult = await catalogClient.addLocation({
|
||||
type: 'url',
|
||||
target,
|
||||
dryRun: true,
|
||||
});
|
||||
return {
|
||||
target,
|
||||
exists: result.exists,
|
||||
entities: result.entities.map(e => ({
|
||||
kind: e.kind,
|
||||
namespace: e.metadata.namespace ?? 'default',
|
||||
name: e.metadata.name,
|
||||
})),
|
||||
};
|
||||
return addLocationResult.entities.map(e => ({
|
||||
location: { type: 'url', target },
|
||||
isRegistered: !!addLocationResult.exists,
|
||||
entity: e,
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
return result.flat();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CompoundEntityRef, Entity } from '@backstage/catalog-model';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { RecursivePartial } from '../util/RecursivePartial';
|
||||
import { LocationSpec } from '@backstage/plugin-catalog-node';
|
||||
|
||||
@@ -50,9 +50,9 @@ export type AnalyzeLocationResponse = {
|
||||
* @public
|
||||
*/
|
||||
export type AnalyzeLocationExistingEntity = {
|
||||
target: string;
|
||||
exists: boolean | undefined;
|
||||
entities: CompoundEntityRef[];
|
||||
location: LocationSpec;
|
||||
isRegistered: boolean;
|
||||
entity: Entity;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,7 @@ import { AnalyzeResult, CatalogImportApi } from './CatalogImportApi';
|
||||
import { getGithubIntegrationConfig } from './GitHub';
|
||||
import { getBranchName, getCatalogFilename } from '../components/helpers';
|
||||
import { AnalyzeLocationResponse } from '@backstage/plugin-catalog-backend';
|
||||
import { CompoundEntityRef } from '@backstage/catalog-model';
|
||||
|
||||
/**
|
||||
* The default implementation of the {@link CatalogImportApi}.
|
||||
@@ -108,9 +109,35 @@ export class CatalogImportClient implements CatalogImportApi {
|
||||
});
|
||||
|
||||
if (analyzation.existingEntityFiles.length > 0) {
|
||||
const locations = analyzation.existingEntityFiles.reduce<
|
||||
Record<
|
||||
string,
|
||||
{
|
||||
target: string;
|
||||
exists?: boolean;
|
||||
entities: CompoundEntityRef[];
|
||||
}
|
||||
>
|
||||
>((state, curr) => {
|
||||
state[curr.location.target] = {
|
||||
target: curr.location.target,
|
||||
exists: curr.isRegistered,
|
||||
entities: [
|
||||
...(curr.location.target in state
|
||||
? state[curr.location.target].entities
|
||||
: []),
|
||||
{
|
||||
name: curr.entity.metadata.name,
|
||||
namespace: curr.entity.metadata.namespace ?? 'default',
|
||||
kind: curr.entity.kind,
|
||||
},
|
||||
],
|
||||
};
|
||||
return state;
|
||||
}, {});
|
||||
return {
|
||||
type: 'locations',
|
||||
locations: analyzation.existingEntityFiles,
|
||||
locations: Object.values(locations),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user