From: 7PH Date: Mon, 22 Jan 2024 10:24:41 +0000 (+0100) Subject: SONAR-21455 Load & Mock software quality impact measures in branch overview page X-Git-Tag: 10.4.0.87286~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=de8e2d2710db116ce0c3d6dd17499223f5e8cd07;p=sonarqube.git SONAR-21455 Load & Mock software quality impact measures in branch overview page --- diff --git a/server/sonar-web/src/main/js/api/measures.ts b/server/sonar-web/src/main/js/api/measures.ts index d1a15e79808..b701d1cbe65 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'; @@ -61,17 +62,102 @@ export function getMeasuresWithPeriod( }).catch(throwGlobalError); } -export function getMeasuresWithPeriodAndMetrics( +export async function getMeasuresWithPeriodAndMetrics( component: string, metrics: string[], branchParameters?: BranchParameters, ): Promise { - return getJSON(COMPONENT_URL, { + // TODO: Remove this mock (SONAR-21488) + const mockedMetrics = metrics.filter( + (metric) => + ![ + MetricKey.maintainability_issues, + MetricKey.reliability_issues, + MetricKey.security_issues, + ].includes(metric as MetricKey), + ); + const result = await getJSON(COMPONENT_URL, { additionalFields: 'period,metrics', component, - metricKeys: metrics.join(','), + metricKeys: mockedMetrics.join(','), ...branchParameters, }).catch(throwGlobalError); + if (metrics.includes(MetricKey.maintainability_issues)) { + result.metrics.push({ + key: MetricKey.maintainability_issues, + name: 'Maintainability Issues', + description: 'Maintainability Issues', + domain: 'Maintainability', + type: MetricType.Data, + higherValuesAreBetter: false, + qualitative: true, + hidden: false, + bestValue: '0', + }); + result.component.measures?.push({ + metric: MetricKey.maintainability_issues, + period: { + index: 0, + value: JSON.stringify({ + total: 3, + high: 1, + medium: 1, + low: 1, + }), + }, + }); + } + if (metrics.includes(MetricKey.reliability_issues)) { + result.metrics.push({ + key: MetricKey.reliability_issues, + name: 'Reliability Issues', + description: 'Reliability Issues', + domain: 'Reliability', + type: MetricType.Data, + higherValuesAreBetter: false, + qualitative: true, + hidden: false, + bestValue: '0', + }); + result.component.measures?.push({ + metric: MetricKey.reliability_issues, + period: { + index: 0, + value: JSON.stringify({ + total: 2, + high: 0, + medium: 1, + low: 1, + }), + }, + }); + } + if (metrics.includes(MetricKey.security_issues)) { + result.metrics.push({ + key: MetricKey.security_issues, + name: 'Security Issues', + description: 'Security Issues', + domain: 'Security', + type: MetricType.Data, + higherValuesAreBetter: false, + qualitative: true, + hidden: false, + bestValue: '0', + }); + result.component.measures?.push({ + metric: MetricKey.security_issues, + period: { + index: 0, + value: JSON.stringify({ + total: 1, + high: 0, + medium: 0, + low: 1, + }), + }, + }); + } + return result; } export function getMeasuresForProjects( diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx index a69d6bdeecc..eb6b0d9892d 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx @@ -54,7 +54,7 @@ import { Analysis, GraphType, MeasureHistory } from '../../../types/project-acti import { QualityGateStatus, QualityGateStatusCondition } from '../../../types/quality-gates'; import { Component, MeasureEnhanced, Metric, Period, QualityGate } from '../../../types/types'; import '../styles.css'; -import { HISTORY_METRICS_LIST, METRICS } from '../utils'; +import { BRANCH_OVERVIEW_METRICS, HISTORY_METRICS_LIST } from '../utils'; import BranchOverviewRenderer from './BranchOverviewRenderer'; interface Props { @@ -236,8 +236,8 @@ export default class BranchOverview extends React.PureComponent { // render them. const metricKeys = projectStatus.conditions !== undefined - ? uniq([...METRICS, ...projectStatus.conditions.map((c) => c.metricKey)]) - : METRICS; + ? uniq([...BRANCH_OVERVIEW_METRICS, ...projectStatus.conditions.map((c) => c.metricKey)]) + : BRANCH_OVERVIEW_METRICS; this.loadMeasuresAndMeta(key, branch, metricKeys).then( ({ measures, metrics, period }) => { @@ -289,7 +289,7 @@ export default class BranchOverview extends React.PureComponent { ) => { return getMeasuresWithPeriodAndMetrics( componentKey, - metricKeys.length > 0 ? metricKeys : METRICS, + metricKeys.length > 0 ? metricKeys : BRANCH_OVERVIEW_METRICS, getBranchLikeQuery(branchLike), ).then(({ component: { measures }, metrics, period }) => { return { diff --git a/server/sonar-web/src/main/js/apps/overview/utils.tsx b/server/sonar-web/src/main/js/apps/overview/utils.tsx index af64bfc7949..a5002a83a74 100644 --- a/server/sonar-web/src/main/js/apps/overview/utils.tsx +++ b/server/sonar-web/src/main/js/apps/overview/utils.tsx @@ -32,7 +32,7 @@ import { AnalysisMeasuresVariations, MeasureHistory } from '../../types/project- import { QualityGateStatusConditionEnhanced } from '../../types/quality-gates'; import { Dict, RawQuery } from '../../types/types'; -export const METRICS: string[] = [ +export const BRANCH_OVERVIEW_METRICS: string[] = [ // quality gate MetricKey.alert_status, MetricKey.quality_gate_details, // TODO: still relevant? @@ -42,6 +42,9 @@ export const METRICS: string[] = [ MetricKey.accepted_issues, MetricKey.new_accepted_issues, MetricKey.high_impact_accepted_issues, + MetricKey.maintainability_issues, + MetricKey.reliability_issues, + MetricKey.security_issues, // bugs MetricKey.bugs, diff --git a/server/sonar-web/src/main/js/types/metrics.ts b/server/sonar-web/src/main/js/types/metrics.ts index 043b54fd979..c59e1aadaf4 100644 --- a/server/sonar-web/src/main/js/types/metrics.ts +++ b/server/sonar-web/src/main/js/types/metrics.ts @@ -69,6 +69,7 @@ export enum MetricKey { line_coverage = 'line_coverage', lines = 'lines', lines_to_cover = 'lines_to_cover', + maintainability_issues = 'maintainability_issues', maintainability_rating_distribution = 'maintainability_rating_distribution', maintainability_rating_effort = 'maintainability_rating_effort', major_violations = 'major_violations', @@ -123,6 +124,7 @@ export enum MetricKey { releasability_effort = 'releasability_effort', releasability_rating = 'releasability_rating', releasability_rating_distribution = 'releasability_rating_distribution', + reliability_issues = 'reliability_issues', reliability_rating = 'reliability_rating', reliability_rating_effort = 'reliability_rating_effort', reliability_rating_distribution = 'reliability_rating_distribution', @@ -130,6 +132,7 @@ export enum MetricKey { reopened_issues = 'reopened_issues', security_hotspots = 'security_hotspots', security_hotspots_reviewed = 'security_hotspots_reviewed', + security_issues = 'security_issues', security_rating = 'security_rating', security_rating_effort = 'security_rating_effort', security_rating_distribution = 'security_rating_distribution',