diff --git a/.changeset/popular-rules-hang.md b/.changeset/yellow-ladybugs-begin.md
similarity index 76%
rename from .changeset/popular-rules-hang.md
rename to .changeset/yellow-ladybugs-begin.md
index 39bc61481d..abfa4e5b50 100644
--- a/.changeset/popular-rules-hang.md
+++ b/.changeset/yellow-ladybugs-begin.md
@@ -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
---
diff --git a/plugins/scorecards/README.md b/plugins/scorecards/README.md
index 20f096ce24..ddcd6f7bc7 100644
--- a/plugins/scorecards/README.md
+++ b/plugins/scorecards/README.md
@@ -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';
-
-} />;
-```
-
### Add Scorecards overview page to the EntityPage:
```tsx
diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json
index d8de4a1ea0..7fa19792ff 100644
--- a/plugins/scorecards/package.json
+++ b/plugins/scorecards/package.json
@@ -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",
diff --git a/plugins/scorecards/src/api/ScorecardsApi.ts b/plugins/scorecards/src/api/ScorecardsApi.ts
index 83f34d4cf5..3e72975861 100644
--- a/plugins/scorecards/src/api/ScorecardsApi.ts
+++ b/plugins/scorecards/src/api/ScorecardsApi.ts
@@ -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({
id: 'plugin.scorecards.service',
@@ -30,15 +31,5 @@ export interface ScorecardsApi {
value: CheckResult[],
) => CheckResultRenderer | undefined;
getAllChecks(): Promise;
- runChecks({
- namespace,
- kind,
- name,
- checks,
- }: {
- namespace: string;
- kind: string;
- name: string;
- checks?: Check[];
- }): Promise;
+ runChecks(entityParams: EntityName, checks?: Check[]): Promise;
}
diff --git a/plugins/scorecards/src/api/ScorecardsClient.ts b/plugins/scorecards/src/api/ScorecardsClient.ts
index bdfc89dc09..b640cc6347 100644
--- a/plugins/scorecards/src/api/ScorecardsClient.ts
+++ b/plugins/scorecards/src/api/ScorecardsClient.ts
@@ -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 = async () => {
- if (!this.baseUrl) {
- this.baseUrl = await this.discoveryApi.getBaseUrl('tech-insights');
- }
- return this.baseUrl;
- };
-
async getAllChecks(): Promise {
- 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 {
- const url = await this.getBaseUrl();
+ async runChecks(
+ entityParams: EntityName,
+ checks: Check[],
+ ): Promise {
+ 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();
}
}
diff --git a/plugins/scorecards/src/plugin.ts b/plugins/scorecards/src/plugin.ts
index c9f0d47571..4c39b9768f 100644
--- a/plugins/scorecards/src/plugin.ts
+++ b/plugins/scorecards/src/plugin.ts
@@ -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',
diff --git a/plugins/scorecards/src/routes.ts b/plugins/scorecards/src/routes.ts
index c81a4b8eef..484a9c7e2b 100644
--- a/plugins/scorecards/src/routes.ts
+++ b/plugins/scorecards/src/routes.ts
@@ -16,5 +16,5 @@
import { createRouteRef } from '@backstage/core-plugin-api';
export const rootRouteRef = createRouteRef({
- title: 'scorecards',
+ id: 'scorecards',
});
diff --git a/plugins/tech-insights-common/package.json b/plugins/tech-insights-common/package.json
index 26d8922329..2476b120ec 100644
--- a/plugins/tech-insights-common/package.json
+++ b/plugins/tech-insights-common/package.json
@@ -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"
diff --git a/plugins/tech-insights-common/src/index.ts b/plugins/tech-insights-common/src/index.ts
index 5b6e814474..ecdaa298c1 100644
--- a/plugins/tech-insights-common/src/index.ts
+++ b/plugins/tech-insights-common/src/index.ts
@@ -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;
};
/**