Merge pull request #15975 from tr-fteixeira/ft/tech-insights-api-fact-schemas

feat(tech-inights): adds getFactSchemas method to client
This commit is contained in:
Fredrik Adelöw
2023-01-31 10:28:11 +01:00
committed by GitHub
12 changed files with 110 additions and 78 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ 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 { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node';
import { FactSchema } from '@backstage/plugin-tech-insights-node';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { HumanDuration } from '@backstage/types';
import { Logger } from 'winston';
import { PluginDatabaseManager } from '@backstage/backend-common';
@@ -17,8 +17,8 @@
import {
FactRetriever,
FactRetrieverRegistration,
FactSchema,
} from '@backstage/plugin-tech-insights-node';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { ConflictError, NotFoundError } from '@backstage/errors';
/**
@@ -16,12 +16,12 @@
import { Knex } from 'knex';
import {
FactLifecycle,
FactSchema,
FactSchemaDefinition,
FlatTechInsightFact,
TechInsightFact,
TechInsightsStore,
} from '@backstage/plugin-tech-insights-node';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { rsort } from 'semver';
import { groupBy, omit } from 'lodash';
import { DateTime } from 'luxon';
@@ -47,5 +47,22 @@ export type FactResponse = {
};
};
// @public
export type FactSchema = {
[name: string]: {
type:
| 'integer'
| 'float'
| 'string'
| 'boolean'
| 'datetime'
| 'set'
| 'object';
description: string;
since?: string;
metadata?: Record<string, any>;
};
};
// (No @packageDocumentation comment for this package)
```
+57
View File
@@ -134,3 +134,60 @@ export type BulkCheckResponse = Array<{
entity: string;
results: CheckResult[];
}>;
/**
* A record type to specify individual fact shapes
*
* Used as part of a schema to validate, identify and generically construct usage implementations
* of individual fact values in the system.
*
* @public
*/
export type FactSchema = {
/**
* Name of the fact
*/
[name: string]: {
/**
* Type of the individual fact value
*
* Numbers are split into integers and floating point values.
* `set` indicates a collection of values, `object` indicates JSON serializable value
*/
type:
| 'integer'
| 'float'
| 'string'
| 'boolean'
| 'datetime'
| 'set'
| 'object';
/**
* A description of this individual fact value
*/
description: string;
/**
* Optional semver string to indicate when this specific fact definition was added to the schema
*/
since?: string;
/**
* Metadata related to an individual fact.
* Can contain links, additional description texts and other actionable data.
*
* Currently loosely typed, but in the future when patterns emerge, key shapes can be defined
*
* examples:
* ```
* \{
* link: 'https://sonarqube.mycompany.com/fix-these-issues',
* suggestion: 'To affect this value, you can do x, y, z',
* minValue: 0
* \}
* ```
*/
metadata?: Record<string, any>;
};
};
+1 -17
View File
@@ -8,6 +8,7 @@ import { Config } from '@backstage/config';
import { DateTime } from 'luxon';
import { Duration } from 'luxon';
import { DurationLike } from 'luxon';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { HumanDuration } from '@backstage/types';
import { JsonValue } from '@backstage/types';
import { Logger } from 'winston';
@@ -78,23 +79,6 @@ export type FactRetrieverRegistration = {
initialDelay?: Duration | HumanDuration;
};
// @public
export type FactSchema = {
[name: string]: {
type:
| 'integer'
| 'float'
| 'string'
| 'boolean'
| 'datetime'
| 'set'
| 'object';
description: string;
since?: string;
metadata?: Record<string, any>;
};
};
// @public
export type FactSchemaDefinition = Omit<FactRetriever, 'handler'>;
+1 -57
View File
@@ -20,6 +20,7 @@ import {
PluginEndpointDiscovery,
TokenManager,
} from '@backstage/backend-common';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { Logger } from 'winston';
/**
@@ -79,63 +80,6 @@ export type FlatTechInsightFact = TechInsightFact & {
id: string;
};
/**
* A record type to specify individual fact shapes
*
* Used as part of a schema to validate, identify and generically construct usage implementations
* of individual fact values in the system.
*
* @public
*/
export type FactSchema = {
/**
* Name of the fact
*/
[name: string]: {
/**
* Type of the individual fact value
*
* Numbers are split into integers and floating point values.
* `set` indicates a collection of values, `object` indicates JSON serializable value
*/
type:
| 'integer'
| 'float'
| 'string'
| 'boolean'
| 'datetime'
| 'set'
| 'object';
/**
* A description of this individual fact value
*/
description: string;
/**
* Optional semver string to indicate when this specific fact definition was added to the schema
*/
since?: string;
/**
* Metadata related to an individual fact.
* Can contain links, additional description texts and other actionable data.
*
* Currently loosely typed, but in the future when patterns emerge, key shapes can be defined
*
* examples:
* ```
* \{
* link: 'https://sonarqube.mycompany.com/fix-these-issues',
* suggestion: 'To affect this value, you can do x, y, z',
* minValue: 0
* \}
* ```
*/
metadata?: Record<string, any>;
};
};
/**
* @public
*
@@ -14,13 +14,13 @@
* limitations under the License.
*/
import {
FactSchema,
TechInsightFact,
FlatTechInsightFact,
FactSchemaDefinition,
FactLifecycle,
} from './facts';
import { DateTime } from 'luxon';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
/**
* TechInsights Database
+5
View File
@@ -11,6 +11,7 @@ import { BulkCheckResponse } from '@backstage/plugin-tech-insights-common';
import { CheckResult } from '@backstage/plugin-tech-insights-common';
import { CompoundEntityRef } from '@backstage/catalog-model';
import { DiscoveryApi } from '@backstage/core-plugin-api';
import { FactSchema } from '@backstage/plugin-tech-insights-common';
import { IdentityApi } from '@backstage/core-plugin-api';
import { JsonValue } from '@backstage/types';
import { default as React_2 } from 'react';
@@ -74,6 +75,8 @@ export interface TechInsightsApi {
// (undocumented)
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
// (undocumented)
getFactSchemas(): Promise<FactSchema[]>;
// (undocumented)
runBulkChecks(
entities: CompoundEntityRef[],
checks?: Check[],
@@ -102,6 +105,8 @@ export class TechInsightsClient implements TechInsightsApi {
// (undocumented)
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
// (undocumented)
getFactSchemas(): Promise<FactSchema[]>;
// (undocumented)
runBulkChecks(
entities: CompoundEntityRef[],
checks?: Check[],
@@ -18,6 +18,7 @@ import { createApiRef } from '@backstage/core-plugin-api';
import {
CheckResult,
BulkCheckResponse,
FactSchema,
} from '@backstage/plugin-tech-insights-common';
import { Check, InsightFacts } from './types';
import { CheckResultRenderer } from '../components/CheckResultRenderer';
@@ -49,4 +50,5 @@ export interface TechInsightsApi {
checks?: Check[],
): Promise<BulkCheckResponse>;
getFacts(entity: CompoundEntityRef, facts: string[]): Promise<InsightFacts>;
getFactSchemas(): Promise<FactSchema[]>;
}
@@ -18,6 +18,7 @@ import { TechInsightsApi } from './TechInsightsApi';
import {
BulkCheckResponse,
CheckResult,
FactSchema,
} from '@backstage/plugin-tech-insights-common';
import { Check, InsightFacts } from './types';
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';
@@ -69,6 +70,10 @@ export class TechInsightsClient implements TechInsightsApi {
return this.api('/checks');
}
async getFactSchemas(): Promise<FactSchema[]> {
return this.api('/fact-schemas');
}
async runChecks(
entityParams: CompoundEntityRef,
checks?: string[],