]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21455 Load & Mock software quality impact measures in branch overview page
author7PH <benjamin.raymond@sonarsource.com>
Mon, 22 Jan 2024 10:24:41 +0000 (11:24 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 31 Jan 2024 20:03:35 +0000 (20:03 +0000)
server/sonar-web/src/main/js/api/measures.ts
server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx
server/sonar-web/src/main/js/apps/overview/utils.tsx
server/sonar-web/src/main/js/types/metrics.ts

index d1a15e7980812107ba973c6f25d92fe76dbc1ae9..b701d1cbe65791954be7443914fcdbccc7dfa739 100644 (file)
@@ -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<MeasuresAndMetaWithPeriod & MeasuresAndMetaWithMetrics> {
-  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(
index a69d6bdeeccb569c92cb8b54ecf11ccad34da879..eb6b0d9892d9be45e2ee89fc55303861b5d7750f 100644 (file)
@@ -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<Props, State> {
     // 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<Props, State> {
   ) => {
     return getMeasuresWithPeriodAndMetrics(
       componentKey,
-      metricKeys.length > 0 ? metricKeys : METRICS,
+      metricKeys.length > 0 ? metricKeys : BRANCH_OVERVIEW_METRICS,
       getBranchLikeQuery(branchLike),
     ).then(({ component: { measures }, metrics, period }) => {
       return {
index af64bfc79490cc6c49ad29e27038091f9a541b7c..a5002a83a74e50628b98131b7e382c4e059ec63a 100644 (file)
@@ -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,
index 043b54fd979041b9a2279cd7e83d54d174fc5737..c59e1aadaf42b8b8a27348d577b1de17b1d82152 100644 (file)
@@ -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',