From: Grégoire Aubert Date: Thu, 8 Mar 2018 10:33:10 +0000 (+0100) Subject: SONAR-10457 Display correct quality gate status on short lived branches X-Git-Tag: 7.5~1537 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=acabda0cc1514ad1d1913dd0729600c71852f59d;p=sonarqube.git SONAR-10457 Display correct quality gate status on short lived branches --- diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx index 7eac067d8dc..5258daf383f 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranch-test.tsx @@ -52,7 +52,7 @@ it('renders short-living branch', () => { isMain: false, mergeBranch: 'master', name: 'foo', - status: { bugs: 0, codeSmells: 0, vulnerabilities: 0 }, + status: { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 }, type: BranchType.SHORT }; const component = {} as Component; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx index bb43ec60c63..5a318153fb9 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenu-test.tsx @@ -94,7 +94,7 @@ function shortBranch(name: string, isOrphan?: true): ShortLivingBranch { isOrphan, mergeBranch: 'master', name, - status: { bugs: 0, codeSmells: 0, vulnerabilities: 0 }, + status: { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 }, type: BranchType.SHORT }; } @@ -108,7 +108,7 @@ function pullRequest(title: string): PullRequest { base: 'master', branch: 'feature', key: '1234', - status: { bugs: 0, codeSmells: 0, vulnerabilities: 0 }, + status: { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 }, title }; } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenuItem-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenuItem-test.tsx index 0635bea82a8..01995e7f92d 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenuItem-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBranchesMenuItem-test.tsx @@ -28,7 +28,7 @@ const shortBranch: ShortLivingBranch = { isMain: false, mergeBranch: 'master', name: 'foo', - status: { bugs: 1, codeSmells: 2, vulnerabilities: 3 }, + status: { bugs: 1, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, type: BranchType.SHORT }; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx index 62bdbdbb715..c6bff99c4a9 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx @@ -37,7 +37,7 @@ it('renders status of short-living branch', () => { isMain: false, mergeBranch: 'master', name: 'feature', - status: { bugs: 0, codeSmells: 2, vulnerabilities: 3 }, + status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, type: BranchType.SHORT }; expect( @@ -74,7 +74,7 @@ it('renders meta for pull request', () => { base: 'master', branch: 'feature', key: '1234', - status: { bugs: 0, codeSmells: 2, vulnerabilities: 3 }, + status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, title: 'Feature PR', url: 'https://example.com/pull/1234' }; diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap index 6e45772bb56..5f53fb0b983 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranch-test.tsx.snap @@ -152,6 +152,7 @@ exports[`renders short-living branch 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "type": "SHORT", diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenu-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenu-test.tsx.snap index cc51efd1976..b30b921ae6b 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenu-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenu-test.tsx.snap @@ -55,6 +55,7 @@ exports[`renders list 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "title": "qux", @@ -99,6 +100,7 @@ exports[`renders list 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "type": "SHORT", @@ -127,6 +129,7 @@ exports[`renders list 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "type": "SHORT", @@ -195,6 +198,7 @@ exports[`renders list 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "type": "SHORT", @@ -250,6 +254,7 @@ exports[`searches 1`] = ` "status": Object { "bugs": 0, "codeSmells": 0, + "qualityGateStatus": "OK", "vulnerabilities": 0, }, "type": "SHORT", diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap index 781da6de591..df7c8da7b47 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap @@ -97,6 +97,7 @@ exports[`renders short-living branch 1`] = ` "status": Object { "bugs": 1, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "type": "SHORT", @@ -118,6 +119,7 @@ exports[`renders short-living branch 1`] = ` "status": Object { "bugs": 1, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "type": "SHORT", @@ -169,6 +171,7 @@ exports[`renders short-living orhpan branch 1`] = ` "status": Object { "bugs": 1, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "type": "SHORT", @@ -191,6 +194,7 @@ exports[`renders short-living orhpan branch 1`] = ` "status": Object { "bugs": 1, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "type": "SHORT", diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap index 46e1c4becd7..06f96d32ee3 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap @@ -61,6 +61,7 @@ exports[`renders meta for pull request 1`] = ` "status": Object { "bugs": 0, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "title": "Feature PR", @@ -95,6 +96,7 @@ exports[`renders status of short-living branch 1`] = ` "status": Object { "bugs": 0, "codeSmells": 2, + "qualityGateStatus": "ERROR", "vulnerabilities": 3, }, "type": "SHORT", diff --git a/server/sonar-web/src/main/js/app/types.ts b/server/sonar-web/src/main/js/app/types.ts index 106d76e679f..922cbf8cf69 100644 --- a/server/sonar-web/src/main/js/app/types.ts +++ b/server/sonar-web/src/main/js/app/types.ts @@ -360,6 +360,7 @@ export interface PullRequest { status?: { bugs: number; codeSmells: number; + qualityGateStatus: string; vulnerabilities: number; }; title: string; @@ -440,6 +441,7 @@ export interface ShortLivingBranch extends Branch { status?: { bugs: number; codeSmells: number; + qualityGateStatus: string; vulnerabilities: number; }; type: BranchType.SHORT; diff --git a/server/sonar-web/src/main/js/components/common/BranchStatus.tsx b/server/sonar-web/src/main/js/components/common/BranchStatus.tsx index d2e3f992973..b2e40112112 100644 --- a/server/sonar-web/src/main/js/components/common/BranchStatus.tsx +++ b/server/sonar-web/src/main/js/components/common/BranchStatus.tsx @@ -22,9 +22,12 @@ import StatusIndicator from './StatusIndicator'; import Level from '../ui/Level'; import BugIcon from '../icons-components/BugIcon'; import CodeSmellIcon from '../icons-components/CodeSmellIcon'; +import HelpIcon from '../icons-components/HelpIcon'; +import Tooltip from '../controls/Tooltip'; import VulnerabilityIcon from '../icons-components/VulnerabilityIcon'; import { BranchLike } from '../../app/types'; import { isShortLivingBranch, isPullRequest, isLongLivingBranch } from '../../helpers/branches'; +import { translateWithParameters } from '../../helpers/l10n'; import './BranchStatus.css'; interface Props { @@ -40,8 +43,8 @@ export default function BranchStatus({ branchLike, concise = false }: Props) { const totalIssues = branchLike.status.bugs + branchLike.status.vulnerabilities + branchLike.status.codeSmells; - - const indicatorColor = totalIssues > 0 ? 'red' : 'green'; + const indicatorColor = getQualityGateColor(branchLike.status.qualityGateStatus); + const shouldDisplayHelper = branchLike.status.qualityGateStatus === 'OK' && totalIssues > 0; return concise ? ( ) : ( ); } else if (isLongLivingBranch(branchLike)) { @@ -79,3 +94,15 @@ export default function BranchStatus({ branchLike, concise = false }: Props) { return null; } } + +function getQualityGateColor(status: string) { + let indicatorColor = 'gray'; + if (status === 'ERROR') { + indicatorColor = 'red'; + } else if (status === 'WARN') { + indicatorColor = 'orange'; + } else if (status === 'OK') { + indicatorColor = 'green'; + } + return indicatorColor; +} diff --git a/server/sonar-web/src/main/js/components/common/StatusIndicator.css b/server/sonar-web/src/main/js/components/common/StatusIndicator.css index a7e86044211..9d0949597ac 100644 --- a/server/sonar-web/src/main/js/components/common/StatusIndicator.css +++ b/server/sonar-web/src/main/js/components/common/StatusIndicator.css @@ -51,3 +51,11 @@ .status-indicator.green { background-color: var(--green); } + +.status-indicator.orange { + background-color: var(--orange); +} + +.status-indicator.gray { + background-color: var(--gray71); +} diff --git a/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx index 12aef459919..516d2f6c222 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx @@ -23,16 +23,22 @@ import BranchStatus from '../BranchStatus'; import { BranchType, LongLivingBranch, ShortLivingBranch } from '../../../app/types'; it('renders status of short-living branches', () => { - checkShort(0, 0, 0); - checkShort(0, 1, 0); - checkShort(7, 3, 6); + checkShort('OK', 0, 0, 0); + checkShort('WARN', 0, 1, 0); + checkShort('ERROR', 7, 3, 6); + checkShort('OK', 0, 0, 1); - function checkShort(bugs: number, codeSmells: number, vulnerabilities: number) { + function checkShort( + qualityGateStatus: string, + bugs: number, + codeSmells: number, + vulnerabilities: number + ) { const shortBranch: ShortLivingBranch = { isMain: false, mergeBranch: 'master', name: 'foo', - status: { bugs, codeSmells, vulnerabilities }, + status: { bugs, codeSmells, qualityGateStatus, vulnerabilities }, type: BranchType.SHORT }; expect(shallow()).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap index d648e77db49..e10d3e2826b 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap @@ -19,7 +19,7 @@ exports[`renders status of short-living branches 1`] = ` className="branch-status" >
  • 0 - +
  • 0 - +
  • 0 - +
  • `; @@ -52,10 +58,10 @@ exports[`renders status of short-living branches 2`] = ` className="branch-status" >
  • @@ -63,19 +69,25 @@ exports[`renders status of short-living branches 2`] = ` className="spacer-left" > 0 - +
  • 0 - +
  • 1 - +
  • `; @@ -85,7 +97,7 @@ exports[`renders status of short-living branches 3`] = ` className="branch-status" >
  • 7 - +
  • 6 - +
  • 3 - + +
  • + +`; + +exports[`renders status of short-living branches 4`] = ` +
      +
    • +
    • +
    • + 0 + +
    • +
    • + 1 + +
    • +
    • + 0 + +
    • + +
    • + +
    • +
    `; diff --git a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts index abf8bd87438..934ef060ecc 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/branches-test.ts @@ -78,8 +78,12 @@ describe('#isSameBranchLike', () => { }); it('compares pull requests', () => { - expect(isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '1234' }))).toBeTruthy(); - expect(isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '5678' }))).toBeFalsy(); + expect( + isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '1234' })) + ).toBeTruthy(); + expect( + isSameBranchLike(pullRequest({ key: '1234' }), pullRequest({ key: '5678' })) + ).toBeFalsy(); }); it('compares branches', () => { @@ -103,7 +107,7 @@ function mainBranch(): MainBranch { } function shortLivingBranch(overrides?: Partial): ShortLivingBranch { - const status = { bugs: 0, codeSmells: 0, vulnerabilities: 0 }; + const status = { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 }; return { isMain: false, mergeBranch: 'master', @@ -120,7 +124,7 @@ function longLivingBranch(overrides?: Partial): LongLivingBran } function pullRequest(overrides?: Partial): PullRequest { - const status = { bugs: 0, codeSmells: 0, vulnerabilities: 0 }; + const status = { bugs: 0, codeSmells: 0, qualityGateStatus: 'OK', vulnerabilities: 0 }; return { base: 'master', branch: 'feature', diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index f5b5fb14f02..caf4db69304 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2650,6 +2650,7 @@ branches.no_support.header=Get the most out of SonarQube with branches analysis branches.no_support.header.text=Analyze each branch of your project separately with the Developer Edition. branches.search_for_branches=Search for branches... branches.pull_requests=Pull Requests +branches.short_lived.quality_gate.description=The branch status is passed because there are no open issue. The remaining {0} issue(s) have been confirmed. branches.short_lived_branches=Short-lived branches branches.pull_request.for_merge_into_x_from_y=for merge into {base} from {branch} branches.see_the_pr=See the PR