您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { IssueStatus } from '../../types/issues';
  21. import { MetricKey } from '../../types/metrics';
  22. import { Dict } from '../../types/types';
  23. const ISSUE_MEASURES = [
  24. MetricKey.violations,
  25. MetricKey.new_violations,
  26. MetricKey.blocker_violations,
  27. MetricKey.critical_violations,
  28. MetricKey.major_violations,
  29. MetricKey.minor_violations,
  30. MetricKey.info_violations,
  31. MetricKey.new_blocker_violations,
  32. MetricKey.new_critical_violations,
  33. MetricKey.new_major_violations,
  34. MetricKey.new_minor_violations,
  35. MetricKey.new_info_violations,
  36. MetricKey.open_issues,
  37. MetricKey.reopened_issues,
  38. MetricKey.confirmed_issues,
  39. MetricKey.false_positive_issues,
  40. MetricKey.code_smells,
  41. MetricKey.new_code_smells,
  42. MetricKey.bugs,
  43. MetricKey.new_bugs,
  44. MetricKey.vulnerabilities,
  45. MetricKey.new_vulnerabilities,
  46. ];
  47. export const DEFAULT_ISSUES_QUERY = {
  48. issueStatuses: `${IssueStatus.Open},${IssueStatus.Confirmed}`,
  49. };
  50. const issueParamsPerMetric: Dict<Dict<string>> = {
  51. [MetricKey.blocker_violations]: { severities: 'BLOCKER' },
  52. [MetricKey.new_blocker_violations]: { severities: 'BLOCKER' },
  53. [MetricKey.critical_violations]: { severities: 'CRITICAL' },
  54. [MetricKey.new_critical_violations]: { severities: 'CRITICAL' },
  55. [MetricKey.major_violations]: { severities: 'MAJOR' },
  56. [MetricKey.new_major_violations]: { severities: 'MAJOR' },
  57. [MetricKey.minor_violations]: { severities: 'MINOR' },
  58. [MetricKey.new_minor_violations]: { severities: 'MINOR' },
  59. [MetricKey.info_violations]: { severities: 'INFO' },
  60. [MetricKey.new_info_violations]: { severities: 'INFO' },
  61. [MetricKey.open_issues]: { issueStatuses: IssueStatus.Open },
  62. [MetricKey.reopened_issues]: { issueStatuses: IssueStatus.Open },
  63. [MetricKey.confirmed_issues]: { issueStatuses: IssueStatus.Confirmed },
  64. [MetricKey.false_positive_issues]: { issueStatuses: IssueStatus.FalsePositive },
  65. [MetricKey.code_smells]: { types: 'CODE_SMELL' },
  66. [MetricKey.new_code_smells]: { types: 'CODE_SMELL' },
  67. [MetricKey.bugs]: { types: 'BUG' },
  68. [MetricKey.new_bugs]: { types: 'BUG' },
  69. [MetricKey.vulnerabilities]: { types: 'VULNERABILITY' },
  70. [MetricKey.new_vulnerabilities]: { types: 'VULNERABILITY' },
  71. };
  72. export function isIssueMeasure(metric: string) {
  73. return ISSUE_MEASURES.indexOf(metric as MetricKey) !== -1;
  74. }
  75. export function propsToIssueParams(metric: string, inNewCodePeriod = false) {
  76. const params: Dict<string | boolean> = {
  77. ...DEFAULT_ISSUES_QUERY,
  78. ...issueParamsPerMetric[metric],
  79. };
  80. if (inNewCodePeriod) {
  81. params.inNewCodePeriod = true;
  82. }
  83. return params;
  84. }