Merge pull request #8657 from goenning/go/tech-insights-optimization

[Tech Insights] remove unecessary http request when running all checks
This commit is contained in:
Patrik Oldsberg
2021-12-30 16:31:49 +01:00
committed by GitHub
2 changed files with 9 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights': patch
---
remove unnecessary http request when running all checks
@@ -66,20 +66,20 @@ export class TechInsightsClient implements TechInsightsApi {
async runChecks(
entityParams: EntityName,
checks: Check[],
checks?: Check[],
): Promise<CheckResult[]> {
const url = await this.discoveryApi.getBaseUrl('tech-insights');
const token = await this.identityApi.getIdToken();
const { namespace, kind, name } = entityParams;
const allChecks = checks ? checks : await this.getAllChecks();
const checkIds = allChecks.map((check: Check) => check.id);
const checkIds = checks ? checks.map(check => check.id) : [];
const requestBody = { checks: checkIds.length > 0 ? checkIds : undefined };
const response = await fetch(
`${url}/checks/run/${encodeURIComponent(namespace)}/${encodeURIComponent(
kind,
)}/${encodeURIComponent(name)}`,
{
method: 'POST',
body: JSON.stringify({ checks: checkIds }),
body: JSON.stringify(requestBody),
headers: {
'Content-Type': 'application/json',
...(token && { Authorization: `Bearer ${token}` }),