Modifications based on PR comments
Signed-off-by: irma12 <irma@roadie.io>
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
---
|
||||
'example-app': patch
|
||||
'example-backend': patch
|
||||
'@backstage/plugin-scorecards': patch
|
||||
'@backstage/plugin-tech-insights-backend': patch
|
||||
'@backstage/plugin-tech-insights-common': patch
|
||||
---
|
||||
@@ -13,16 +13,6 @@ cd packages/app
|
||||
yarn add @backstage/plugin-scorecards
|
||||
```
|
||||
|
||||
### Adding the plugin to your `packages/app`
|
||||
|
||||
```tsx
|
||||
// In packages/app/src/App.tsx
|
||||
|
||||
import { EntityScorecardContent } from '@backstage/plugin-scorecards';
|
||||
|
||||
<Route path="/scorecards" element={<EntityScorecardContent />} />;
|
||||
```
|
||||
|
||||
### Add Scorecards overview page to the EntityPage:
|
||||
|
||||
```tsx
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
"react-use": "^17.2.4",
|
||||
"react-router-dom": "6.0.0-beta.0",
|
||||
"@backstage/plugin-catalog-react": "^0.6.2",
|
||||
"@backstage/plugin-tech-insights-common": "^0.1.0"
|
||||
"@backstage/plugin-tech-insights-common": "^0.1.0",
|
||||
"@backstage/catalog-model": "^0.9.7",
|
||||
"@backstage/errors": "^0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.8.2",
|
||||
|
||||
@@ -18,6 +18,7 @@ import { createApiRef } from '@backstage/core-plugin-api';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { Check } from './types';
|
||||
import { CheckResultRenderer } from '../components/CheckResultRenderer';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
|
||||
export const scorecardsApiRef = createApiRef<ScorecardsApi>({
|
||||
id: 'plugin.scorecards.service',
|
||||
@@ -30,15 +31,5 @@ export interface ScorecardsApi {
|
||||
value: CheckResult[],
|
||||
) => CheckResultRenderer | undefined;
|
||||
getAllChecks(): Promise<Check[]>;
|
||||
runChecks({
|
||||
namespace,
|
||||
kind,
|
||||
name,
|
||||
checks,
|
||||
}: {
|
||||
namespace: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
checks?: Check[];
|
||||
}): Promise<CheckResult[]>;
|
||||
runChecks(entityParams: EntityName, checks?: Check[]): Promise<CheckResult[]>;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ import { ScorecardsApi } from './ScorecardsApi';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { Check } from './types';
|
||||
import { DiscoveryApi } from '@backstage/core-plugin-api';
|
||||
import { ResponseError } from '@backstage/errors';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
|
||||
import {
|
||||
CheckResultRenderer,
|
||||
defaultCheckResultRenderers,
|
||||
@@ -30,7 +33,6 @@ export type Options = {
|
||||
|
||||
export class ScorecardsClient implements ScorecardsApi {
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
private baseUrl: string = '';
|
||||
|
||||
constructor(options: Options) {
|
||||
this.discoveryApi = options.discoveryApi;
|
||||
@@ -44,39 +46,27 @@ export class ScorecardsClient implements ScorecardsApi {
|
||||
return resultRenderers.find(d => d.type === type);
|
||||
}
|
||||
|
||||
getBaseUrl: () => Promise<string> = async () => {
|
||||
if (!this.baseUrl) {
|
||||
this.baseUrl = await this.discoveryApi.getBaseUrl('tech-insights');
|
||||
}
|
||||
return this.baseUrl;
|
||||
};
|
||||
|
||||
async getAllChecks(): Promise<Check[]> {
|
||||
const url = await this.getBaseUrl();
|
||||
const allChecks = await fetch(`${url}/checks`);
|
||||
const payload = await allChecks.json();
|
||||
if (!allChecks.ok) {
|
||||
throw new Error(payload.errors[0]);
|
||||
const url = await this.discoveryApi.getBaseUrl('tech-insights');
|
||||
const response = await fetch(`${url}/checks`);
|
||||
if (!response.ok) {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
return payload;
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
async runChecks({
|
||||
namespace,
|
||||
kind,
|
||||
name,
|
||||
checks,
|
||||
}: {
|
||||
namespace: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
checks: Check[];
|
||||
}): Promise<CheckResult[]> {
|
||||
const url = await this.getBaseUrl();
|
||||
async runChecks(
|
||||
entityParams: EntityName,
|
||||
checks: Check[],
|
||||
): Promise<CheckResult[]> {
|
||||
const url = await this.discoveryApi.getBaseUrl('tech-insights');
|
||||
const { namespace, kind, name } = entityParams;
|
||||
const allChecks = checks ? checks : await this.getAllChecks();
|
||||
const checkIds = allChecks.map((check: Check) => check.id);
|
||||
const response = await fetch(
|
||||
`${url}/checks/run/${namespace}/${kind}/${name}`,
|
||||
`${url}/checks/run/${encodeURIComponent(namespace)}/${encodeURIComponent(
|
||||
kind,
|
||||
)}/${encodeURIComponent(name)}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ checks: checkIds }),
|
||||
@@ -85,7 +75,9 @@ export class ScorecardsClient implements ScorecardsApi {
|
||||
},
|
||||
},
|
||||
);
|
||||
const result = await response.json();
|
||||
return result;
|
||||
if (!response.ok) {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import { rootRouteRef } from './routes';
|
||||
import { scorecardsApiRef } from './api/ScorecardsApi';
|
||||
import { ScorecardsClient } from './api';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const scorecardsPlugin = createPlugin({
|
||||
id: 'scorecards',
|
||||
apis: [
|
||||
@@ -37,6 +40,9 @@ export const scorecardsPlugin = createPlugin({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const EntityScorecardContent = scorecardsPlugin.provide(
|
||||
createRoutableExtension({
|
||||
name: 'EntityScorecardContent',
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
import { createRouteRef } from '@backstage/core-plugin-api';
|
||||
|
||||
export const rootRouteRef = createRouteRef({
|
||||
title: 'scorecards',
|
||||
id: 'scorecards',
|
||||
});
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/luxon": "^2.0.5",
|
||||
"luxon": "^2.0.2"
|
||||
"luxon": "^2.0.2",
|
||||
"@backstage/types": "^0.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.9.0"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -112,7 +113,7 @@ export type FactResponse = {
|
||||
export type CheckResult = {
|
||||
facts: FactResponse;
|
||||
check: CheckResponse;
|
||||
result: any;
|
||||
result: JsonValue;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user