From dc62dcab12e72f447ef1241df7e4a718b2bf476c Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 17 Nov 2021 14:28:54 +0100 Subject: [PATCH 01/15] Introduce scorecards Signed-off-by: irma12 --- .changeset/popular-rules-hang.md | 11 +++ packages/app/package.json | 1 + plugins/scorecards/.eslintrc.js | 3 + plugins/scorecards/README.md | 52 +++++++++++ plugins/scorecards/api-report.md | 27 ++++++ plugins/scorecards/dev/index.tsx | 27 ++++++ plugins/scorecards/package.json | 52 +++++++++++ plugins/scorecards/src/api/ScorecardsApi.ts | 44 +++++++++ .../scorecards/src/api/ScorecardsClient.ts | 91 +++++++++++++++++++ plugins/scorecards/src/api/index.ts | 17 ++++ plugins/scorecards/src/api/types.ts | 22 +++++ .../components/BooleanCheck/BooleanCheck.tsx | 62 +++++++++++++ .../src/components/BooleanCheck/index.ts | 17 ++++ .../src/components/CheckResultRenderer.tsx | 40 ++++++++ .../ScorecardsOverview/ChecksOverview.tsx | 66 ++++++++++++++ .../ScorecardsOverview/ScorecardsOverview.tsx | 41 +++++++++ .../components/ScorecardsOverview/index.ts | 17 ++++ plugins/scorecards/src/index.ts | 16 ++++ plugins/scorecards/src/plugin.test.ts | 22 +++++ plugins/scorecards/src/plugin.ts | 47 ++++++++++ plugins/scorecards/src/routes.ts | 20 ++++ plugins/scorecards/src/setupTests.ts | 17 ++++ .../src/service/router.ts | 5 - plugins/tech-insights-common/api-report.md | 1 + plugins/tech-insights-common/src/index.ts | 1 + 25 files changed, 714 insertions(+), 5 deletions(-) create mode 100644 .changeset/popular-rules-hang.md create mode 100644 plugins/scorecards/.eslintrc.js create mode 100644 plugins/scorecards/README.md create mode 100644 plugins/scorecards/api-report.md create mode 100644 plugins/scorecards/dev/index.tsx create mode 100644 plugins/scorecards/package.json create mode 100644 plugins/scorecards/src/api/ScorecardsApi.ts create mode 100644 plugins/scorecards/src/api/ScorecardsClient.ts create mode 100644 plugins/scorecards/src/api/index.ts create mode 100644 plugins/scorecards/src/api/types.ts create mode 100644 plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx create mode 100644 plugins/scorecards/src/components/BooleanCheck/index.ts create mode 100644 plugins/scorecards/src/components/CheckResultRenderer.tsx create mode 100644 plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx create mode 100644 plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx create mode 100644 plugins/scorecards/src/components/ScorecardsOverview/index.ts create mode 100644 plugins/scorecards/src/index.ts create mode 100644 plugins/scorecards/src/plugin.test.ts create mode 100644 plugins/scorecards/src/plugin.ts create mode 100644 plugins/scorecards/src/routes.ts create mode 100644 plugins/scorecards/src/setupTests.ts diff --git a/.changeset/popular-rules-hang.md b/.changeset/popular-rules-hang.md new file mode 100644 index 0000000000..593cfcd3b6 --- /dev/null +++ b/.changeset/popular-rules-hang.md @@ -0,0 +1,11 @@ +--- +'example-app': patch +'example-backend': patch +'@backstage/plugin-scorecards': patch +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-common': patch +--- + +Removed unecessary check in @backstage/plugin-tech-insights-backend + +Added new property 'result' in every CheckResult in @backstage/plugin-tech-insights-common diff --git a/packages/app/package.json b/packages/app/package.json index 9a1fb108f6..82fdeb6d18 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -36,6 +36,7 @@ "@backstage/plugin-pagerduty": "0.3.17", "@backstage/plugin-rollbar": "^0.3.18", "@backstage/plugin-scaffolder": "^0.11.8", + "@backstage/plugin-scorecards": "^0.1.0", "@backstage/plugin-search": "^0.4.15", "@backstage/plugin-sentry": "^0.3.26", "@backstage/plugin-shortcuts": "^0.1.12", diff --git a/plugins/scorecards/.eslintrc.js b/plugins/scorecards/.eslintrc.js new file mode 100644 index 0000000000..13573efa9c --- /dev/null +++ b/plugins/scorecards/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: [require.resolve('@backstage/cli/config/eslint')], +}; diff --git a/plugins/scorecards/README.md b/plugins/scorecards/README.md new file mode 100644 index 0000000000..2ff9aaf1ab --- /dev/null +++ b/plugins/scorecards/README.md @@ -0,0 +1,52 @@ +# Scorecards + +This plugin represents scorecards which are rendered as a part of the default Backstage Tech Insights feature. +It provides UI for the scorecards as well as a check overview. + +## Installation + +### Install the plugin + +```bash +# From your Backstage root directory +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'; + +} />; +``` + +3. Add Scorecards overview page to the EntityPage: + +```tsx +// packages/app/src/components/catalog/EntityPage.tsx + +import { EntityScorecardContent } from '@backstage/plugin-scorecards'; + +const serviceEntityPage = ( + + + {overviewContent} + + + {cicdContent} + + ... + + + + ... + +); +``` + +## Links + +- [The Backstage homepage](https://backstage.io) diff --git a/plugins/scorecards/api-report.md b/plugins/scorecards/api-report.md new file mode 100644 index 0000000000..eb3ce4533b --- /dev/null +++ b/plugins/scorecards/api-report.md @@ -0,0 +1,27 @@ +## API Report File for "@backstage/plugin-scorecards" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { RouteRef } from '@backstage/core-plugin-api'; + +// Warning: (ae-missing-release-tag) "EntityScorecardContent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const EntityScorecardContent: () => JSX.Element; + +// Warning: (ae-missing-release-tag) "scorecardsPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) +// +// @public (undocumented) +export const scorecardsPlugin: BackstagePlugin< + { + root: RouteRef; + }, + {} +>; + +// (No @packageDocumentation comment for this package) +``` diff --git a/plugins/scorecards/dev/index.tsx b/plugins/scorecards/dev/index.tsx new file mode 100644 index 0000000000..559e92b969 --- /dev/null +++ b/plugins/scorecards/dev/index.tsx @@ -0,0 +1,27 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import React from 'react'; +import { createDevApp } from '@backstage/dev-utils'; +import { scorecardsPlugin, EntityScorecardContent } from '../src/plugin'; + +createDevApp() + .registerPlugin(scorecardsPlugin) + .addPage({ + element: , + title: 'Root Page', + path: '/scorecards', + }) + .render(); diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json new file mode 100644 index 0000000000..4d104410da --- /dev/null +++ b/plugins/scorecards/package.json @@ -0,0 +1,52 @@ +{ + "name": "@backstage/plugin-scorecards", + "version": "0.1.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public", + "main": "dist/index.esm.js", + "types": "dist/index.d.ts" + }, + "scripts": { + "build": "backstage-cli plugin:build", + "start": "backstage-cli plugin:serve", + "lint": "backstage-cli lint", + "test": "backstage-cli test", + "diff": "backstage-cli plugin:diff", + "prepack": "backstage-cli prepack", + "postpack": "backstage-cli postpack", + "clean": "backstage-cli clean" + }, + "dependencies": { + "@backstage/core-components": "^0.7.2", + "@backstage/core-plugin-api": "^0.1.12", + "@backstage/theme": "^0.2.12", + "@material-ui/core": "^4.12.2", + "@material-ui/icons": "^4.9.1", + "@material-ui/lab": "4.0.0-alpha.57", + "react": "^16.13.1", + "react-dom": "^16.13.1", + "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" + }, + "devDependencies": { + "@backstage/cli": "^0.8.1", + "@backstage/core-app-api": "^0.1.19", + "@backstage/dev-utils": "^0.2.12", + "@backstage/test-utils": "^0.1.20", + "@testing-library/jest-dom": "^5.10.1", + "@testing-library/react": "^11.2.5", + "@testing-library/user-event": "^13.1.8", + "@types/jest": "*", + "@types/node": "*", + "msw": "^0.35.0", + "cross-fetch": "^3.0.6" + }, + "files": [ + "dist" + ] +} diff --git a/plugins/scorecards/src/api/ScorecardsApi.ts b/plugins/scorecards/src/api/ScorecardsApi.ts new file mode 100644 index 0000000000..83f34d4cf5 --- /dev/null +++ b/plugins/scorecards/src/api/ScorecardsApi.ts @@ -0,0 +1,44 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createApiRef } from '@backstage/core-plugin-api'; +import { CheckResult } from '@backstage/plugin-tech-insights-common'; +import { Check } from './types'; +import { CheckResultRenderer } from '../components/CheckResultRenderer'; + +export const scorecardsApiRef = createApiRef({ + id: 'plugin.scorecards.service', + description: 'Used by the scorecards plugin to make requests', +}); + +export interface ScorecardsApi { + getScorecardsDefinition: ( + type: string, + value: CheckResult[], + ) => CheckResultRenderer | undefined; + getAllChecks(): Promise; + runChecks({ + namespace, + kind, + name, + checks, + }: { + namespace: string; + kind: string; + name: string; + checks?: Check[]; + }): Promise; +} diff --git a/plugins/scorecards/src/api/ScorecardsClient.ts b/plugins/scorecards/src/api/ScorecardsClient.ts new file mode 100644 index 0000000000..bdfc89dc09 --- /dev/null +++ b/plugins/scorecards/src/api/ScorecardsClient.ts @@ -0,0 +1,91 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ScorecardsApi } from './ScorecardsApi'; +import { CheckResult } from '@backstage/plugin-tech-insights-common'; +import { Check } from './types'; +import { DiscoveryApi } from '@backstage/core-plugin-api'; +import { + CheckResultRenderer, + defaultCheckResultRenderers, +} from '../components/CheckResultRenderer'; + +export type Options = { + discoveryApi: DiscoveryApi; + proxyPath?: string; +}; + +export class ScorecardsClient implements ScorecardsApi { + private readonly discoveryApi: DiscoveryApi; + private baseUrl: string = ''; + + constructor(options: Options) { + this.discoveryApi = options.discoveryApi; + } + + getScorecardsDefinition( + type: string, + value: CheckResult[], + ): CheckResultRenderer | undefined { + const resultRenderers = defaultCheckResultRenderers(value); + 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]); + } + return payload; + } + + async runChecks({ + namespace, + kind, + name, + checks, + }: { + namespace: string; + kind: string; + name: string; + checks: Check[]; + }): Promise { + const url = await this.getBaseUrl(); + 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}`, + { + method: 'POST', + body: JSON.stringify({ checks: checkIds }), + headers: { + 'Content-Type': 'application/json', + }, + }, + ); + const result = await response.json(); + return result; + } +} diff --git a/plugins/scorecards/src/api/index.ts b/plugins/scorecards/src/api/index.ts new file mode 100644 index 0000000000..afebc5432f --- /dev/null +++ b/plugins/scorecards/src/api/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export * from './ScorecardsApi'; +export * from './ScorecardsClient'; diff --git a/plugins/scorecards/src/api/types.ts b/plugins/scorecards/src/api/types.ts new file mode 100644 index 0000000000..20071ba0c9 --- /dev/null +++ b/plugins/scorecards/src/api/types.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export type Check = { + id: string; + type: string; + name: string; + description: string; + factIds: string[]; +}; diff --git a/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx b/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx new file mode 100644 index 0000000000..3920538983 --- /dev/null +++ b/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx @@ -0,0 +1,62 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { makeStyles, List, ListItem, ListItemText } from '@material-ui/core'; +import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; +import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline'; +import { CheckResult } from '@backstage/plugin-tech-insights-common'; + +const useStyles = makeStyles(() => ({ + listItemText: { + paddingRight: '1rem', + flex: '0 1 auto', + }, + icon: { + marginLeft: 'auto', + }, +})); + +type Prop = { + checkResult: CheckResult[]; +}; + +const renderResult = (classes: any, result: Boolean) => { + return result ? ( + + ) : ( + + ); +}; + +export const BooleanCheck = ({ checkResult }: Prop) => { + const classes = useStyles(); + + return ( + + {checkResult!.map(check => ( + + + {renderResult(classes, check.result)} + + ))} + + ); +}; diff --git a/plugins/scorecards/src/components/BooleanCheck/index.ts b/plugins/scorecards/src/components/BooleanCheck/index.ts new file mode 100644 index 0000000000..729ab4d62e --- /dev/null +++ b/plugins/scorecards/src/components/BooleanCheck/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { BooleanCheck } from './BooleanCheck'; diff --git a/plugins/scorecards/src/components/CheckResultRenderer.tsx b/plugins/scorecards/src/components/CheckResultRenderer.tsx new file mode 100644 index 0000000000..adac458d74 --- /dev/null +++ b/plugins/scorecards/src/components/CheckResultRenderer.tsx @@ -0,0 +1,40 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { CheckResult } from '@backstage/plugin-tech-insights-common'; +import React from 'react'; +import { BooleanCheck } from './BooleanCheck'; + +export type CheckResultRenderer = { + type: string; + title: string; + description: string; + component: React.ReactElement; +}; + +export function defaultCheckResultRenderers( + value: CheckResult[], +): CheckResultRenderer[] { + return [ + { + type: 'json-rules-engine', + title: 'Boolean scorecard', + description: + 'This card represents an overview of default boolean checks:', + component: , + }, + ]; +} diff --git a/plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx b/plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx new file mode 100644 index 0000000000..3c66226da9 --- /dev/null +++ b/plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx @@ -0,0 +1,66 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { makeStyles, Grid, Typography } from '@material-ui/core'; +import { useApi } from '@backstage/core-plugin-api'; +import { Content, Page, InfoCard } from '@backstage/core-components'; +import { CheckResult } from '@backstage/plugin-tech-insights-common'; +import { scorecardsApiRef } from '../../api/ScorecardsApi'; + +const useStyles = makeStyles(() => ({ + contentScorecards: { + paddingLeft: 0, + paddingRight: 0, + }, + subheader: { + fontWeight: 'bold', + }, +})); + +type Checks = { + checks: CheckResult[]; +}; + +export const ChecksOverview = ({ checks }: Checks) => { + const classes = useStyles(); + const api = useApi(scorecardsApiRef); + const checkRenderType = api.getScorecardsDefinition( + checks[0].check.type, + checks, + ); + + if (checkRenderType) { + return ( + + + + + + {checkRenderType.description} + + + {checkRenderType.component} + + + + + + ); + } + + return <>; +}; diff --git a/plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx b/plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx new file mode 100644 index 0000000000..7bfd57be72 --- /dev/null +++ b/plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx @@ -0,0 +1,41 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { useParams } from 'react-router-dom'; +import { useAsync } from 'react-use'; +import { Progress } from '@backstage/core-components'; +import { useApi } from '@backstage/core-plugin-api'; +import { ChecksOverview } from './ChecksOverview'; +import Alert from '@material-ui/lab/Alert'; +import { scorecardsApiRef } from '../../api/ScorecardsApi'; + +export const ScorecardsOverview = () => { + const api = useApi(scorecardsApiRef); + const { namespace, kind, name } = useParams(); + + const { value, loading, error } = useAsync( + async () => await api.runChecks({ namespace, kind, name }), + ); + + if (loading) { + return ; + } else if (error) { + return {error.message}; + } + + return ; +}; diff --git a/plugins/scorecards/src/components/ScorecardsOverview/index.ts b/plugins/scorecards/src/components/ScorecardsOverview/index.ts new file mode 100644 index 0000000000..64198790d9 --- /dev/null +++ b/plugins/scorecards/src/components/ScorecardsOverview/index.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export { ScorecardsOverview } from './ScorecardsOverview'; diff --git a/plugins/scorecards/src/index.ts b/plugins/scorecards/src/index.ts new file mode 100644 index 0000000000..cba54febcf --- /dev/null +++ b/plugins/scorecards/src/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { scorecardsPlugin, EntityScorecardContent } from './plugin'; diff --git a/plugins/scorecards/src/plugin.test.ts b/plugins/scorecards/src/plugin.test.ts new file mode 100644 index 0000000000..537a6399bf --- /dev/null +++ b/plugins/scorecards/src/plugin.test.ts @@ -0,0 +1,22 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { scorecardsPlugin } from './plugin'; + +describe('scorecards', () => { + it('should export plugin', () => { + expect(scorecardsPlugin).toBeDefined(); + }); +}); diff --git a/plugins/scorecards/src/plugin.ts b/plugins/scorecards/src/plugin.ts new file mode 100644 index 0000000000..c9f0d47571 --- /dev/null +++ b/plugins/scorecards/src/plugin.ts @@ -0,0 +1,47 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { + createPlugin, + createRoutableExtension, + createApiFactory, + discoveryApiRef, +} from '@backstage/core-plugin-api'; +import { rootRouteRef } from './routes'; +import { scorecardsApiRef } from './api/ScorecardsApi'; +import { ScorecardsClient } from './api'; + +export const scorecardsPlugin = createPlugin({ + id: 'scorecards', + apis: [ + createApiFactory({ + api: scorecardsApiRef, + deps: { discoveryApi: discoveryApiRef }, + factory: ({ discoveryApi }) => new ScorecardsClient({ discoveryApi }), + }), + ], + routes: { + root: rootRouteRef, + }, +}); + +export const EntityScorecardContent = scorecardsPlugin.provide( + createRoutableExtension({ + name: 'EntityScorecardContent', + component: () => + import('./components/ScorecardsOverview').then(m => m.ScorecardsOverview), + mountPoint: rootRouteRef, + }), +); diff --git a/plugins/scorecards/src/routes.ts b/plugins/scorecards/src/routes.ts new file mode 100644 index 0000000000..c81a4b8eef --- /dev/null +++ b/plugins/scorecards/src/routes.ts @@ -0,0 +1,20 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createRouteRef } from '@backstage/core-plugin-api'; + +export const rootRouteRef = createRouteRef({ + title: 'scorecards', +}); diff --git a/plugins/scorecards/src/setupTests.ts b/plugins/scorecards/src/setupTests.ts new file mode 100644 index 0000000000..fc6dbd98f8 --- /dev/null +++ b/plugins/scorecards/src/setupTests.ts @@ -0,0 +1,17 @@ +/* + * Copyright 2021 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import '@testing-library/jest-dom'; +import 'cross-fetch/polyfill'; diff --git a/plugins/tech-insights-backend/src/service/router.ts b/plugins/tech-insights-backend/src/service/router.ts index a8951318ea..80902c307c 100644 --- a/plugins/tech-insights-backend/src/service/router.ts +++ b/plugins/tech-insights-backend/src/service/router.ts @@ -92,11 +92,6 @@ export async function createRouter< router.post('/checks/run/:namespace/:kind/:name', async (req, res) => { const { namespace, kind, name } = req.params; try { - if (!('checks' in req.body)) { - return res.status(422).send({ - message: 'Failed to get checks from request.', - }); - } const { checks }: { checks: string[] } = req.body; const entityTriplet = stringifyEntityRef({ namespace, kind, name }); const checkResult = await factChecker.runChecks(entityTriplet, checks); diff --git a/plugins/tech-insights-common/api-report.md b/plugins/tech-insights-common/api-report.md index ddb38cfa85..3c806daa57 100644 --- a/plugins/tech-insights-common/api-report.md +++ b/plugins/tech-insights-common/api-report.md @@ -25,6 +25,7 @@ export interface CheckResponse { export type CheckResult = { facts: FactResponse; check: CheckResponse; + result: any; }; // @public diff --git a/plugins/tech-insights-common/src/index.ts b/plugins/tech-insights-common/src/index.ts index 4bfc660748..5b6e814474 100644 --- a/plugins/tech-insights-common/src/index.ts +++ b/plugins/tech-insights-common/src/index.ts @@ -112,6 +112,7 @@ export type FactResponse = { export type CheckResult = { facts: FactResponse; check: CheckResponse; + result: any; }; /** From d8e598adc1d2cd5a90a06336a07449be801b8b30 Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 17 Nov 2021 14:33:11 +0100 Subject: [PATCH 02/15] Small fix Signed-off-by: irma12 --- plugins/scorecards/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scorecards/README.md b/plugins/scorecards/README.md index 2ff9aaf1ab..20f096ce24 100644 --- a/plugins/scorecards/README.md +++ b/plugins/scorecards/README.md @@ -23,7 +23,7 @@ import { EntityScorecardContent } from '@backstage/plugin-scorecards'; } />; ``` -3. Add Scorecards overview page to the EntityPage: +### Add Scorecards overview page to the EntityPage: ```tsx // packages/app/src/components/catalog/EntityPage.tsx From b8d536df8c386de9e547b6863693ca871b60a75e Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 17 Nov 2021 14:38:20 +0100 Subject: [PATCH 03/15] fix spelling in changeset Signed-off-by: irma12 --- .changeset/popular-rules-hang.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/popular-rules-hang.md b/.changeset/popular-rules-hang.md index 593cfcd3b6..39bc61481d 100644 --- a/.changeset/popular-rules-hang.md +++ b/.changeset/popular-rules-hang.md @@ -6,6 +6,6 @@ '@backstage/plugin-tech-insights-common': patch --- -Removed unecessary check in @backstage/plugin-tech-insights-backend +Removed unnecessary check in @backstage/plugin-tech-insights-backend. -Added new property 'result' in every CheckResult in @backstage/plugin-tech-insights-common +Added new property 'result' in every CheckResult in @backstage/plugin-tech-insights-common. From 89622c6ae292d7f3c2beff73e5abe3e4f543a0dd Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 17 Nov 2021 15:16:02 +0100 Subject: [PATCH 04/15] update packages Signed-off-by: irma12 --- plugins/scorecards/package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json index 4d104410da..d8de4a1ea0 100644 --- a/plugins/scorecards/package.json +++ b/plugins/scorecards/package.json @@ -20,9 +20,9 @@ "clean": "backstage-cli clean" }, "dependencies": { - "@backstage/core-components": "^0.7.2", - "@backstage/core-plugin-api": "^0.1.12", - "@backstage/theme": "^0.2.12", + "@backstage/core-components": "^0.7.3", + "@backstage/core-plugin-api": "^0.1.13", + "@backstage/theme": "^0.2.13", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.57", @@ -34,15 +34,15 @@ "@backstage/plugin-tech-insights-common": "^0.1.0" }, "devDependencies": { - "@backstage/cli": "^0.8.1", - "@backstage/core-app-api": "^0.1.19", + "@backstage/cli": "^0.8.2", + "@backstage/core-app-api": "^0.1.20", "@backstage/dev-utils": "^0.2.12", - "@backstage/test-utils": "^0.1.20", + "@backstage/test-utils": "^0.1.21", "@testing-library/jest-dom": "^5.10.1", "@testing-library/react": "^11.2.5", "@testing-library/user-event": "^13.1.8", - "@types/jest": "*", - "@types/node": "*", + "@types/jest": "^26.0.7", + "@types/node": "^14.14.32", "msw": "^0.35.0", "cross-fetch": "^3.0.6" }, From 883fd2f3a58367e3e9437a24e82847a68dff1d3d Mon Sep 17 00:00:00 2001 From: irma12 Date: Tue, 23 Nov 2021 12:50:01 +0100 Subject: [PATCH 05/15] Modifications based on PR comments Signed-off-by: irma12 --- ...rules-hang.md => yellow-ladybugs-begin.md} | 3 -- plugins/scorecards/README.md | 10 ---- plugins/scorecards/package.json | 4 +- plugins/scorecards/src/api/ScorecardsApi.ts | 13 +---- .../scorecards/src/api/ScorecardsClient.ts | 50 ++++++++----------- plugins/scorecards/src/plugin.ts | 6 +++ plugins/scorecards/src/routes.ts | 2 +- plugins/tech-insights-common/package.json | 3 +- plugins/tech-insights-common/src/index.ts | 3 +- 9 files changed, 37 insertions(+), 57 deletions(-) rename .changeset/{popular-rules-hang.md => yellow-ladybugs-begin.md} (76%) 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; }; /** From f6429efb828e4eff0abe4168777022647a81cdfb Mon Sep 17 00:00:00 2001 From: irma12 Date: Tue, 23 Nov 2021 13:06:55 +0100 Subject: [PATCH 06/15] Fix type of check to JsonValue Signed-off-by: irma12 --- plugins/scorecards/package.json | 3 ++- .../scorecards/src/components/BooleanCheck/BooleanCheck.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json index 7fa19792ff..392216c27d 100644 --- a/plugins/scorecards/package.json +++ b/plugins/scorecards/package.json @@ -33,7 +33,8 @@ "@backstage/plugin-catalog-react": "^0.6.2", "@backstage/plugin-tech-insights-common": "^0.1.0", "@backstage/catalog-model": "^0.9.7", - "@backstage/errors": "^0.1.4" + "@backstage/errors": "^0.1.4", + "@backstage/types": "^0.1.1" }, "devDependencies": { "@backstage/cli": "^0.8.2", diff --git a/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx b/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx index 3920538983..a10730ce7b 100644 --- a/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx +++ b/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx @@ -19,6 +19,7 @@ import { makeStyles, List, ListItem, ListItemText } from '@material-ui/core'; import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; +import { JsonValue } from '@backstage/types'; const useStyles = makeStyles(() => ({ listItemText: { @@ -34,7 +35,7 @@ type Prop = { checkResult: CheckResult[]; }; -const renderResult = (classes: any, result: Boolean) => { +const renderResult = (classes: any, result: JsonValue) => { return result ? ( ) : ( From 289de3ab347a85813cf46ed45509fa8e2383200f Mon Sep 17 00:00:00 2001 From: irma12 Date: Tue, 23 Nov 2021 15:37:16 +0100 Subject: [PATCH 07/15] Update cli package Signed-off-by: irma12 --- plugins/scorecards/package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json index 392216c27d..c0c25f67d4 100644 --- a/plugins/scorecards/package.json +++ b/plugins/scorecards/package.json @@ -20,8 +20,8 @@ "clean": "backstage-cli clean" }, "dependencies": { - "@backstage/core-components": "^0.7.3", - "@backstage/core-plugin-api": "^0.1.13", + "@backstage/core-components": "^0.7.4", + "@backstage/core-plugin-api": "^0.2.0", "@backstage/theme": "^0.2.13", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", @@ -30,17 +30,17 @@ "react-dom": "^16.13.1", "react-use": "^17.2.4", "react-router-dom": "6.0.0-beta.0", - "@backstage/plugin-catalog-react": "^0.6.2", + "@backstage/plugin-catalog-react": "^0.6.4", "@backstage/plugin-tech-insights-common": "^0.1.0", "@backstage/catalog-model": "^0.9.7", "@backstage/errors": "^0.1.4", "@backstage/types": "^0.1.1" }, "devDependencies": { - "@backstage/cli": "^0.8.2", - "@backstage/core-app-api": "^0.1.20", - "@backstage/dev-utils": "^0.2.12", - "@backstage/test-utils": "^0.1.21", + "@backstage/cli": "^0.9.0", + "@backstage/core-app-api": "^0.1.22", + "@backstage/dev-utils": "^0.2.13", + "@backstage/test-utils": "^0.1.22", "@testing-library/jest-dom": "^5.10.1", "@testing-library/react": "^11.2.5", "@testing-library/user-event": "^13.1.8", From c39cf20e1f25ebe1f137e8a4fac0473623325596 Mon Sep 17 00:00:00 2001 From: irma12 Date: Tue, 23 Nov 2021 15:51:19 +0100 Subject: [PATCH 08/15] Add API reports Signed-off-by: irma12 --- plugins/scorecards/api-report.md | 4 ---- plugins/tech-insights-common/api-report.md | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/scorecards/api-report.md b/plugins/scorecards/api-report.md index eb3ce4533b..705cce373e 100644 --- a/plugins/scorecards/api-report.md +++ b/plugins/scorecards/api-report.md @@ -8,13 +8,9 @@ import { BackstagePlugin } from '@backstage/core-plugin-api'; import { RouteRef } from '@backstage/core-plugin-api'; -// Warning: (ae-missing-release-tag) "EntityScorecardContent" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const EntityScorecardContent: () => JSX.Element; -// Warning: (ae-missing-release-tag) "scorecardsPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) -// // @public (undocumented) export const scorecardsPlugin: BackstagePlugin< { diff --git a/plugins/tech-insights-common/api-report.md b/plugins/tech-insights-common/api-report.md index 3c806daa57..8618f6266b 100644 --- a/plugins/tech-insights-common/api-report.md +++ b/plugins/tech-insights-common/api-report.md @@ -4,6 +4,7 @@ ```ts import { DateTime } from 'luxon'; +import { JsonValue } from '@backstage/types'; // @public export interface BooleanCheckResult extends CheckResult { @@ -25,7 +26,7 @@ export interface CheckResponse { export type CheckResult = { facts: FactResponse; check: CheckResponse; - result: any; + result: JsonValue; }; // @public From b5bd60fddc6d543b0ff0584e124a939f3c900a5c Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 24 Nov 2021 23:11:50 +0100 Subject: [PATCH 09/15] Changesets fixes Signed-off-by: irma12 --- .changeset/cold-feet-drop.md | 5 +++++ .changeset/hungry-bikes-leave.md | 5 +++++ .changeset/stupid-readers-cough.md | 5 +++++ .changeset/yellow-ladybugs-begin.md | 8 -------- packages/app/package.json | 2 +- plugins/scorecards/package.json | 2 +- plugins/scorecards/src/api/ScorecardsClient.ts | 1 - 7 files changed, 17 insertions(+), 11 deletions(-) create mode 100644 .changeset/cold-feet-drop.md create mode 100644 .changeset/hungry-bikes-leave.md create mode 100644 .changeset/stupid-readers-cough.md delete mode 100644 .changeset/yellow-ladybugs-begin.md diff --git a/.changeset/cold-feet-drop.md b/.changeset/cold-feet-drop.md new file mode 100644 index 0000000000..aff289cadf --- /dev/null +++ b/.changeset/cold-feet-drop.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-tech-insights-common': patch +--- + +Added new property 'result' in CheckResult in @backstage/plugin-tech-insights-common. This property is later used in `@backstage/plugin-scorecards` package. diff --git a/.changeset/hungry-bikes-leave.md b/.changeset/hungry-bikes-leave.md new file mode 100644 index 0000000000..d40a313415 --- /dev/null +++ b/.changeset/hungry-bikes-leave.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-tech-insights-backend': patch +--- + +Removed unnecessary check for specific server error in @backstage plugin-tech-insights-backend. diff --git a/.changeset/stupid-readers-cough.md b/.changeset/stupid-readers-cough.md new file mode 100644 index 0000000000..ab4ab2388b --- /dev/null +++ b/.changeset/stupid-readers-cough.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scorecards': patch +--- + +New package containing scorecards, appropriate UI components for the Tech Insights plugin. diff --git a/.changeset/yellow-ladybugs-begin.md b/.changeset/yellow-ladybugs-begin.md deleted file mode 100644 index abfa4e5b50..0000000000 --- a/.changeset/yellow-ladybugs-begin.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -'@backstage/plugin-tech-insights-backend': patch -'@backstage/plugin-tech-insights-common': patch ---- - -Removed unnecessary check in @backstage/plugin-tech-insights-backend. - -Added new property 'result' in every CheckResult in @backstage/plugin-tech-insights-common. diff --git a/packages/app/package.json b/packages/app/package.json index 4f6f6a2ea2..1882ddc1f1 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -44,7 +44,7 @@ "@backstage/plugin-todo": "^0.1.15", "@backstage/plugin-user-settings": "^0.3.11", "@backstage/search-common": "^0.2.0", - "@backstage/plugin-scorecards": "^0.1.0", + "@backstage/plugin-scorecards": "^0.0.0", "@backstage/theme": "^0.2.11", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", diff --git a/plugins/scorecards/package.json b/plugins/scorecards/package.json index c0c25f67d4..5ec6fec342 100644 --- a/plugins/scorecards/package.json +++ b/plugins/scorecards/package.json @@ -1,6 +1,6 @@ { "name": "@backstage/plugin-scorecards", - "version": "0.1.0", + "version": "0.0.0", "main": "src/index.ts", "types": "src/index.ts", "license": "Apache-2.0", diff --git a/plugins/scorecards/src/api/ScorecardsClient.ts b/plugins/scorecards/src/api/ScorecardsClient.ts index b640cc6347..014f3f065d 100644 --- a/plugins/scorecards/src/api/ScorecardsClient.ts +++ b/plugins/scorecards/src/api/ScorecardsClient.ts @@ -28,7 +28,6 @@ import { export type Options = { discoveryApi: DiscoveryApi; - proxyPath?: string; }; export class ScorecardsClient implements ScorecardsApi { From 1f455f8abb675e7eb57ba6c49e78fc93b4648cc6 Mon Sep 17 00:00:00 2001 From: irma12 Date: Fri, 26 Nov 2021 13:51:43 +0100 Subject: [PATCH 10/15] Rename scorecards plugin to tech-insights plugin Signed-off-by: irma12 --- .changeset/cold-feet-drop.md | 2 +- .changeset/stupid-readers-cough.md | 4 +- packages/app/package.json | 2 +- plugins/scorecards/README.md | 42 ----------------- .../.eslintrc.js | 0 plugins/tech-insights/README.md | 47 +++++++++++++++++++ .../dev/index.tsx | 11 +++-- .../package.json | 2 +- .../src/api/TechInsightsApi.ts} | 8 ++-- .../src/api/TechInsightsClient.ts} | 4 +- .../src => tech-insights/src/api}/index.ts | 3 +- .../src/api/types.ts | 0 .../components/BooleanCheck/BooleanCheck.tsx | 3 +- .../src/components/BooleanCheck/index.ts | 0 .../src/components/CheckResultRenderer.tsx | 2 +- .../ScorecardsOverview/ChecksOverview.tsx | 8 ++-- .../ScorecardsOverview/ScorecardsOverview.tsx | 4 +- .../components/ScorecardsOverview/index.ts | 0 .../src/api => tech-insights/src}/index.ts | 6 ++- .../src/plugin.test.ts | 6 +-- .../src/plugin.ts | 16 +++---- .../src/routes.ts | 2 +- .../src/setupTests.ts | 0 23 files changed, 93 insertions(+), 79 deletions(-) delete mode 100644 plugins/scorecards/README.md rename plugins/{scorecards => tech-insights}/.eslintrc.js (100%) create mode 100644 plugins/tech-insights/README.md rename plugins/{scorecards => tech-insights}/dev/index.tsx (77%) rename plugins/{scorecards => tech-insights}/package.json (97%) rename plugins/{scorecards/src/api/ScorecardsApi.ts => tech-insights/src/api/TechInsightsApi.ts} (84%) rename plugins/{scorecards/src/api/ScorecardsClient.ts => tech-insights/src/api/TechInsightsClient.ts} (95%) rename plugins/{scorecards/src => tech-insights/src/api}/index.ts (89%) rename plugins/{scorecards => tech-insights}/src/api/types.ts (100%) rename plugins/{scorecards => tech-insights}/src/components/BooleanCheck/BooleanCheck.tsx (96%) rename plugins/{scorecards => tech-insights}/src/components/BooleanCheck/index.ts (100%) rename plugins/{scorecards => tech-insights}/src/components/CheckResultRenderer.tsx (93%) rename plugins/{scorecards => tech-insights}/src/components/ScorecardsOverview/ChecksOverview.tsx (87%) rename plugins/{scorecards => tech-insights}/src/components/ScorecardsOverview/ScorecardsOverview.tsx (92%) rename plugins/{scorecards => tech-insights}/src/components/ScorecardsOverview/index.ts (100%) rename plugins/{scorecards/src/api => tech-insights/src}/index.ts (87%) rename plugins/{scorecards => tech-insights}/src/plugin.test.ts (83%) rename plugins/{scorecards => tech-insights}/src/plugin.ts (72%) rename plugins/{scorecards => tech-insights}/src/routes.ts (96%) rename plugins/{scorecards => tech-insights}/src/setupTests.ts (100%) diff --git a/.changeset/cold-feet-drop.md b/.changeset/cold-feet-drop.md index aff289cadf..3103ae5ea8 100644 --- a/.changeset/cold-feet-drop.md +++ b/.changeset/cold-feet-drop.md @@ -2,4 +2,4 @@ '@backstage/plugin-tech-insights-common': patch --- -Added new property 'result' in CheckResult in @backstage/plugin-tech-insights-common. This property is later used in `@backstage/plugin-scorecards` package. +Added new property 'result' in CheckResult in @backstage/plugin-tech-insights-common. This property is later used in `@backstage/plugin-tech-insights` package. diff --git a/.changeset/stupid-readers-cough.md b/.changeset/stupid-readers-cough.md index ab4ab2388b..b497245b53 100644 --- a/.changeset/stupid-readers-cough.md +++ b/.changeset/stupid-readers-cough.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scorecards': patch +'@backstage/plugin-tech-insights': patch --- -New package containing scorecards, appropriate UI components for the Tech Insights plugin. +New package containing UI components for the Tech Insights plugin. diff --git a/packages/app/package.json b/packages/app/package.json index 1882ddc1f1..d0ac17542a 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -44,7 +44,7 @@ "@backstage/plugin-todo": "^0.1.15", "@backstage/plugin-user-settings": "^0.3.11", "@backstage/search-common": "^0.2.0", - "@backstage/plugin-scorecards": "^0.0.0", + "@backstage/plugin-tech-insights": "^0.0.0", "@backstage/theme": "^0.2.11", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", diff --git a/plugins/scorecards/README.md b/plugins/scorecards/README.md deleted file mode 100644 index ddcd6f7bc7..0000000000 --- a/plugins/scorecards/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Scorecards - -This plugin represents scorecards which are rendered as a part of the default Backstage Tech Insights feature. -It provides UI for the scorecards as well as a check overview. - -## Installation - -### Install the plugin - -```bash -# From your Backstage root directory -cd packages/app -yarn add @backstage/plugin-scorecards -``` - -### Add Scorecards overview page to the EntityPage: - -```tsx -// packages/app/src/components/catalog/EntityPage.tsx - -import { EntityScorecardContent } from '@backstage/plugin-scorecards'; - -const serviceEntityPage = ( - - - {overviewContent} - - - {cicdContent} - - ... - - - - ... - -); -``` - -## Links - -- [The Backstage homepage](https://backstage.io) diff --git a/plugins/scorecards/.eslintrc.js b/plugins/tech-insights/.eslintrc.js similarity index 100% rename from plugins/scorecards/.eslintrc.js rename to plugins/tech-insights/.eslintrc.js diff --git a/plugins/tech-insights/README.md b/plugins/tech-insights/README.md new file mode 100644 index 0000000000..b61cea48ec --- /dev/null +++ b/plugins/tech-insights/README.md @@ -0,0 +1,47 @@ +# Tech Insights + +This plugin provides the UI for the `@backstage/tech-insights-backend` plugin, in order to display results of the checks running following the rules and the logic defined in the `@backstage/tech-insights-backend` plugin itself. + +Main areas covered by this plugin currently are: + +- Providing an overview for default boolean checks in a form of Scorecards. + +- Providing an option to render different custom components based on type of the checks running in the backend. + +## Installation + +### Install the plugin + +```bash +# From your Backstage root directory +cd packages/app +yarn add @backstage/plugin-tech-insights +``` + +### Add boolean checks overview (Scorecards) page to the EntityPage: + +```tsx +// packages/app/src/components/catalog/EntityPage.tsx + +import { EntityTechInsightsScorecardContent } from '@backstage/plugin-tech-insights'; + +const serviceEntityPage = ( + + + {overviewContent} + + + {cicdContent} + + ... + + + + ... + +); +``` + +## Links + +- [The Backstage homepage](https://backstage.io) diff --git a/plugins/scorecards/dev/index.tsx b/plugins/tech-insights/dev/index.tsx similarity index 77% rename from plugins/scorecards/dev/index.tsx rename to plugins/tech-insights/dev/index.tsx index 559e92b969..17b1fca00e 100644 --- a/plugins/scorecards/dev/index.tsx +++ b/plugins/tech-insights/dev/index.tsx @@ -15,13 +15,16 @@ */ import React from 'react'; import { createDevApp } from '@backstage/dev-utils'; -import { scorecardsPlugin, EntityScorecardContent } from '../src/plugin'; +import { + techInsightsPlugin, + EntityTechInsightsScorecardContent, +} from '../src/plugin'; createDevApp() - .registerPlugin(scorecardsPlugin) + .registerPlugin(techInsightsPlugin) .addPage({ - element: , + element: , title: 'Root Page', - path: '/scorecards', + path: '/tech-insight-scorecard', }) .render(); diff --git a/plugins/scorecards/package.json b/plugins/tech-insights/package.json similarity index 97% rename from plugins/scorecards/package.json rename to plugins/tech-insights/package.json index 5ec6fec342..1c1658b082 100644 --- a/plugins/scorecards/package.json +++ b/plugins/tech-insights/package.json @@ -1,5 +1,5 @@ { - "name": "@backstage/plugin-scorecards", + "name": "@backstage/plugin-tech-insights", "version": "0.0.0", "main": "src/index.ts", "types": "src/index.ts", diff --git a/plugins/scorecards/src/api/ScorecardsApi.ts b/plugins/tech-insights/src/api/TechInsightsApi.ts similarity index 84% rename from plugins/scorecards/src/api/ScorecardsApi.ts rename to plugins/tech-insights/src/api/TechInsightsApi.ts index 3e72975861..2c55930f0a 100644 --- a/plugins/scorecards/src/api/ScorecardsApi.ts +++ b/plugins/tech-insights/src/api/TechInsightsApi.ts @@ -20,12 +20,12 @@ import { Check } from './types'; import { CheckResultRenderer } from '../components/CheckResultRenderer'; import { EntityName } from '@backstage/catalog-model'; -export const scorecardsApiRef = createApiRef({ - id: 'plugin.scorecards.service', - description: 'Used by the scorecards plugin to make requests', +export const techInsightsApiRef = createApiRef({ + id: 'plugin.techinsights.service', + description: 'Used by the tech insights plugin to make requests', }); -export interface ScorecardsApi { +export interface TechInsightsApi { getScorecardsDefinition: ( type: string, value: CheckResult[], diff --git a/plugins/scorecards/src/api/ScorecardsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts similarity index 95% rename from plugins/scorecards/src/api/ScorecardsClient.ts rename to plugins/tech-insights/src/api/TechInsightsClient.ts index 014f3f065d..25002e30a1 100644 --- a/plugins/scorecards/src/api/ScorecardsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ScorecardsApi } from './ScorecardsApi'; +import { TechInsightsApi } from './TechInsightsApi'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; import { Check } from './types'; import { DiscoveryApi } from '@backstage/core-plugin-api'; @@ -30,7 +30,7 @@ export type Options = { discoveryApi: DiscoveryApi; }; -export class ScorecardsClient implements ScorecardsApi { +export class TechInsightsClient implements TechInsightsApi { private readonly discoveryApi: DiscoveryApi; constructor(options: Options) { diff --git a/plugins/scorecards/src/index.ts b/plugins/tech-insights/src/api/index.ts similarity index 89% rename from plugins/scorecards/src/index.ts rename to plugins/tech-insights/src/api/index.ts index cba54febcf..bcd2575a52 100644 --- a/plugins/scorecards/src/index.ts +++ b/plugins/tech-insights/src/api/index.ts @@ -13,4 +13,5 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export { scorecardsPlugin, EntityScorecardContent } from './plugin'; +export * from './TechInsightsApi'; +export * from './TechInsightsClient'; diff --git a/plugins/scorecards/src/api/types.ts b/plugins/tech-insights/src/api/types.ts similarity index 100% rename from plugins/scorecards/src/api/types.ts rename to plugins/tech-insights/src/api/types.ts diff --git a/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx similarity index 96% rename from plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx rename to plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx index a10730ce7b..6dba0a56a3 100644 --- a/plugins/scorecards/src/components/BooleanCheck/BooleanCheck.tsx +++ b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx @@ -48,9 +48,10 @@ export const BooleanCheck = ({ checkResult }: Prop) => { return ( - {checkResult!.map(check => ( + {checkResult!.map((check, index) => ( , }, ]; diff --git a/plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx b/plugins/tech-insights/src/components/ScorecardsOverview/ChecksOverview.tsx similarity index 87% rename from plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx rename to plugins/tech-insights/src/components/ScorecardsOverview/ChecksOverview.tsx index 3c66226da9..10025d1ba6 100644 --- a/plugins/scorecards/src/components/ScorecardsOverview/ChecksOverview.tsx +++ b/plugins/tech-insights/src/components/ScorecardsOverview/ChecksOverview.tsx @@ -19,15 +19,17 @@ import { makeStyles, Grid, Typography } from '@material-ui/core'; import { useApi } from '@backstage/core-plugin-api'; import { Content, Page, InfoCard } from '@backstage/core-components'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; -import { scorecardsApiRef } from '../../api/ScorecardsApi'; +import { techInsightsApiRef } from '../../api/TechInsightsApi'; +import { BackstageTheme } from '@backstage/theme'; -const useStyles = makeStyles(() => ({ +const useStyles = makeStyles((theme: BackstageTheme) => ({ contentScorecards: { paddingLeft: 0, paddingRight: 0, }, subheader: { fontWeight: 'bold', + paddingLeft: theme.spacing(0.5), }, })); @@ -37,7 +39,7 @@ type Checks = { export const ChecksOverview = ({ checks }: Checks) => { const classes = useStyles(); - const api = useApi(scorecardsApiRef); + const api = useApi(techInsightsApiRef); const checkRenderType = api.getScorecardsDefinition( checks[0].check.type, checks, diff --git a/plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx b/plugins/tech-insights/src/components/ScorecardsOverview/ScorecardsOverview.tsx similarity index 92% rename from plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx rename to plugins/tech-insights/src/components/ScorecardsOverview/ScorecardsOverview.tsx index 7bfd57be72..92a57bd643 100644 --- a/plugins/scorecards/src/components/ScorecardsOverview/ScorecardsOverview.tsx +++ b/plugins/tech-insights/src/components/ScorecardsOverview/ScorecardsOverview.tsx @@ -21,10 +21,10 @@ import { Progress } from '@backstage/core-components'; import { useApi } from '@backstage/core-plugin-api'; import { ChecksOverview } from './ChecksOverview'; import Alert from '@material-ui/lab/Alert'; -import { scorecardsApiRef } from '../../api/ScorecardsApi'; +import { techInsightsApiRef } from '../../api/TechInsightsApi'; export const ScorecardsOverview = () => { - const api = useApi(scorecardsApiRef); + const api = useApi(techInsightsApiRef); const { namespace, kind, name } = useParams(); const { value, loading, error } = useAsync( diff --git a/plugins/scorecards/src/components/ScorecardsOverview/index.ts b/plugins/tech-insights/src/components/ScorecardsOverview/index.ts similarity index 100% rename from plugins/scorecards/src/components/ScorecardsOverview/index.ts rename to plugins/tech-insights/src/components/ScorecardsOverview/index.ts diff --git a/plugins/scorecards/src/api/index.ts b/plugins/tech-insights/src/index.ts similarity index 87% rename from plugins/scorecards/src/api/index.ts rename to plugins/tech-insights/src/index.ts index afebc5432f..273c11fd71 100644 --- a/plugins/scorecards/src/api/index.ts +++ b/plugins/tech-insights/src/index.ts @@ -13,5 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -export * from './ScorecardsApi'; -export * from './ScorecardsClient'; +export { + techInsightsPlugin, + EntityTechInsightsScorecardContent, +} from './plugin'; diff --git a/plugins/scorecards/src/plugin.test.ts b/plugins/tech-insights/src/plugin.test.ts similarity index 83% rename from plugins/scorecards/src/plugin.test.ts rename to plugins/tech-insights/src/plugin.test.ts index 537a6399bf..a4a9e6f308 100644 --- a/plugins/scorecards/src/plugin.test.ts +++ b/plugins/tech-insights/src/plugin.test.ts @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { scorecardsPlugin } from './plugin'; +import { techInsightsPlugin } from './plugin'; -describe('scorecards', () => { +describe('tech insights', () => { it('should export plugin', () => { - expect(scorecardsPlugin).toBeDefined(); + expect(techInsightsPlugin).toBeDefined(); }); }); diff --git a/plugins/scorecards/src/plugin.ts b/plugins/tech-insights/src/plugin.ts similarity index 72% rename from plugins/scorecards/src/plugin.ts rename to plugins/tech-insights/src/plugin.ts index 4c39b9768f..f229b654f3 100644 --- a/plugins/scorecards/src/plugin.ts +++ b/plugins/tech-insights/src/plugin.ts @@ -20,19 +20,19 @@ import { discoveryApiRef, } from '@backstage/core-plugin-api'; import { rootRouteRef } from './routes'; -import { scorecardsApiRef } from './api/ScorecardsApi'; -import { ScorecardsClient } from './api'; +import { techInsightsApiRef } from './api/TechInsightsApi'; +import { TechInsightsClient } from './api/TechInsightsClient'; /** * @public */ -export const scorecardsPlugin = createPlugin({ - id: 'scorecards', +export const techInsightsPlugin = createPlugin({ + id: 'tech-insights', apis: [ createApiFactory({ - api: scorecardsApiRef, + api: techInsightsApiRef, deps: { discoveryApi: discoveryApiRef }, - factory: ({ discoveryApi }) => new ScorecardsClient({ discoveryApi }), + factory: ({ discoveryApi }) => new TechInsightsClient({ discoveryApi }), }), ], routes: { @@ -43,9 +43,9 @@ export const scorecardsPlugin = createPlugin({ /** * @public */ -export const EntityScorecardContent = scorecardsPlugin.provide( +export const EntityTechInsightsScorecardContent = techInsightsPlugin.provide( createRoutableExtension({ - name: 'EntityScorecardContent', + name: 'EntityTechInsightsScorecardContent', component: () => import('./components/ScorecardsOverview').then(m => m.ScorecardsOverview), mountPoint: rootRouteRef, diff --git a/plugins/scorecards/src/routes.ts b/plugins/tech-insights/src/routes.ts similarity index 96% rename from plugins/scorecards/src/routes.ts rename to plugins/tech-insights/src/routes.ts index 484a9c7e2b..b1b7900074 100644 --- a/plugins/scorecards/src/routes.ts +++ b/plugins/tech-insights/src/routes.ts @@ -16,5 +16,5 @@ import { createRouteRef } from '@backstage/core-plugin-api'; export const rootRouteRef = createRouteRef({ - id: 'scorecards', + id: 'tech-insights', }); diff --git a/plugins/scorecards/src/setupTests.ts b/plugins/tech-insights/src/setupTests.ts similarity index 100% rename from plugins/scorecards/src/setupTests.ts rename to plugins/tech-insights/src/setupTests.ts From c8b4a30d1d98e250c7d447110aac99156959a3e2 Mon Sep 17 00:00:00 2001 From: irma12 Date: Fri, 26 Nov 2021 14:01:39 +0100 Subject: [PATCH 11/15] Small typo fix in changeset docs Signed-off-by: irma12 --- .changeset/hungry-bikes-leave.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/hungry-bikes-leave.md b/.changeset/hungry-bikes-leave.md index d40a313415..b6ac827cfe 100644 --- a/.changeset/hungry-bikes-leave.md +++ b/.changeset/hungry-bikes-leave.md @@ -2,4 +2,4 @@ '@backstage/plugin-tech-insights-backend': patch --- -Removed unnecessary check for specific server error in @backstage plugin-tech-insights-backend. +Removed unnecessary check for specific server error in `@backstage plugin-tech-insights-backend`. From 8b14c7146d2bbd0c6832b48d39783663cf0199d0 Mon Sep 17 00:00:00 2001 From: irma12 Date: Fri, 26 Nov 2021 15:00:04 +0100 Subject: [PATCH 12/15] Add API Report Signed-off-by: irma12 --- plugins/tech-insights/api-report.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 plugins/tech-insights/api-report.md diff --git a/plugins/tech-insights/api-report.md b/plugins/tech-insights/api-report.md new file mode 100644 index 0000000000..e7f30a2b30 --- /dev/null +++ b/plugins/tech-insights/api-report.md @@ -0,0 +1,23 @@ +## API Report File for "@backstage/plugin-tech-insights" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +/// + +import { BackstagePlugin } from '@backstage/core-plugin-api'; +import { RouteRef } from '@backstage/core-plugin-api'; + +// @public (undocumented) +export const EntityTechInsightsScorecardContent: () => JSX.Element; + +// @public (undocumented) +export const techInsightsPlugin: BackstagePlugin< + { + root: RouteRef; + }, + {} +>; + +// (No @packageDocumentation comment for this package) +``` From a089a286b2e32856bfca5a5e714a4d2f557c0178 Mon Sep 17 00:00:00 2001 From: irma12 Date: Fri, 26 Nov 2021 15:19:51 +0100 Subject: [PATCH 13/15] Update package.json Signed-off-by: irma12 --- plugins/tech-insights/package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/tech-insights/package.json b/plugins/tech-insights/package.json index 1c1658b082..79d184f0a5 100644 --- a/plugins/tech-insights/package.json +++ b/plugins/tech-insights/package.json @@ -20,8 +20,8 @@ "clean": "backstage-cli clean" }, "dependencies": { - "@backstage/core-components": "^0.7.4", - "@backstage/core-plugin-api": "^0.2.0", + "@backstage/core-components": "^0.7.5", + "@backstage/core-plugin-api": "^0.2.1", "@backstage/theme": "^0.2.13", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", @@ -37,10 +37,10 @@ "@backstage/types": "^0.1.1" }, "devDependencies": { - "@backstage/cli": "^0.9.0", - "@backstage/core-app-api": "^0.1.22", + "@backstage/cli": "^0.9.1", + "@backstage/core-app-api": "^0.1.23", "@backstage/dev-utils": "^0.2.13", - "@backstage/test-utils": "^0.1.22", + "@backstage/test-utils": "^0.1.23", "@testing-library/jest-dom": "^5.10.1", "@testing-library/react": "^11.2.5", "@testing-library/user-event": "^13.1.8", From 517db130c4043cb19a23576e47c29a5f5ef9be9a Mon Sep 17 00:00:00 2001 From: irma12 Date: Tue, 30 Nov 2021 18:29:43 +0100 Subject: [PATCH 14/15] Final fixes Signed-off-by: irma12 --- .changeset/stupid-readers-cough.md | 2 +- plugins/scorecards/api-report.md | 23 ----------------------- 2 files changed, 1 insertion(+), 24 deletions(-) delete mode 100644 plugins/scorecards/api-report.md diff --git a/.changeset/stupid-readers-cough.md b/.changeset/stupid-readers-cough.md index b497245b53..82119ed695 100644 --- a/.changeset/stupid-readers-cough.md +++ b/.changeset/stupid-readers-cough.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-tech-insights': patch +'@backstage/plugin-tech-insights': minor --- New package containing UI components for the Tech Insights plugin. diff --git a/plugins/scorecards/api-report.md b/plugins/scorecards/api-report.md deleted file mode 100644 index 705cce373e..0000000000 --- a/plugins/scorecards/api-report.md +++ /dev/null @@ -1,23 +0,0 @@ -## API Report File for "@backstage/plugin-scorecards" - -> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). - -```ts -/// - -import { BackstagePlugin } from '@backstage/core-plugin-api'; -import { RouteRef } from '@backstage/core-plugin-api'; - -// @public (undocumented) -export const EntityScorecardContent: () => JSX.Element; - -// @public (undocumented) -export const scorecardsPlugin: BackstagePlugin< - { - root: RouteRef; - }, - {} ->; - -// (No @packageDocumentation comment for this package) -``` From f4d351d441dda073e1650730e9e9af6421608454 Mon Sep 17 00:00:00 2001 From: irma12 Date: Wed, 1 Dec 2021 10:24:07 +0100 Subject: [PATCH 15/15] Last fixes Signed-off-by: irma12 --- .changeset/cold-feet-drop.md | 2 +- .../components/BooleanCheck/BooleanCheck.tsx | 22 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.changeset/cold-feet-drop.md b/.changeset/cold-feet-drop.md index 3103ae5ea8..2d9daf0c1b 100644 --- a/.changeset/cold-feet-drop.md +++ b/.changeset/cold-feet-drop.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-tech-insights-common': patch +'@backstage/plugin-tech-insights-common': minor --- Added new property 'result' in CheckResult in @backstage/plugin-tech-insights-common. This property is later used in `@backstage/plugin-tech-insights` package. diff --git a/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx index 6dba0a56a3..e38e0aa7b3 100644 --- a/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx +++ b/plugins/tech-insights/src/components/BooleanCheck/BooleanCheck.tsx @@ -19,11 +19,11 @@ import { makeStyles, List, ListItem, ListItemText } from '@material-ui/core'; import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline'; import ErrorOutlineIcon from '@material-ui/icons/ErrorOutline'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; -import { JsonValue } from '@backstage/types'; +import { BackstageTheme } from '@backstage/theme'; -const useStyles = makeStyles(() => ({ +const useStyles = makeStyles((theme: BackstageTheme) => ({ listItemText: { - paddingRight: '1rem', + paddingRight: theme.spacing(0.5), flex: '0 1 auto', }, icon: { @@ -35,20 +35,12 @@ type Prop = { checkResult: CheckResult[]; }; -const renderResult = (classes: any, result: JsonValue) => { - return result ? ( - - ) : ( - - ); -}; - export const BooleanCheck = ({ checkResult }: Prop) => { const classes = useStyles(); return ( - {checkResult!.map((check, index) => ( + {checkResult.map((check, index) => ( { secondary={check.check.description} className={classes.listItemText} /> - {renderResult(classes, check.result)} + {check.result ? ( + + ) : ( + + )} ))}