From d6ab0613a3797935022e73d883678e77a8569cbb Mon Sep 17 00:00:00 2001 From: sblausten Date: Wed, 6 Jul 2022 13:46:10 +0200 Subject: [PATCH 1/6] Extend model so we can represent fact retrievers in the UI Signed-off-by: sblausten --- .../service/fact/factRetrievers/entityMetadataFactRetriever.ts | 3 +++ .../fact/factRetrievers/entityOwnershipFactRetriever.ts | 3 +++ .../src/service/fact/factRetrievers/techdocsFactRetriever.ts | 3 +++ 3 files changed, 9 insertions(+) diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts index caa19dbeaf..3103f9bdd5 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts @@ -30,6 +30,9 @@ import isEmpty from 'lodash/isEmpty'; export const entityMetadataFactRetriever: FactRetriever = { id: 'entityMetadataFactRetriever', version: '0.0.1', + title: 'Entity Metadata', + description: + 'Generates facts which indicate the completeness of entity metadata', schema: { hasTitle: { type: 'boolean', diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts index c1e9b2710e..974f1d30cd 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts @@ -29,6 +29,9 @@ import { Entity } from '@backstage/catalog-model'; export const entityOwnershipFactRetriever: FactRetriever = { id: 'entityOwnershipFactRetriever', version: '0.0.1', + title: 'Entity Ownership', + description: + 'Generates facts which indicate the quality of data in the spec.owner field', entityFilter: [ { kind: ['component', 'domain', 'system', 'api', 'resource', 'template'] }, ], diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts index 6bc84f4aa9..dc14298a55 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts @@ -34,6 +34,9 @@ const techdocsAnnotationFactName = export const techdocsFactRetriever: FactRetriever = { id: 'techdocsFactRetriever', version: '0.0.1', + title: 'Tech Docs', + description: + 'Generates facts related to the completeness of techdocs configuration for entities', schema: { [techdocsAnnotationFactName]: { type: 'boolean', From bcc122c46d34f4340c2f4e628900451472d2c00a Mon Sep 17 00:00:00 2001 From: sblausten Date: Wed, 6 Jul 2022 13:59:42 +0200 Subject: [PATCH 2/6] Api report and changelog Signed-off-by: sblausten --- .changeset/rich-steaks-juggle.md | 9 +++++++++ plugins/tech-insights-node/api-report.md | 2 ++ plugins/tech-insights-node/src/facts.ts | 10 ++++++++++ 3 files changed, 21 insertions(+) create mode 100644 .changeset/rich-steaks-juggle.md diff --git a/.changeset/rich-steaks-juggle.md b/.changeset/rich-steaks-juggle.md new file mode 100644 index 0000000000..291e9dac2b --- /dev/null +++ b/.changeset/rich-steaks-juggle.md @@ -0,0 +1,9 @@ +--- +'@backstage/plugin-tech-insights-node': minor +'@backstage/plugin-tech-insights-backend': patch +--- + +**Breaking**: The FactRetriever model is extended by adding required title and description fields. This allows us to +display Fact Retrievers in the UI in future. + +If you have existing custom `FactRetriever` implementations hardcoded, you'll need to add a `title` and `description` to them. diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 09d409fecd..060158a619 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -46,12 +46,14 @@ export type FactLifecycle = TTL | MaxItems; // @public export interface FactRetriever { + description: string; entityFilter?: | Record[] | Record; handler: (ctx: FactRetrieverContext) => Promise; id: string; schema: FactSchema; + title: string; version: string; } diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index bcc2aa42e1..6905a12f9c 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -174,6 +174,16 @@ export interface FactRetriever { */ version: string; + /** + * A short display title for the fact retriever to be used in the interface + */ + title: string; + + /** + * A short display description for the fact retriever to be used in the interface. + */ + description: string; + /** * Handler function that needs to be implemented to retrieve fact values for entities. * From 54f4eba5611386c2300d225e625587a79e7f3aa1 Mon Sep 17 00:00:00 2001 From: sblausten Date: Wed, 6 Jul 2022 16:09:27 +0200 Subject: [PATCH 3/6] Refactor Signed-off-by: sblausten --- .changeset/rich-steaks-juggle.md | 7 +- plugins/tech-insights-backend/api-report.md | 2 +- .../service/fact/FactRetrieverEngine.test.ts | 4 +- .../src/service/fact/FactRetrieverEngine.ts | 2 +- .../src/service/fact/FactRetrieverRegistry.ts | 2 +- .../src/service/fact/createFactRetriever.ts | 4 +- .../entityMetadataFactRetriever.ts | 6 +- .../entityOwnershipFactRetriever.ts | 6 +- .../factRetrievers/techdocsFactRetriever.ts | 6 +- plugins/tech-insights-common/api-report.md | 16 +++ plugins/tech-insights-common/package.json | 3 +- plugins/tech-insights-common/src/index.ts | 62 +++++++++ plugins/tech-insights-node/api-report.md | 14 +- plugins/tech-insights-node/src/facts.ts | 58 +------- yarn.lock | 126 ++++++++++++++++++ 15 files changed, 226 insertions(+), 92 deletions(-) diff --git a/.changeset/rich-steaks-juggle.md b/.changeset/rich-steaks-juggle.md index 291e9dac2b..b873efd59e 100644 --- a/.changeset/rich-steaks-juggle.md +++ b/.changeset/rich-steaks-juggle.md @@ -1,9 +1,10 @@ --- -'@backstage/plugin-tech-insights-node': minor -'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-node': patch +'@backstage/plugin-tech-insights-backend': minor +'@backstage/plugin-tech-insights-common': minor --- -**Breaking**: The FactRetriever model is extended by adding required title and description fields. This allows us to +**Breaking**: The FactRetriever model is extended by adding a title and description fields and moved to the common package. This allows us to display Fact Retrievers in the UI in future. If you have existing custom `FactRetriever` implementations hardcoded, you'll need to add a `title` and `description` to them. diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index 32d45f8afd..616d0f2c79 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -9,7 +9,7 @@ import express from 'express'; import { FactChecker } from '@backstage/plugin-tech-insights-node'; import { FactCheckerFactory } from '@backstage/plugin-tech-insights-node'; import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; -import { FactRetriever } from '@backstage/plugin-tech-insights-node'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; import { FactSchema } from '@backstage/plugin-tech-insights-node'; import { Logger } from 'winston'; diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts index 454711171f..34b816479d 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts @@ -14,7 +14,6 @@ * limitations under the License. */ import { - FactRetriever, FactRetrieverRegistration, FactSchemaDefinition, TechInsightFact, @@ -30,12 +29,15 @@ import { import { ConfigReader } from '@backstage/config'; import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils'; import { TaskScheduler } from '@backstage/backend-tasks'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; jest.useFakeTimers(); const testFactRetriever: FactRetriever = { id: 'test_factretriever', version: '0.0.1', + title: 'Test 1', + description: 'testing', entityFilter: [{ kind: 'component' }], schema: { testnumberfact: { diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts index 25e7610809..1d37e4d857 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts @@ -15,7 +15,6 @@ */ import { FactLifecycle, - FactRetriever, FactRetrieverContext, FactRetrieverRegistration, TechInsightFact, @@ -25,6 +24,7 @@ import { FactRetrieverRegistry } from './FactRetrieverRegistry'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { Duration } from 'luxon'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; function randomDailyCron() { const rand = (min: number, max: number) => diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts index 504d561f17..17139f0992 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts @@ -15,11 +15,11 @@ */ import { - FactRetriever, FactRetrieverRegistration, FactSchema, } from '@backstage/plugin-tech-insights-node'; import { ConflictError, NotFoundError } from '@backstage/errors'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * @public diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index de49888e1b..bd4960d10f 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -15,15 +15,15 @@ */ import { FactLifecycle, - FactRetriever, FactRetrieverRegistration, } from '@backstage/plugin-tech-insights-node'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * @public * * @param cadence - cron expression to indicate when the fact retriever should be triggered - * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler + * @param factRetriever - Implementation of fact retriever definition * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run * */ diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts index 3103f9bdd5..7bddb4c0c6 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts @@ -14,13 +14,11 @@ * limitations under the License. */ -import { - FactRetriever, - FactRetrieverContext, -} from '@backstage/plugin-tech-insights-node'; +import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; import isEmpty from 'lodash/isEmpty'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * Generates facts which indicate the completeness of entity metadata. diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts index 974f1d30cd..39fbd0dea7 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts @@ -14,12 +14,10 @@ * limitations under the License. */ -import { - FactRetriever, - FactRetrieverContext, -} from '@backstage/plugin-tech-insights-node'; +import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * Generates facts which indicate the quality of data in the spec.owner field. diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts index dc14298a55..95b043cfc8 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts @@ -14,13 +14,11 @@ * limitations under the License. */ -import { - FactRetriever, - FactRetrieverContext, -} from '@backstage/plugin-tech-insights-node'; +import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; import { entityHasAnnotation, generateAnnotationFactName } from './utils'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; const techdocsAnnotation = 'backstage.io/techdocs-ref'; const techdocsAnnotationFactName = diff --git a/plugins/tech-insights-common/api-report.md b/plugins/tech-insights-common/api-report.md index 0236c0619a..746d99f663 100644 --- a/plugins/tech-insights-common/api-report.md +++ b/plugins/tech-insights-common/api-report.md @@ -4,7 +4,10 @@ ```ts import { DateTime } from 'luxon'; +import { FactRetrieverContext } from '../../tech-insights-node'; +import { FactSchema } from '../../tech-insights-node'; import { JsonValue } from '@backstage/types'; +import { TechInsightFact } from '../../tech-insights-node'; // @public export interface BooleanCheckResult extends CheckResult { @@ -47,5 +50,18 @@ export type FactResponse = { }; }; +// @public +export interface FactRetriever { + description: string; + entityFilter?: + | Record[] + | Record; + handler: (ctx: FactRetrieverContext) => Promise; + id: string; + schema: FactSchema; + title: string; + version: string; +} + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/tech-insights-common/package.json b/plugins/tech-insights-common/package.json index 14ec147bb9..bc98cdb888 100644 --- a/plugins/tech-insights-common/package.json +++ b/plugins/tech-insights-common/package.json @@ -35,7 +35,8 @@ "dependencies": { "@types/luxon": "^2.0.5", "luxon": "^2.0.2", - "@backstage/types": "^1.0.0" + "@backstage/types": "^1.0.0", + "@backstage/plugin-tech-insights-node": "^0.3.1" }, "devDependencies": { "@backstage/cli": "^0.18.0-next.1" diff --git a/plugins/tech-insights-common/src/index.ts b/plugins/tech-insights-common/src/index.ts index 66af5c2f93..42abb3dd44 100644 --- a/plugins/tech-insights-common/src/index.ts +++ b/plugins/tech-insights-common/src/index.ts @@ -16,6 +16,11 @@ import { DateTime } from 'luxon'; import { JsonValue } from '@backstage/types'; +import { + FactRetrieverContext, + FactSchema, + TechInsightFact, +} from '@backstage/plugin-tech-insights-node'; /** * @public @@ -101,6 +106,63 @@ export type FactResponse = { }; }; +/** + * FactRetriever interface + * + * @public + */ +export interface FactRetriever { + /** + * A unique identifier of the retriever. + * Used to identify and store individual facts returned from this retriever + * and schemas defined by this retriever. + */ + id: string; + + /** + * Semver string indicating the version of this fact retriever + * This version is used to determine if the schema this fact retriever matches the data this fact retriever provides. + * + * Should be incremented on changes to returned data from the handler or if the schema changes. + */ + version: string; + + /** + * A short display title for the fact retriever to be used in the interface + */ + title: string; + + /** + * A short display description for the fact retriever to be used in the interface. + */ + description: string; + + /** + * Handler function that needs to be implemented to retrieve fact values for entities. + * + * @param ctx - FactRetrieverContext which can be used to retrieve config and contact integrations + * @returns - A collection of TechInsightFacts grouped by entities. + */ + handler: (ctx: FactRetrieverContext) => Promise; + + /** + * A fact schema defining the shape of data returned from the handler method for each entity + */ + schema: FactSchema; + + /** + * An optional object/array of objects of entity filters to indicate if this fact retriever is valid for an entity type. + * If omitted, the retriever should apply to all entities. + * + * Should be defined for example: + * \{ field: 'kind', values: \['component'\] \} + * \{ field: 'metadata.name', values: \['component-1', 'component-2'\] \} + */ + entityFilter?: + | Record[] + | Record; +} + /** * Generic CheckResult * diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 060158a619..0ca1e22787 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,6 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -44,19 +45,6 @@ export interface FactCheckerFactory< // @public export type FactLifecycle = TTL | MaxItems; -// @public -export interface FactRetriever { - description: string; - entityFilter?: - | Record[] - | Record; - handler: (ctx: FactRetrieverContext) => Promise; - id: string; - schema: FactSchema; - title: string; - version: string; -} - // @public export type FactRetrieverContext = { config: Config; diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index 6905a12f9c..6c37616b0c 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -21,6 +21,7 @@ import { TokenManager, } from '@backstage/backend-common'; import { Logger } from 'winston'; +import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value. @@ -153,63 +154,6 @@ export type FactRetrieverContext = { | Record; }; -/** - * FactRetriever interface - * - * @public - */ -export interface FactRetriever { - /** - * A unique identifier of the retriever. - * Used to identify and store individual facts returned from this retriever - * and schemas defined by this retriever. - */ - id: string; - - /** - * Semver string indicating the version of this fact retriever - * This version is used to determine if the schema this fact retriever matches the data this fact retriever provides. - * - * Should be incremented on changes to returned data from the handler or if the schema changes. - */ - version: string; - - /** - * A short display title for the fact retriever to be used in the interface - */ - title: string; - - /** - * A short display description for the fact retriever to be used in the interface. - */ - description: string; - - /** - * Handler function that needs to be implemented to retrieve fact values for entities. - * - * @param ctx - FactRetrieverContext which can be used to retrieve config and contact integrations - * @returns - A collection of TechInsightFacts grouped by entities. - */ - handler: (ctx: FactRetrieverContext) => Promise; - - /** - * A fact schema defining the shape of data returned from the handler method for each entity - */ - schema: FactSchema; - - /** - * An optional object/array of objects of entity filters to indicate if this fact retriever is valid for an entity type. - * If omitted, the retriever should apply to all entities. - * - * Should be defined for example: - * \{ field: 'kind', values: \['component'\] \} - * \{ field: 'metadata.name', values: \['component-1', 'component-2'\] \} - */ - entityFilter?: - | Record[] - | Record; -} - /** * A Luxon duration like object for time to live value * diff --git a/yarn.lock b/yarn.lock index f06a187ebf..8f557e9551 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1535,6 +1535,59 @@ "@babel/helper-validator-identifier" "^7.16.7" to-fast-properties "^2.0.0" +"@backstage/backend-common@^0.14.0": + version "0.14.0" + resolved "https://registry.npmjs.org/@backstage/backend-common/-/backend-common-0.14.0.tgz#da7537c7a58ce596db36be3bb584b9c199f58296" + integrity sha512-xiEOknaWtyfiWcL8+fkQKMfSnpQr1FsKFX6xVc74Lrgmd46VMW7pbhDQULQDaeCN+jhwTfxCcsemhtcJjimq+w== + dependencies: + "@backstage/cli-common" "^0.1.9" + "@backstage/config" "^1.0.1" + "@backstage/config-loader" "^1.1.2" + "@backstage/errors" "^1.0.0" + "@backstage/integration" "^1.2.1" + "@backstage/types" "^1.0.0" + "@google-cloud/storage" "^6.0.0" + "@keyv/redis" "^2.2.3" + "@manypkg/get-packages" "^1.1.3" + "@octokit/rest" "^18.5.3" + "@types/cors" "^2.8.6" + "@types/dockerode" "^3.3.0" + "@types/express" "^4.17.6" + "@types/luxon" "^2.0.4" + "@types/webpack-env" "^1.15.2" + archiver "^5.0.2" + aws-sdk "^2.840.0" + base64-stream "^1.0.0" + compression "^1.7.4" + concat-stream "^2.0.0" + cors "^2.8.5" + dockerode "^3.3.1" + express "^4.17.1" + express-promise-router "^4.1.0" + fs-extra "10.1.0" + git-url-parse "^11.6.0" + helmet "^5.0.2" + isomorphic-git "^1.8.0" + jose "^4.6.0" + keyv "^4.0.3" + keyv-memcache "^1.2.5" + knex "^1.0.2" + lodash "^4.17.21" + logform "^2.3.2" + luxon "^2.3.1" + minimatch "^5.0.0" + minimist "^1.2.5" + morgan "^1.10.0" + node-abort-controller "^3.0.1" + node-fetch "^2.6.7" + raw-body "^2.4.1" + selfsigned "^2.0.0" + stoppable "^1.1.0" + tar "^6.1.2" + unzipper "^0.10.11" + winston "^3.2.1" + yn "^4.0.0" + "@backstage/catalog-client@^1.0.3": version "1.0.3" resolved "https://registry.npmjs.org/@backstage/catalog-client/-/catalog-client-1.0.3.tgz#cb91472ccc31df322f69e7e4e80939b3535660cd" @@ -1557,6 +1610,27 @@ lodash "^4.17.21" uuid "^8.0.0" +"@backstage/config-loader@^1.1.2": + version "1.1.2" + resolved "https://registry.npmjs.org/@backstage/config-loader/-/config-loader-1.1.2.tgz#72cb0d7b2647f5a646bb279360bc34732e06521f" + integrity sha512-c5ZO7xDJn609DBIsYAWGE5kgh+7SPYUmG2ADtVX9SbXaql3VCafGlhc2hAZQa/O12W04qi3GgwGg0bqSFmx5uw== + dependencies: + "@backstage/cli-common" "^0.1.9" + "@backstage/config" "^1.0.1" + "@backstage/errors" "^1.0.0" + "@backstage/types" "^1.0.0" + "@types/json-schema" "^7.0.6" + ajv "^8.10.0" + chokidar "^3.5.2" + fs-extra "10.1.0" + json-schema "^0.4.0" + json-schema-merge-allof "^0.8.1" + json-schema-traverse "^1.0.0" + node-fetch "^2.6.7" + typescript-json-schema "^0.53.0" + yaml "^1.9.2" + yup "^0.32.9" + "@backstage/core-components@^0.9.0", "@backstage/core-components@^0.9.5": version "0.9.5" resolved "https://registry.npmjs.org/@backstage/core-components/-/core-components-0.9.5.tgz#5a0b34867aaee0549bfa67b39a69c09588fa3c7a" @@ -1747,6 +1821,19 @@ qs "^6.9.4" react-use "^17.2.4" +"@backstage/plugin-tech-insights-node@^0.3.1": + version "0.3.1" + resolved "https://registry.npmjs.org/@backstage/plugin-tech-insights-node/-/plugin-tech-insights-node-0.3.1.tgz#d9bf40b07c57bac67b251ac8d53c0ad26ad2e651" + integrity sha512-okfIZIVUVdhejqmd9UHaVg42VukHPT0RIVeUblALXDxip9PND+W4hKgZTRs7/2Z/IWOxGyGLEwAkRG0QSLnysg== + dependencies: + "@backstage/backend-common" "^0.14.0" + "@backstage/config" "^1.0.1" + "@backstage/plugin-tech-insights-common" "^0.2.4" + "@backstage/types" "^1.0.0" + "@types/luxon" "^2.0.5" + luxon "^2.0.2" + winston "^3.2.1" + "@backstage/theme@^0.2.15", "@backstage/theme@^0.2.6", "@backstage/theme@^0.2.7", "@backstage/theme@^0.2.9": version "0.2.15" resolved "https://registry.npmjs.org/@backstage/theme/-/theme-0.2.15.tgz#478491c9bca9dca85d5af08767ba512eabcd3669" @@ -17052,6 +17139,26 @@ kleur@^4.0.3, kleur@^4.1.4: resolved "https://registry.npmjs.org/kleur/-/kleur-4.1.4.tgz#8c202987d7e577766d039a8cd461934c01cda04d" integrity sha512-8QADVssbrFjivHWQU7KkMgptGTl6WAcSdlbBPY4uNF+mWr6DGcKrvY2w4FQJoXch7+fKMjj0dRrL75vk3k23OA== +knex@^1.0.2: + version "1.0.7" + resolved "https://registry.npmjs.org/knex/-/knex-1.0.7.tgz#965f4490efc451b140aac4c5c6efa39fd877597b" + integrity sha512-89jxuRATt4qJMb9ZyyaKBy0pQ4d5h7eOFRqiNFnUvsgU+9WZ2eIaZKrAPG1+F3mgu5UloPUnkVE5Yo2sKZUs6Q== + dependencies: + colorette "2.0.16" + commander "^9.1.0" + debug "4.3.4" + escalade "^3.1.1" + esm "^3.2.25" + get-package-type "^0.1.0" + getopts "2.3.0" + interpret "^2.2.0" + lodash "^4.17.21" + pg-connection-string "2.5.0" + rechoir "^0.8.0" + resolve-from "^5.0.0" + tarn "^3.0.2" + tildify "2.0.0" + knex@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/knex/-/knex-2.1.0.tgz#9348aace3a08ff5be26eb1c8e838416ddf1aa216" @@ -20420,6 +20527,11 @@ path-case@^3.0.4: dot-case "^3.0.4" tslib "^2.0.3" +path-equal@1.1.2: + version "1.1.2" + resolved "https://registry.npmjs.org/path-equal/-/path-equal-1.1.2.tgz#260e7c449c4c2022f68cc5fa6e617e892858250d" + integrity sha512-p5kxPPwCdbf5AdXzT1bUBJomhgBlEjRBavYNr1XUpMFIE4Hnf2roueCMXudZK5tnaAu1tTmp3GPzqwJK45IHEA== + path-equal@^1.1.2: version "1.2.2" resolved "https://registry.npmjs.org/path-equal/-/path-equal-1.2.2.tgz#fa2997f0a829de22ec8f5f86461ca5590d49b832" @@ -25218,6 +25330,20 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= +typescript-json-schema@^0.53.0: + version "0.53.1" + resolved "https://registry.npmjs.org/typescript-json-schema/-/typescript-json-schema-0.53.1.tgz#9204547f3e145169b40928998366ff6d28b81d32" + integrity sha512-Hg+RnOKUd38MOzC0rDft03a8xvwO+gCcj1F77smw2tCoZYQpFoLtrXWBGdvCX+REliko5WYel2kux17HPFqjLQ== + dependencies: + "@types/json-schema" "^7.0.9" + "@types/node" "^16.9.2" + glob "^7.1.7" + path-equal "1.1.2" + safe-stable-stringify "^2.2.0" + ts-node "^10.2.1" + typescript "~4.6.0" + yargs "^17.1.1" + typescript-json-schema@^0.54.0: version "0.54.0" resolved "https://registry.npmjs.org/typescript-json-schema/-/typescript-json-schema-0.54.0.tgz#b3fc42ad90df6a0f6ab57571ebc8b4d41125df4f" From 4f17e4eb5517cce765e59f61301dc92da33632bb Mon Sep 17 00:00:00 2001 From: sblausten Date: Wed, 6 Jul 2022 17:13:42 +0200 Subject: [PATCH 4/6] Revert "Refactor" This reverts commit 54f4eba5611386c2300d225e625587a79e7f3aa1. Signed-off-by: sblausten --- .changeset/rich-steaks-juggle.md | 7 +- plugins/tech-insights-backend/api-report.md | 2 +- .../service/fact/FactRetrieverEngine.test.ts | 4 +- .../src/service/fact/FactRetrieverEngine.ts | 2 +- .../src/service/fact/FactRetrieverRegistry.ts | 2 +- .../src/service/fact/createFactRetriever.ts | 4 +- .../entityMetadataFactRetriever.ts | 6 +- .../entityOwnershipFactRetriever.ts | 6 +- .../factRetrievers/techdocsFactRetriever.ts | 6 +- plugins/tech-insights-common/api-report.md | 16 --- plugins/tech-insights-common/package.json | 3 +- plugins/tech-insights-common/src/index.ts | 62 --------- plugins/tech-insights-node/api-report.md | 14 +- plugins/tech-insights-node/src/facts.ts | 58 +++++++- yarn.lock | 126 ------------------ 15 files changed, 92 insertions(+), 226 deletions(-) diff --git a/.changeset/rich-steaks-juggle.md b/.changeset/rich-steaks-juggle.md index b873efd59e..291e9dac2b 100644 --- a/.changeset/rich-steaks-juggle.md +++ b/.changeset/rich-steaks-juggle.md @@ -1,10 +1,9 @@ --- -'@backstage/plugin-tech-insights-node': patch -'@backstage/plugin-tech-insights-backend': minor -'@backstage/plugin-tech-insights-common': minor +'@backstage/plugin-tech-insights-node': minor +'@backstage/plugin-tech-insights-backend': patch --- -**Breaking**: The FactRetriever model is extended by adding a title and description fields and moved to the common package. This allows us to +**Breaking**: The FactRetriever model is extended by adding required title and description fields. This allows us to display Fact Retrievers in the UI in future. If you have existing custom `FactRetriever` implementations hardcoded, you'll need to add a `title` and `description` to them. diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index 616d0f2c79..32d45f8afd 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -9,7 +9,7 @@ import express from 'express'; import { FactChecker } from '@backstage/plugin-tech-insights-node'; import { FactCheckerFactory } from '@backstage/plugin-tech-insights-node'; import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; +import { FactRetriever } from '@backstage/plugin-tech-insights-node'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; import { FactSchema } from '@backstage/plugin-tech-insights-node'; import { Logger } from 'winston'; diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts index 34b816479d..454711171f 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts @@ -14,6 +14,7 @@ * limitations under the License. */ import { + FactRetriever, FactRetrieverRegistration, FactSchemaDefinition, TechInsightFact, @@ -29,15 +30,12 @@ import { import { ConfigReader } from '@backstage/config'; import { TestDatabaseId, TestDatabases } from '@backstage/backend-test-utils'; import { TaskScheduler } from '@backstage/backend-tasks'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; jest.useFakeTimers(); const testFactRetriever: FactRetriever = { id: 'test_factretriever', version: '0.0.1', - title: 'Test 1', - description: 'testing', entityFilter: [{ kind: 'component' }], schema: { testnumberfact: { diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts index 1d37e4d857..25e7610809 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.ts @@ -15,6 +15,7 @@ */ import { FactLifecycle, + FactRetriever, FactRetrieverContext, FactRetrieverRegistration, TechInsightFact, @@ -24,7 +25,6 @@ import { FactRetrieverRegistry } from './FactRetrieverRegistry'; import { Logger } from 'winston'; import { PluginTaskScheduler } from '@backstage/backend-tasks'; import { Duration } from 'luxon'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; function randomDailyCron() { const rand = (min: number, max: number) => diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts index 17139f0992..504d561f17 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts @@ -15,11 +15,11 @@ */ import { + FactRetriever, FactRetrieverRegistration, FactSchema, } from '@backstage/plugin-tech-insights-node'; import { ConflictError, NotFoundError } from '@backstage/errors'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * @public diff --git a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts index bd4960d10f..de49888e1b 100644 --- a/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/createFactRetriever.ts @@ -15,15 +15,15 @@ */ import { FactLifecycle, + FactRetriever, FactRetrieverRegistration, } from '@backstage/plugin-tech-insights-node'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * @public * * @param cadence - cron expression to indicate when the fact retriever should be triggered - * @param factRetriever - Implementation of fact retriever definition + * @param factRetriever - Implementation of fact retriever consisting of at least id, version, schema and handler * @param lifecycle - Optional lifecycle definition indicating the cleanup logic of facts when this retriever is run * */ diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts index 7bddb4c0c6..3103f9bdd5 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityMetadataFactRetriever.ts @@ -14,11 +14,13 @@ * limitations under the License. */ -import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; +import { + FactRetriever, + FactRetrieverContext, +} from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; import isEmpty from 'lodash/isEmpty'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * Generates facts which indicate the completeness of entity metadata. diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts index 39fbd0dea7..974f1d30cd 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/entityOwnershipFactRetriever.ts @@ -14,10 +14,12 @@ * limitations under the License. */ -import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; +import { + FactRetriever, + FactRetrieverContext, +} from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * Generates facts which indicate the quality of data in the spec.owner field. diff --git a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts index 95b043cfc8..dc14298a55 100644 --- a/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts +++ b/plugins/tech-insights-backend/src/service/fact/factRetrievers/techdocsFactRetriever.ts @@ -14,11 +14,13 @@ * limitations under the License. */ -import { FactRetrieverContext } from '@backstage/plugin-tech-insights-node'; +import { + FactRetriever, + FactRetrieverContext, +} from '@backstage/plugin-tech-insights-node'; import { CatalogClient } from '@backstage/catalog-client'; import { Entity } from '@backstage/catalog-model'; import { entityHasAnnotation, generateAnnotationFactName } from './utils'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; const techdocsAnnotation = 'backstage.io/techdocs-ref'; const techdocsAnnotationFactName = diff --git a/plugins/tech-insights-common/api-report.md b/plugins/tech-insights-common/api-report.md index 746d99f663..0236c0619a 100644 --- a/plugins/tech-insights-common/api-report.md +++ b/plugins/tech-insights-common/api-report.md @@ -4,10 +4,7 @@ ```ts import { DateTime } from 'luxon'; -import { FactRetrieverContext } from '../../tech-insights-node'; -import { FactSchema } from '../../tech-insights-node'; import { JsonValue } from '@backstage/types'; -import { TechInsightFact } from '../../tech-insights-node'; // @public export interface BooleanCheckResult extends CheckResult { @@ -50,18 +47,5 @@ export type FactResponse = { }; }; -// @public -export interface FactRetriever { - description: string; - entityFilter?: - | Record[] - | Record; - handler: (ctx: FactRetrieverContext) => Promise; - id: string; - schema: FactSchema; - title: string; - version: string; -} - // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/tech-insights-common/package.json b/plugins/tech-insights-common/package.json index bc98cdb888..14ec147bb9 100644 --- a/plugins/tech-insights-common/package.json +++ b/plugins/tech-insights-common/package.json @@ -35,8 +35,7 @@ "dependencies": { "@types/luxon": "^2.0.5", "luxon": "^2.0.2", - "@backstage/types": "^1.0.0", - "@backstage/plugin-tech-insights-node": "^0.3.1" + "@backstage/types": "^1.0.0" }, "devDependencies": { "@backstage/cli": "^0.18.0-next.1" diff --git a/plugins/tech-insights-common/src/index.ts b/plugins/tech-insights-common/src/index.ts index 42abb3dd44..66af5c2f93 100644 --- a/plugins/tech-insights-common/src/index.ts +++ b/plugins/tech-insights-common/src/index.ts @@ -16,11 +16,6 @@ import { DateTime } from 'luxon'; import { JsonValue } from '@backstage/types'; -import { - FactRetrieverContext, - FactSchema, - TechInsightFact, -} from '@backstage/plugin-tech-insights-node'; /** * @public @@ -106,63 +101,6 @@ export type FactResponse = { }; }; -/** - * FactRetriever interface - * - * @public - */ -export interface FactRetriever { - /** - * A unique identifier of the retriever. - * Used to identify and store individual facts returned from this retriever - * and schemas defined by this retriever. - */ - id: string; - - /** - * Semver string indicating the version of this fact retriever - * This version is used to determine if the schema this fact retriever matches the data this fact retriever provides. - * - * Should be incremented on changes to returned data from the handler or if the schema changes. - */ - version: string; - - /** - * A short display title for the fact retriever to be used in the interface - */ - title: string; - - /** - * A short display description for the fact retriever to be used in the interface. - */ - description: string; - - /** - * Handler function that needs to be implemented to retrieve fact values for entities. - * - * @param ctx - FactRetrieverContext which can be used to retrieve config and contact integrations - * @returns - A collection of TechInsightFacts grouped by entities. - */ - handler: (ctx: FactRetrieverContext) => Promise; - - /** - * A fact schema defining the shape of data returned from the handler method for each entity - */ - schema: FactSchema; - - /** - * An optional object/array of objects of entity filters to indicate if this fact retriever is valid for an entity type. - * If omitted, the retriever should apply to all entities. - * - * Should be defined for example: - * \{ field: 'kind', values: \['component'\] \} - * \{ field: 'metadata.name', values: \['component-1', 'component-2'\] \} - */ - entityFilter?: - | Record[] - | Record; -} - /** * Generic CheckResult * diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 0ca1e22787..060158a619 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,7 +8,6 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; import { PluginEndpointDiscovery } from '@backstage/backend-common'; @@ -45,6 +44,19 @@ export interface FactCheckerFactory< // @public export type FactLifecycle = TTL | MaxItems; +// @public +export interface FactRetriever { + description: string; + entityFilter?: + | Record[] + | Record; + handler: (ctx: FactRetrieverContext) => Promise; + id: string; + schema: FactSchema; + title: string; + version: string; +} + // @public export type FactRetrieverContext = { config: Config; diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index 6c37616b0c..6905a12f9c 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -21,7 +21,6 @@ import { TokenManager, } from '@backstage/backend-common'; import { Logger } from 'winston'; -import { FactRetriever } from '@backstage/plugin-tech-insights-common'; /** * A container for facts. The shape of the fact records needs to correspond to the FactSchema with same `ref` value. @@ -154,6 +153,63 @@ export type FactRetrieverContext = { | Record; }; +/** + * FactRetriever interface + * + * @public + */ +export interface FactRetriever { + /** + * A unique identifier of the retriever. + * Used to identify and store individual facts returned from this retriever + * and schemas defined by this retriever. + */ + id: string; + + /** + * Semver string indicating the version of this fact retriever + * This version is used to determine if the schema this fact retriever matches the data this fact retriever provides. + * + * Should be incremented on changes to returned data from the handler or if the schema changes. + */ + version: string; + + /** + * A short display title for the fact retriever to be used in the interface + */ + title: string; + + /** + * A short display description for the fact retriever to be used in the interface. + */ + description: string; + + /** + * Handler function that needs to be implemented to retrieve fact values for entities. + * + * @param ctx - FactRetrieverContext which can be used to retrieve config and contact integrations + * @returns - A collection of TechInsightFacts grouped by entities. + */ + handler: (ctx: FactRetrieverContext) => Promise; + + /** + * A fact schema defining the shape of data returned from the handler method for each entity + */ + schema: FactSchema; + + /** + * An optional object/array of objects of entity filters to indicate if this fact retriever is valid for an entity type. + * If omitted, the retriever should apply to all entities. + * + * Should be defined for example: + * \{ field: 'kind', values: \['component'\] \} + * \{ field: 'metadata.name', values: \['component-1', 'component-2'\] \} + */ + entityFilter?: + | Record[] + | Record; +} + /** * A Luxon duration like object for time to live value * diff --git a/yarn.lock b/yarn.lock index 8f557e9551..f06a187ebf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1535,59 +1535,6 @@ "@babel/helper-validator-identifier" "^7.16.7" to-fast-properties "^2.0.0" -"@backstage/backend-common@^0.14.0": - version "0.14.0" - resolved "https://registry.npmjs.org/@backstage/backend-common/-/backend-common-0.14.0.tgz#da7537c7a58ce596db36be3bb584b9c199f58296" - integrity sha512-xiEOknaWtyfiWcL8+fkQKMfSnpQr1FsKFX6xVc74Lrgmd46VMW7pbhDQULQDaeCN+jhwTfxCcsemhtcJjimq+w== - dependencies: - "@backstage/cli-common" "^0.1.9" - "@backstage/config" "^1.0.1" - "@backstage/config-loader" "^1.1.2" - "@backstage/errors" "^1.0.0" - "@backstage/integration" "^1.2.1" - "@backstage/types" "^1.0.0" - "@google-cloud/storage" "^6.0.0" - "@keyv/redis" "^2.2.3" - "@manypkg/get-packages" "^1.1.3" - "@octokit/rest" "^18.5.3" - "@types/cors" "^2.8.6" - "@types/dockerode" "^3.3.0" - "@types/express" "^4.17.6" - "@types/luxon" "^2.0.4" - "@types/webpack-env" "^1.15.2" - archiver "^5.0.2" - aws-sdk "^2.840.0" - base64-stream "^1.0.0" - compression "^1.7.4" - concat-stream "^2.0.0" - cors "^2.8.5" - dockerode "^3.3.1" - express "^4.17.1" - express-promise-router "^4.1.0" - fs-extra "10.1.0" - git-url-parse "^11.6.0" - helmet "^5.0.2" - isomorphic-git "^1.8.0" - jose "^4.6.0" - keyv "^4.0.3" - keyv-memcache "^1.2.5" - knex "^1.0.2" - lodash "^4.17.21" - logform "^2.3.2" - luxon "^2.3.1" - minimatch "^5.0.0" - minimist "^1.2.5" - morgan "^1.10.0" - node-abort-controller "^3.0.1" - node-fetch "^2.6.7" - raw-body "^2.4.1" - selfsigned "^2.0.0" - stoppable "^1.1.0" - tar "^6.1.2" - unzipper "^0.10.11" - winston "^3.2.1" - yn "^4.0.0" - "@backstage/catalog-client@^1.0.3": version "1.0.3" resolved "https://registry.npmjs.org/@backstage/catalog-client/-/catalog-client-1.0.3.tgz#cb91472ccc31df322f69e7e4e80939b3535660cd" @@ -1610,27 +1557,6 @@ lodash "^4.17.21" uuid "^8.0.0" -"@backstage/config-loader@^1.1.2": - version "1.1.2" - resolved "https://registry.npmjs.org/@backstage/config-loader/-/config-loader-1.1.2.tgz#72cb0d7b2647f5a646bb279360bc34732e06521f" - integrity sha512-c5ZO7xDJn609DBIsYAWGE5kgh+7SPYUmG2ADtVX9SbXaql3VCafGlhc2hAZQa/O12W04qi3GgwGg0bqSFmx5uw== - dependencies: - "@backstage/cli-common" "^0.1.9" - "@backstage/config" "^1.0.1" - "@backstage/errors" "^1.0.0" - "@backstage/types" "^1.0.0" - "@types/json-schema" "^7.0.6" - ajv "^8.10.0" - chokidar "^3.5.2" - fs-extra "10.1.0" - json-schema "^0.4.0" - json-schema-merge-allof "^0.8.1" - json-schema-traverse "^1.0.0" - node-fetch "^2.6.7" - typescript-json-schema "^0.53.0" - yaml "^1.9.2" - yup "^0.32.9" - "@backstage/core-components@^0.9.0", "@backstage/core-components@^0.9.5": version "0.9.5" resolved "https://registry.npmjs.org/@backstage/core-components/-/core-components-0.9.5.tgz#5a0b34867aaee0549bfa67b39a69c09588fa3c7a" @@ -1821,19 +1747,6 @@ qs "^6.9.4" react-use "^17.2.4" -"@backstage/plugin-tech-insights-node@^0.3.1": - version "0.3.1" - resolved "https://registry.npmjs.org/@backstage/plugin-tech-insights-node/-/plugin-tech-insights-node-0.3.1.tgz#d9bf40b07c57bac67b251ac8d53c0ad26ad2e651" - integrity sha512-okfIZIVUVdhejqmd9UHaVg42VukHPT0RIVeUblALXDxip9PND+W4hKgZTRs7/2Z/IWOxGyGLEwAkRG0QSLnysg== - dependencies: - "@backstage/backend-common" "^0.14.0" - "@backstage/config" "^1.0.1" - "@backstage/plugin-tech-insights-common" "^0.2.4" - "@backstage/types" "^1.0.0" - "@types/luxon" "^2.0.5" - luxon "^2.0.2" - winston "^3.2.1" - "@backstage/theme@^0.2.15", "@backstage/theme@^0.2.6", "@backstage/theme@^0.2.7", "@backstage/theme@^0.2.9": version "0.2.15" resolved "https://registry.npmjs.org/@backstage/theme/-/theme-0.2.15.tgz#478491c9bca9dca85d5af08767ba512eabcd3669" @@ -17139,26 +17052,6 @@ kleur@^4.0.3, kleur@^4.1.4: resolved "https://registry.npmjs.org/kleur/-/kleur-4.1.4.tgz#8c202987d7e577766d039a8cd461934c01cda04d" integrity sha512-8QADVssbrFjivHWQU7KkMgptGTl6WAcSdlbBPY4uNF+mWr6DGcKrvY2w4FQJoXch7+fKMjj0dRrL75vk3k23OA== -knex@^1.0.2: - version "1.0.7" - resolved "https://registry.npmjs.org/knex/-/knex-1.0.7.tgz#965f4490efc451b140aac4c5c6efa39fd877597b" - integrity sha512-89jxuRATt4qJMb9ZyyaKBy0pQ4d5h7eOFRqiNFnUvsgU+9WZ2eIaZKrAPG1+F3mgu5UloPUnkVE5Yo2sKZUs6Q== - dependencies: - colorette "2.0.16" - commander "^9.1.0" - debug "4.3.4" - escalade "^3.1.1" - esm "^3.2.25" - get-package-type "^0.1.0" - getopts "2.3.0" - interpret "^2.2.0" - lodash "^4.17.21" - pg-connection-string "2.5.0" - rechoir "^0.8.0" - resolve-from "^5.0.0" - tarn "^3.0.2" - tildify "2.0.0" - knex@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/knex/-/knex-2.1.0.tgz#9348aace3a08ff5be26eb1c8e838416ddf1aa216" @@ -20527,11 +20420,6 @@ path-case@^3.0.4: dot-case "^3.0.4" tslib "^2.0.3" -path-equal@1.1.2: - version "1.1.2" - resolved "https://registry.npmjs.org/path-equal/-/path-equal-1.1.2.tgz#260e7c449c4c2022f68cc5fa6e617e892858250d" - integrity sha512-p5kxPPwCdbf5AdXzT1bUBJomhgBlEjRBavYNr1XUpMFIE4Hnf2roueCMXudZK5tnaAu1tTmp3GPzqwJK45IHEA== - path-equal@^1.1.2: version "1.2.2" resolved "https://registry.npmjs.org/path-equal/-/path-equal-1.2.2.tgz#fa2997f0a829de22ec8f5f86461ca5590d49b832" @@ -25330,20 +25218,6 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript-json-schema@^0.53.0: - version "0.53.1" - resolved "https://registry.npmjs.org/typescript-json-schema/-/typescript-json-schema-0.53.1.tgz#9204547f3e145169b40928998366ff6d28b81d32" - integrity sha512-Hg+RnOKUd38MOzC0rDft03a8xvwO+gCcj1F77smw2tCoZYQpFoLtrXWBGdvCX+REliko5WYel2kux17HPFqjLQ== - dependencies: - "@types/json-schema" "^7.0.9" - "@types/node" "^16.9.2" - glob "^7.1.7" - path-equal "1.1.2" - safe-stable-stringify "^2.2.0" - ts-node "^10.2.1" - typescript "~4.6.0" - yargs "^17.1.1" - typescript-json-schema@^0.54.0: version "0.54.0" resolved "https://registry.npmjs.org/typescript-json-schema/-/typescript-json-schema-0.54.0.tgz#b3fc42ad90df6a0f6ab57571ebc8b4d41125df4f" From 307ade749948966d7e01ffa6de3b78a95a091fd5 Mon Sep 17 00:00:00 2001 From: sblausten Date: Wed, 6 Jul 2022 17:17:52 +0200 Subject: [PATCH 5/6] Fix test and make fields optional Signed-off-by: sblausten --- .changeset/rich-steaks-juggle.md | 8 +++----- .../src/service/fact/FactRetrieverEngine.test.ts | 2 ++ plugins/tech-insights-node/api-report.md | 4 ++-- plugins/tech-insights-node/src/facts.ts | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.changeset/rich-steaks-juggle.md b/.changeset/rich-steaks-juggle.md index 291e9dac2b..f47de1af0d 100644 --- a/.changeset/rich-steaks-juggle.md +++ b/.changeset/rich-steaks-juggle.md @@ -1,9 +1,7 @@ --- -'@backstage/plugin-tech-insights-node': minor +'@backstage/plugin-tech-insights-node': patch '@backstage/plugin-tech-insights-backend': patch --- -**Breaking**: The FactRetriever model is extended by adding required title and description fields. This allows us to -display Fact Retrievers in the UI in future. - -If you have existing custom `FactRetriever` implementations hardcoded, you'll need to add a `title` and `description` to them. +The FactRetriever model is extended by adding optional title and description fields. This allows us to display Fact +Retrievers in the UI in future. diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts index 454711171f..f9b145c876 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverEngine.test.ts @@ -36,6 +36,8 @@ jest.useFakeTimers(); const testFactRetriever: FactRetriever = { id: 'test_factretriever', version: '0.0.1', + title: 'Test 1', + description: 'testing', entityFilter: [{ kind: 'component' }], schema: { testnumberfact: { diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 060158a619..84677bdcbc 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -46,14 +46,14 @@ export type FactLifecycle = TTL | MaxItems; // @public export interface FactRetriever { - description: string; + description?: string; entityFilter?: | Record[] | Record; handler: (ctx: FactRetrieverContext) => Promise; id: string; schema: FactSchema; - title: string; + title?: string; version: string; } diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index 6905a12f9c..cda238694f 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -177,12 +177,12 @@ export interface FactRetriever { /** * A short display title for the fact retriever to be used in the interface */ - title: string; + title?: string; /** * A short display description for the fact retriever to be used in the interface. */ - description: string; + description?: string; /** * Handler function that needs to be implemented to retrieve fact values for entities. From 2dbbb583c5d4a87a263b4f11805e796d1f8ed1f8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 6 Jul 2022 17:40:40 +0200 Subject: [PATCH 6/6] Update .changeset/rich-steaks-juggle.md Signed-off-by: sblausten --- .changeset/rich-steaks-juggle.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.changeset/rich-steaks-juggle.md b/.changeset/rich-steaks-juggle.md index f47de1af0d..5879f2dace 100644 --- a/.changeset/rich-steaks-juggle.md +++ b/.changeset/rich-steaks-juggle.md @@ -3,5 +3,4 @@ '@backstage/plugin-tech-insights-backend': patch --- -The FactRetriever model is extended by adding optional title and description fields. This allows us to display Fact -Retrievers in the UI in future. +The `FactRetriever` model has been extended by adding optional title and description fields, allowing you to display them in the UI.