import { ApplicationPeriod } from '../../../types/application';
import { BranchLike } from '../../../types/branch-like';
import { ComponentQualifier } from '../../../types/component';
+import { IssueType } from '../../../types/issues';
import { MetricKey } from '../../../types/metrics';
import MeasurementLabel from '../components/MeasurementLabel';
-import { IssueType, MeasurementType } from '../utils';
+import { MeasurementType } from '../utils';
import { DrilldownMeasureValue } from './DrilldownMeasureValue';
import { LeakPeriodInfo } from './LeakPeriodInfo';
import MeasuresPanelIssueMeasureRow from './MeasuresPanelIssueMeasureRow';
import * as React from 'react';
import { BranchLike } from '../../../types/branch-like';
import { ComponentQualifier } from '../../../types/component';
+import { IssueType } from '../../../types/issues';
import IssueLabel from '../components/IssueLabel';
import IssueRating from '../components/IssueRating';
-import { IssueType } from '../utils';
import DebtValue from './DebtValue';
import SecurityHotspotsReviewed from './SecurityHotspotsReviewed';
import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
import { ComponentQualifier } from '../../../../types/component';
+import { IssueType } from '../../../../types/issues';
import { MetricKey } from '../../../../types/metrics';
-import { IssueType } from '../../utils';
import MeasuresPanelIssueMeasureRow, {
MeasuresPanelIssueMeasureRowProps
} from '../MeasuresPanelIssueMeasureRow';
import { findMeasure } from '../../../helpers/measures';
import { getComponentIssuesUrl, getComponentSecurityHotspotsUrl } from '../../../helpers/urls';
import { BranchLike } from '../../../types/branch-like';
-import { getIssueIconClass, getIssueMetricKey, IssueType } from '../utils';
+import { IssueType } from '../../../types/issues';
+import { getIssueIconClass, getIssueMetricKey } from '../utils';
export interface IssueLabelProps {
branchLike?: BranchLike;
import DrilldownLink from '../../../components/shared/DrilldownLink';
import { findMeasure } from '../../../helpers/measures';
import { BranchLike } from '../../../types/branch-like';
-import { getIssueRatingMetricKey, getIssueRatingName, IssueType } from '../utils';
+import { IssueType } from '../../../types/issues';
+import { getIssueRatingMetricKey, getIssueRatingName } from '../utils';
export interface IssueRatingProps {
branchLike?: BranchLike;
import * as React from 'react';
import { mockPullRequest } from '../../../../helpers/mocks/branch-like';
import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
+import { IssueType } from '../../../../types/issues';
import { MetricKey } from '../../../../types/metrics';
-import { IssueType } from '../../utils';
import { IssueLabel, IssueLabelProps } from '../IssueLabel';
it('should render correctly for bugs', () => {
import * as React from 'react';
import { mockPullRequest } from '../../../../helpers/mocks/branch-like';
import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
+import { IssueType } from '../../../../types/issues';
import { MetricKey } from '../../../../types/metrics';
-import { IssueType } from '../../utils';
import { IssueRating, IssueRatingProps } from '../IssueRating';
it('should render correctly for bugs', () => {
import { fetchBranchStatus } from '../../../store/rootActions';
import { getBranchStatusByBranchLike, Store } from '../../../store/rootReducer';
import { BranchLike, PullRequest } from '../../../types/branch-like';
+import { IssueType } from '../../../types/issues';
import { QualityGateStatusCondition } from '../../../types/quality-gates';
import IssueLabel from '../components/IssueLabel';
import IssueRating from '../components/IssueRating';
import MeasurementLabel from '../components/MeasurementLabel';
import QualityGateConditions from '../components/QualityGateConditions';
import '../styles.css';
-import { IssueType, MeasurementType, PR_METRICS } from '../utils';
+import { MeasurementType, PR_METRICS } from '../utils';
import AfterMergeEstimate from './AfterMergeEstimate';
import LargeQualityGateBadge from './LargeQualityGateBadge';
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import BugIcon from 'sonar-ui-common/components/icons/BugIcon';
-import CodeSmellIcon from 'sonar-ui-common/components/icons/CodeSmellIcon';
-import SecurityHotspotIcon from 'sonar-ui-common/components/icons/SecurityHotspotIcon';
-import VulnerabilityIcon from 'sonar-ui-common/components/icons/VulnerabilityIcon';
import DuplicationsRating from 'sonar-ui-common/components/ui/DuplicationsRating';
import { translate } from 'sonar-ui-common/helpers/l10n';
import CoverageRating from '../../components/ui/CoverageRating';
+import { ISSUETYPE_METRIC_KEYS_MAP } from '../../helpers/issues';
+import { IssueType } from '../../types/issues';
import { MetricKey } from '../../types/metrics';
export const METRICS: string[] = [
}
};
-export enum IssueType {
- CodeSmell = 'CODE_SMELL',
- Vulnerability = 'VULNERABILITY',
- Bug = 'BUG',
- SecurityHotspot = 'SECURITY_HOTSPOT'
-}
-
-const ISSUETYPE_MAP = {
- [IssueType.CodeSmell]: {
- metric: MetricKey.code_smells,
- newMetric: MetricKey.new_code_smells,
- rating: MetricKey.sqale_rating,
- newRating: MetricKey.new_maintainability_rating,
- ratingName: 'Maintainability',
- iconClass: CodeSmellIcon
- },
- [IssueType.Vulnerability]: {
- metric: MetricKey.vulnerabilities,
- newMetric: MetricKey.new_vulnerabilities,
- rating: MetricKey.security_rating,
- newRating: MetricKey.new_security_rating,
- ratingName: 'Security',
- iconClass: VulnerabilityIcon
- },
- [IssueType.Bug]: {
- metric: MetricKey.bugs,
- newMetric: MetricKey.new_bugs,
- rating: MetricKey.reliability_rating,
- newRating: MetricKey.new_reliability_rating,
- ratingName: 'Reliability',
- iconClass: BugIcon
- },
- [IssueType.SecurityHotspot]: {
- metric: MetricKey.security_hotspots,
- newMetric: MetricKey.new_security_hotspots,
- rating: MetricKey.security_review_rating,
- newRating: MetricKey.new_security_review_rating,
- ratingName: 'SecurityReview',
- iconClass: SecurityHotspotIcon
- }
-};
-
export function getIssueRatingName(type: IssueType) {
- return translate('metric_domain', ISSUETYPE_MAP[type].ratingName);
+ return translate('metric_domain', ISSUETYPE_METRIC_KEYS_MAP[type].ratingName);
}
export function getIssueIconClass(type: IssueType) {
- return ISSUETYPE_MAP[type].iconClass;
+ return ISSUETYPE_METRIC_KEYS_MAP[type].iconClass;
}
export function getIssueMetricKey(type: IssueType, useDiffMetric: boolean) {
- return useDiffMetric ? ISSUETYPE_MAP[type].newMetric : ISSUETYPE_MAP[type].metric;
+ return useDiffMetric
+ ? ISSUETYPE_METRIC_KEYS_MAP[type].newMetric
+ : ISSUETYPE_METRIC_KEYS_MAP[type].metric;
}
export function getIssueRatingMetricKey(type: IssueType, useDiffMetric: boolean) {
- return useDiffMetric ? ISSUETYPE_MAP[type].newRating : ISSUETYPE_MAP[type].rating;
+ return useDiffMetric
+ ? ISSUETYPE_METRIC_KEYS_MAP[type].newRating
+ : ISSUETYPE_METRIC_KEYS_MAP[type].rating;
}
export function getMeasurementIconClass(type: MeasurementType) {
import { omitNil } from 'sonar-ui-common/helpers/request';
import { getBaseUrl, getPathUrlAsString } from 'sonar-ui-common/helpers/urls';
import { getBranchLikeQuery } from '../../helpers/branch-like';
+import { ISSUE_TYPES } from '../../helpers/constants';
+import { ISSUETYPE_METRIC_KEYS_MAP } from '../../helpers/issues';
import { getBranchLikeUrl, getCodeUrl, getComponentIssuesUrl } from '../../helpers/urls';
import { BranchLike } from '../../types/branch-like';
import { ComponentQualifier } from '../../types/component';
measuresOverlay: boolean;
}
-const METRIC_KEY_FOR_ISSUE_TYPE: { [type in T.IssueType]: string } = {
- BUG: 'bugs',
- VULNERABILITY: 'vulnerabilities',
- CODE_SMELL: 'code_smells',
- SECURITY_HOTSPOT: 'security_hotspots'
-};
-
export default class SourceViewerHeader extends React.PureComponent<Props, State> {
state: State = { measuresOverlay: false };
<>
<div className="source-viewer-header-measure-separator" />
- {['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'].map((type: T.IssueType) => {
+ {ISSUE_TYPES.map((type: T.IssueType) => {
const params = {
...getBranchLikeQuery(branchLike),
fileUuids: sourceViewerFile.uuid,
};
const measure = componentMeasures.find(
- m => m.metric === METRIC_KEY_FOR_ISSUE_TYPE[type]
+ m => m.metric === ISSUETYPE_METRIC_KEYS_MAP[type].metric
);
return (
<div className="source-viewer-header-measure" key={type}>
import * as React from 'react';
import { mockMainBranch } from '../../../helpers/mocks/branch-like';
import { mockSourceViewerFile } from '../../../helpers/testMocks';
+import { MetricKey } from '../../../types/metrics';
import SourceViewerHeader from '../SourceViewerHeader';
it('should render correctly for a regular file', () => {
it('should render correctly if issue details are passed', () => {
const componentMeasures: T.Measure[] = [
- { metric: 'code_smells', value: '1' },
- { metric: 'unused_metric_to_be_ignored', value: '42' },
- { metric: 'security_hotspots', value: '2' },
- { metric: 'vulnerabilities', value: '2' }
+ { metric: MetricKey.code_smells, value: '1' },
+ { metric: MetricKey.file_complexity_distribution, value: '42' }, // unused, should be ignored
+ { metric: MetricKey.security_hotspots, value: '2' },
+ { metric: MetricKey.vulnerabilities, value: '2' }
];
expect(
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { colors } from '../app/theme';
+import { IssueType } from '../types/issues';
export const SEVERITIES = ['BLOCKER', 'CRITICAL', 'MAJOR', 'MINOR', 'INFO'];
export const STATUSES = ['OPEN', 'REOPENED', 'CONFIRMED', 'RESOLVED', 'CLOSED'];
export const ISSUE_TYPES: T.IssueType[] = [
- 'BUG',
- 'VULNERABILITY',
- 'CODE_SMELL',
- 'SECURITY_HOTSPOT'
+ IssueType.Bug,
+ IssueType.Vulnerability,
+ IssueType.CodeSmell,
+ IssueType.SecurityHotspot
];
export const RULE_TYPES: T.RuleType[] = ['BUG', 'VULNERABILITY', 'CODE_SMELL', 'SECURITY_HOTSPOT'];
export const RULE_STATUSES = ['READY', 'BETA', 'DEPRECATED'];
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { flatten, sortBy } from 'lodash';
+import BugIcon from 'sonar-ui-common/components/icons/BugIcon';
+import CodeSmellIcon from 'sonar-ui-common/components/icons/CodeSmellIcon';
+import SecurityHotspotIcon from 'sonar-ui-common/components/icons/SecurityHotspotIcon';
+import VulnerabilityIcon from 'sonar-ui-common/components/icons/VulnerabilityIcon';
+import { IssueType } from '../types/issues';
+import { MetricKey } from '../types/metrics';
import { ISSUE_TYPES } from './constants';
interface Comment {
...ensureTextRange(issue)
} as T.Issue;
}
+
+export const ISSUETYPE_METRIC_KEYS_MAP = {
+ [IssueType.CodeSmell]: {
+ metric: MetricKey.code_smells,
+ newMetric: MetricKey.new_code_smells,
+ rating: MetricKey.sqale_rating,
+ newRating: MetricKey.new_maintainability_rating,
+ ratingName: 'Maintainability',
+ iconClass: CodeSmellIcon
+ },
+ [IssueType.Vulnerability]: {
+ metric: MetricKey.vulnerabilities,
+ newMetric: MetricKey.new_vulnerabilities,
+ rating: MetricKey.security_rating,
+ newRating: MetricKey.new_security_rating,
+ ratingName: 'Security',
+ iconClass: VulnerabilityIcon
+ },
+ [IssueType.Bug]: {
+ metric: MetricKey.bugs,
+ newMetric: MetricKey.new_bugs,
+ rating: MetricKey.reliability_rating,
+ newRating: MetricKey.new_reliability_rating,
+ ratingName: 'Reliability',
+ iconClass: BugIcon
+ },
+ [IssueType.SecurityHotspot]: {
+ metric: MetricKey.security_hotspots,
+ newMetric: MetricKey.new_security_hotspots,
+ rating: MetricKey.security_review_rating,
+ newRating: MetricKey.new_security_review_rating,
+ ratingName: 'SecurityReview',
+ iconClass: SecurityHotspotIcon
+ }
+};
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.
+ */
+
+export enum IssueType {
+ CodeSmell = 'CODE_SMELL',
+ Vulnerability = 'VULNERABILITY',
+ Bug = 'BUG',
+ SecurityHotspot = 'SECURITY_HOTSPOT'
+}