Merge branch 'master' of https://github.com/backstage/backstage into marley/7678-pull-request-custom-filters-2
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
"@backstage/core-plugin-api": "^0.4.1",
|
||||
"@backstage/plugin-catalog": "^0.7.7",
|
||||
"@backstage/plugin-catalog-react": "^0.6.10",
|
||||
"@date-io/luxon": "1.x",
|
||||
"@date-io/luxon": "2.x",
|
||||
"@material-ui/core": "^4.12.2",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.57",
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"@backstage/errors": "^0.1.3",
|
||||
"@backstage/plugin-catalog-react": "^0.6.10",
|
||||
"@backstage/theme": "^0.2.14",
|
||||
"@date-io/luxon": "1.x",
|
||||
"@date-io/luxon": "2.x",
|
||||
"@material-ui/core": "^4.12.2",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.57",
|
||||
|
||||
@@ -36,7 +36,8 @@ yarn add @backstage/plugin-sonarqube
|
||||
|
||||
3. Add the proxy config:
|
||||
|
||||
Provide a method for your Backstage backend to get to your SonarQube API end point. Add configuration to your `app-config.yaml` file depending on the product you use.
|
||||
Provide a method for your Backstage backend to get to your SonarQube API end point. Add configuration to your `app-config.yaml` file depending on the product you use. Make sure to keep the trailing colon after the `SONARQUBE_TOKEN`, it is required to call
|
||||
the Web API (see [docs](https://docs.sonarqube.org/latest/extend/web-api/)).
|
||||
|
||||
**SonarCloud**
|
||||
|
||||
@@ -45,6 +46,7 @@ proxy:
|
||||
'/sonarqube':
|
||||
target: https://sonarcloud.io/api
|
||||
allowedMethods: ['GET']
|
||||
# note that the colon after the token is required
|
||||
auth: '${SONARQUBE_TOKEN}:'
|
||||
# Environmental variable: SONARQUBE_TOKEN
|
||||
# Fetch the sonar-auth-token from https://sonarcloud.io/account/security/
|
||||
@@ -57,6 +59,7 @@ proxy:
|
||||
'/sonarqube':
|
||||
target: https://your.sonarqube.instance.com/api
|
||||
allowedMethods: ['GET']
|
||||
# note that the colon after the token is required
|
||||
auth: '${SONARQUBE_TOKEN}:'
|
||||
# Environmental variable: SONARQUBE_TOKEN
|
||||
# Fetch the sonar-auth-token from https://sonarcloud.io/account/security/
|
||||
@@ -65,7 +68,7 @@ sonarQube:
|
||||
baseUrl: https://your.sonarqube.instance.com
|
||||
```
|
||||
|
||||
4. Get and provide `SONARQUBE_TOKEN` as an env variable (https://sonarcloud.io/account/security or https://docs.sonarqube.org/latest/user-guide/user-token/)
|
||||
4. Get and provide `SONARQUBE_TOKEN` as an env variable (https://sonarcloud.io/account/security or https://docs.sonarqube.org/latest/user-guide/user-token/).
|
||||
|
||||
5. Run the following commands in the root folder of the project to install and compile the changes.
|
||||
|
||||
|
||||
+6
-2
@@ -35,6 +35,7 @@ import { pick } from 'lodash';
|
||||
import Ajv, { SchemaObject } from 'ajv';
|
||||
import * as validationSchema from './validation-schema.json';
|
||||
import { JSON_RULE_ENGINE_CHECK_TYPE } from '../constants';
|
||||
import { isError } from '@backstage/errors';
|
||||
|
||||
const noopEvent = {
|
||||
type: 'noop',
|
||||
@@ -117,7 +118,7 @@ export class JsonRulesEngineFactChecker
|
||||
if (hasAllFacts) {
|
||||
engine.addRule({ ...techInsightCheck.rule, event: noopEvent });
|
||||
} else {
|
||||
this.logger.warn(
|
||||
this.logger.debug(
|
||||
`Skipping ${
|
||||
rule.name
|
||||
} due to missing facts: ${techInsightCheck.factIds
|
||||
@@ -139,7 +140,10 @@ export class JsonRulesEngineFactChecker
|
||||
Object.values(facts),
|
||||
);
|
||||
} catch (e) {
|
||||
throw new Error(`Failed to run rules engine, ${e.message}`);
|
||||
if (isError(e)) {
|
||||
throw new Error(`Failed to run rules engine, ${e.message}`);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,6 +112,8 @@ export class TechInsightsDatabase implements TechInsightsStore {
|
||||
this.db('facts')
|
||||
.max('timestamp')
|
||||
.column('id as subId')
|
||||
.where({ entity: entityTriplet })
|
||||
.and.whereIn('id', ids)
|
||||
.groupBy('id')
|
||||
.as('subQ'),
|
||||
'facts.id',
|
||||
|
||||
@@ -27,10 +27,12 @@ import { Logger } from 'winston';
|
||||
import { DateTime } from 'luxon';
|
||||
import { PersistenceContext } from './persistence/persistenceContext';
|
||||
import {
|
||||
EntityName,
|
||||
EntityRef,
|
||||
parseEntityName,
|
||||
stringifyEntityRef,
|
||||
} from '@backstage/catalog-model';
|
||||
import { errorHandler } from '@backstage/backend-common';
|
||||
|
||||
/**
|
||||
* @public
|
||||
@@ -91,14 +93,26 @@ export async function createRouter<
|
||||
|
||||
router.post('/checks/run/:namespace/:kind/:name', async (req, res) => {
|
||||
const { namespace, kind, name } = req.params;
|
||||
try {
|
||||
const { checks }: { checks: string[] } = req.body;
|
||||
const entityTriplet = stringifyEntityRef({ namespace, kind, name });
|
||||
const checkResult = await factChecker.runChecks(entityTriplet, checks);
|
||||
return res.send(checkResult);
|
||||
} catch (e) {
|
||||
return res.status(500).json({ message: e.message }).send();
|
||||
}
|
||||
const { checks }: { checks: string[] } = req.body;
|
||||
const entityTriplet = stringifyEntityRef({ namespace, kind, name });
|
||||
const checkResult = await factChecker.runChecks(entityTriplet, checks);
|
||||
return res.send(checkResult);
|
||||
});
|
||||
|
||||
router.post('/checks/run', async (req, res) => {
|
||||
const { checks, entities }: { checks: string[]; entities: EntityName[] } =
|
||||
req.body;
|
||||
const tasks = entities.map(async entity => {
|
||||
const entityTriplet =
|
||||
typeof entity === 'string' ? entity : stringifyEntityRef(entity);
|
||||
const results = await factChecker.runChecks(entityTriplet, checks);
|
||||
return {
|
||||
entity: entityTriplet,
|
||||
results,
|
||||
};
|
||||
});
|
||||
const results = await Promise.all(tasks);
|
||||
return res.send(results);
|
||||
});
|
||||
} else {
|
||||
logger.info(
|
||||
@@ -153,5 +167,7 @@ export async function createRouter<
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
router.use(errorHandler());
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,12 @@ export interface BooleanCheckResult extends CheckResult {
|
||||
result: boolean;
|
||||
}
|
||||
|
||||
// @public
|
||||
export type BulkCheckResponse = Array<{
|
||||
entity: string;
|
||||
results: CheckResult[];
|
||||
}>;
|
||||
|
||||
// @public
|
||||
export interface CheckResponse {
|
||||
description: string;
|
||||
|
||||
@@ -124,3 +124,13 @@ export type CheckResult = {
|
||||
export interface BooleanCheckResult extends CheckResult {
|
||||
result: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Response type for bulk check opretation. Contains a list of entities and their respective check results.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type BulkCheckResponse = Array<{
|
||||
entity: string;
|
||||
results: CheckResult[];
|
||||
}>;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
import { ApiRef } from '@backstage/core-plugin-api';
|
||||
import { BackstagePlugin } from '@backstage/core-plugin-api';
|
||||
import { BulkCheckResponse } from '@backstage/plugin-tech-insights-common';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
import { default as React_2 } from 'react';
|
||||
@@ -50,6 +51,11 @@ export interface TechInsightsApi {
|
||||
description?: string,
|
||||
) => CheckResultRenderer | undefined;
|
||||
// (undocumented)
|
||||
runBulkChecks(
|
||||
entities: EntityName[],
|
||||
checks?: Check[],
|
||||
): Promise<BulkCheckResponse>;
|
||||
// (undocumented)
|
||||
runChecks(entityParams: EntityName, checks?: Check[]): Promise<CheckResult[]>;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
|
||||
import { createApiRef } from '@backstage/core-plugin-api';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import {
|
||||
CheckResult,
|
||||
BulkCheckResponse,
|
||||
} from '@backstage/plugin-tech-insights-common';
|
||||
import { Check } from './types';
|
||||
import { CheckResultRenderer } from '../components/CheckResultRenderer';
|
||||
import { EntityName } from '@backstage/catalog-model';
|
||||
@@ -43,4 +46,8 @@ export interface TechInsightsApi {
|
||||
) => CheckResultRenderer | undefined;
|
||||
getAllChecks(): Promise<Check[]>;
|
||||
runChecks(entityParams: EntityName, checks?: Check[]): Promise<CheckResult[]>;
|
||||
runBulkChecks(
|
||||
entities: EntityName[],
|
||||
checks?: Check[],
|
||||
): Promise<BulkCheckResponse>;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
*/
|
||||
|
||||
import { TechInsightsApi } from './TechInsightsApi';
|
||||
import { CheckResult } from '@backstage/plugin-tech-insights-common';
|
||||
import {
|
||||
BulkCheckResponse,
|
||||
CheckResult,
|
||||
} from '@backstage/plugin-tech-insights-common';
|
||||
import { Check } from './types';
|
||||
import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api';
|
||||
import { ResponseError } from '@backstage/errors';
|
||||
@@ -97,4 +100,29 @@ export class TechInsightsClient implements TechInsightsApi {
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
async runBulkChecks(
|
||||
entities: EntityName[],
|
||||
checks?: Check[],
|
||||
): Promise<BulkCheckResponse> {
|
||||
const url = await this.discoveryApi.getBaseUrl('tech-insights');
|
||||
const token = await this.identityApi.getIdToken();
|
||||
const checkIds = checks ? checks.map(check => check.id) : [];
|
||||
const requestBody = {
|
||||
entities,
|
||||
checks: checkIds.length > 0 ? checkIds : undefined,
|
||||
};
|
||||
const response = await fetch(`${url}/checks/run`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(requestBody),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(token && { Authorization: `Bearer ${token}` }),
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw await ResponseError.fromResponse(response);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user