aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/portfolio/utils.ts
blob: fe3bae452fb33d6fb4c8bbb85650d5410ed3f4c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
///
/// SonarQube
/// Copyright (C) 2009-2018 SonarSource SA
/// mailto:info AT sonarsource DOT com
///
/// This program is free software; you can redistribute it and/or
/// modify it under the terms of the GNU Lesser General Public
/// License as published by the Free Software Foundation; either
/// version 3 of the License, or (at your option) any later version.
///
/// This program is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
/// Lesser General Public License for more details.
///
/// You should have received a copy of the GNU Lesser General Public License
/// along with this program; if not, write to the Free Software Foundation,
/// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
///

/*
 * SonarQube
 * Copyright (C) 2009-2016 SonarSource SA
 * mailto:contact AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
export function getNextRating(rating: number): number | undefined {
  return rating > 1 ? rating - 1 : undefined;
}

function getWorstSeverity(data: string): { severity: string; count: number } | undefined {
  const SEVERITY_ORDER = ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'];

  const severities: { [key: string]: number } = {};
  data.split(';').forEach(equality => {
    const [key, count] = equality.split('=');
    severities[key] = Number(count);
  });

  for (let i = 0; i < SEVERITY_ORDER.length; i++) {
    const count = severities[SEVERITY_ORDER[i]];
    if (count > 0) {
      return { severity: SEVERITY_ORDER[i], count };
    }
  }

  return undefined;
}

export function getEffortToNextRating(
  measures: Array<{ metric: { key: string }; value: string }>,
  metricKey: string
) {
  const measure = measures.find(measure => measure.metric.key === metricKey);
  if (!measure) {
    return undefined;
  }
  return getWorstSeverity(measure.value);
}

export const PORTFOLIO_METRICS = [
  'projects',
  'ncloc',
  'ncloc_language_distribution',

  'releasability_rating',
  'releasability_effort',

  'sqale_rating',
  'maintainability_rating_effort',

  'reliability_rating',
  'reliability_rating_effort',

  'security_rating',
  'security_rating_effort',

  'last_change_on_releasability_rating',
  'last_change_on_maintainability_rating',
  'last_change_on_security_rating',
  'last_change_on_reliability_rating'
];

export const SUB_COMPONENTS_METRICS = [
  'ncloc',
  'releasability_rating',
  'security_rating',
  'reliability_rating',
  'sqale_rating',
  'alert_status'
];

export function convertMeasures(measures: Array<{ metric: string; value?: string }>) {
  const result: { [key: string]: string | undefined } = {};
  measures.forEach(measure => {
    result[measure.metric] = measure.value;
  });
  return result;
}