From 778b946e5c7c8e4eae89aa7eaf46993df3e26f2e Mon Sep 17 00:00:00 2001 From: Marek Calus Date: Mon, 9 Nov 2020 19:26:22 +0100 Subject: [PATCH] Fix code review suggestions in catalog-backend --- .../src/ingestion/LocationAnalyzer.ts | 12 +++++++----- plugins/catalog-backend/src/ingestion/types.ts | 6 +++--- plugins/catalog-backend/src/service/router.ts | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts b/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts index 435ed4f872..560a5c0563 100644 --- a/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts +++ b/plugins/catalog-backend/src/ingestion/LocationAnalyzer.ts @@ -15,6 +15,7 @@ */ import { Logger } from 'winston'; +import GitUriParser from 'git-url-parse'; import { AnalyzeLocationRequest, AnalyzeLocationResponse, @@ -30,18 +31,19 @@ export class LocationAnalyzerClient implements LocationAnalyzer { async generateConfig( request: AnalyzeLocationRequest, ): Promise { - const [ownerName, repoName] = request.location.target.split('/').slice(-2); + const { owner, name, source } = GitUriParser(request.location.target); const entity = { apiVersion: 'backstage.io/v1alpha1', kind: 'Component', metadata: { - name: repoName, - annotations: { 'github.com/project-slug': `${ownerName}/${repoName}` }, + name: name, + // Probably won't handle properly self-hosted git providers with custom url + annotations: { [`${source}/project-slug`]: `${owner}/${name}` }, }, - spec: { type: 'service', owner: ownerName, lifecycle: 'experimental' }, + spec: { type: 'other', owner: owner, lifecycle: 'unknown' }, }; - this.logger.silly(`entity created for ${request.location.target}`); + this.logger.debug(`entity created for ${request.location.target}`); return { existingEntityFiles: [], generateEntities: [{ entity, fields: [] }], diff --git a/plugins/catalog-backend/src/ingestion/types.ts b/plugins/catalog-backend/src/ingestion/types.ts index 9645a33140..29308fdd92 100644 --- a/plugins/catalog-backend/src/ingestion/types.ts +++ b/plugins/catalog-backend/src/ingestion/types.ts @@ -121,9 +121,9 @@ type AnalyzeLocationEntityField = { // The outcome of the analysis for this particular field state: - | 'analysis_suggested_value' - | 'analysis_suggested_no_value' - | 'needs_user_input'; + | 'analysisSuggestedValue' + | 'analysisSuggestedNoValue' + | 'needsUserInput'; // If the analysis did suggest a value, this is where it would be. Not sure if we want // to limit this to strings or if we want it to be any JsonValue diff --git a/plugins/catalog-backend/src/service/router.ts b/plugins/catalog-backend/src/service/router.ts index 17c417214f..fd9062bf94 100644 --- a/plugins/catalog-backend/src/service/router.ts +++ b/plugins/catalog-backend/src/service/router.ts @@ -47,7 +47,7 @@ export async function createRouter( entitiesCatalog, locationsCatalog, higherOrderOperation, - locationAnalyzer: locationAnalyzer, + locationAnalyzer, } = options; const router = Router();