From fb78dac5f434764fa5e18c8750aa4abcd630123f Mon Sep 17 00:00:00 2001 From: 7PH Date: Fri, 15 Dec 2023 12:13:04 +0100 Subject: [PATCH] SONAR-21259 SONAR-21273 Introduce new metrics and mock response --- server/sonar-web/src/main/js/api/measures.ts | 55 +++++++++++++++++-- server/sonar-web/src/main/js/types/metrics.ts | 2 + 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/api/measures.ts b/server/sonar-web/src/main/js/api/measures.ts index d1a15e79808..58389491d5d 100644 --- a/server/sonar-web/src/main/js/api/measures.ts +++ b/server/sonar-web/src/main/js/api/measures.ts @@ -25,6 +25,7 @@ import { MeasuresAndMetaWithPeriod, MeasuresForProjects, } from '../types/measures'; +import { MetricKey, MetricType } from '../types/metrics'; import { Measure } from '../types/types'; const COMPONENT_URL = '/api/measures/component'; @@ -35,17 +36,63 @@ export function getMeasures( return getJSON(COMPONENT_URL, data).then((r) => r.component.measures, throwGlobalError); } -export function getMeasuresWithMetrics( +export async function getMeasuresWithMetrics( component: string, metrics: string[], branchParameters?: BranchParameters, ): Promise { - return getJSON(COMPONENT_URL, { + // TODO: Remove this mock (SONAR-21259) + const mockedMetrics = metrics.filter( + (metric) => + metric !== MetricKey.pullrequest_addressed_issues && metric !== MetricKey.new_accepted_issues, + ); + const result = (await getJSON(COMPONENT_URL, { additionalFields: 'metrics', component, - metricKeys: metrics.join(','), + metricKeys: mockedMetrics.join(','), ...branchParameters, - }).catch(throwGlobalError); + }).catch(throwGlobalError)) as MeasuresAndMetaWithMetrics; + if (metrics.includes(MetricKey.pullrequest_addressed_issues)) { + result.metrics.push({ + key: MetricKey.pullrequest_addressed_issues, + name: 'Addressed Issues', + description: 'Addressed Issues', + domain: 'Reliability', + type: MetricType.Integer, + higherValuesAreBetter: false, + qualitative: true, + hidden: false, + bestValue: '0', + }); + result.component.measures?.push({ + metric: MetricKey.pullrequest_addressed_issues, + period: { + index: 0, + value: '11', + }, + }); + } + if (metrics.includes(MetricKey.new_accepted_issues)) { + result.metrics.push({ + key: MetricKey.new_accepted_issues, + name: 'Accepted Issues', + description: 'Accepted Issues', + domain: 'Reliability', + type: MetricType.Integer, + higherValuesAreBetter: false, + qualitative: true, + hidden: false, + bestValue: '0', + }); + result.component.measures?.push({ + metric: MetricKey.new_accepted_issues, + period: { + index: 0, + value: '12', + }, + }); + } + return result; } export function getMeasuresWithPeriod( diff --git a/server/sonar-web/src/main/js/types/metrics.ts b/server/sonar-web/src/main/js/types/metrics.ts index 80fa387761f..43e1cc79d95 100644 --- a/server/sonar-web/src/main/js/types/metrics.ts +++ b/server/sonar-web/src/main/js/types/metrics.ts @@ -76,6 +76,7 @@ export enum MetricKey { ncloc = 'ncloc', ncloc_data = 'ncloc_data', ncloc_language_distribution = 'ncloc_language_distribution', + new_accepted_issues = 'new_accepted_issues', new_blocker_violations = 'new_blocker_violations', new_branch_coverage = 'new_branch_coverage', new_bugs = 'new_bugs', @@ -116,6 +117,7 @@ export enum MetricKey { public_api = 'public_api', public_documented_api_density = 'public_documented_api_density', public_undocumented_api = 'public_undocumented_api', + pullrequest_addressed_issues = 'pullrequest_addressed_issues', quality_gate_details = 'quality_gate_details', quality_profiles = 'quality_profiles', releasability_effort = 'releasability_effort', -- 2.39.5