Fix code review suggestions in catalog-backend

This commit is contained in:
Marek Calus
2020-11-09 19:26:22 +01:00
parent 2361177d4e
commit 778b946e5c
3 changed files with 11 additions and 9 deletions
@@ -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<AnalyzeLocationResponse> {
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: [] }],
@@ -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
@@ -47,7 +47,7 @@ export async function createRouter(
entitiesCatalog,
locationsCatalog,
higherOrderOperation,
locationAnalyzer: locationAnalyzer,
locationAnalyzer,
} = options;
const router = Router();