Skip to content

Commit 12ec1e7

Browse files
AndreiIurkoAndrei Iurko
andauthored
QD-10150 show fresh coverage green if a threshold was met (#441)
Co-authored-by: Andrei Iurko <[email protected]>
1 parent e9c04b4 commit 12ec1e7

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

scan/__tests__/data/some.sarif.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8261,13 +8261,16 @@
82618261
"qodanaFailureConditions": {
82628262
"testCoverageThresholds": {
82638263
"totalCoverage": 40,
8264-
"freshCoverage": 40
8264+
"freshCoverage": 30
82658265
}
82668266
},
82678267
"coverage": {
82688268
"totalCoverage": 45.0,
82698269
"totalLines": 124.0,
8270-
"totalCoveredLines": 56.0
8270+
"totalCoveredLines": 56.0,
8271+
"freshCoverage": 33.0,
8272+
"freshLines": 9.0,
8273+
"freshCoveredLines": 3.0
82718274
}
82728275
}
82738276
}

scan/__tests__/main.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ function passedCoverageFixture(): string {
362362
@@ Code coverage @@
363363
+ 45% total lines covered
364364
124 lines analyzed, 56 lines covered
365+
+ 33% fresh lines covered
366+
9 lines analyzed, 3 lines covered
365367
# Calculated according to the filters of your coverage tool
366368
\`\`\``
367369
}
@@ -371,7 +373,7 @@ function failedCoverageFixture(): string {
371373
@@ Code coverage @@
372374
- 0% total lines covered
373375
100 lines analyzed, 0 lines covered
374-
! 0% fresh lines covered
376+
- 0% fresh lines covered
375377
100 lines analyzed, 0 lines covered
376378
# Calculated according to the filters of your coverage tool
377379
\`\`\``

scan/dist/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137094,24 +137094,28 @@ ${message}
137094137094
\`\`\``;
137095137095
}
137096137096
__name(wrapToDiffBlock, "wrapToDiffBlock");
137097+
function makeConclusion(conclusion, failedByThreshold) {
137098+
if (failedByThreshold) {
137099+
return `- ${conclusion}`;
137100+
} else {
137101+
return `+ ${conclusion}`;
137102+
}
137103+
}
137104+
__name(makeConclusion, "makeConclusion");
137097137105
function getCoverageStats(c) {
137098137106
if (c.totalLines === 0 && c.totalCoveredLines === 0) {
137099137107
return "";
137100137108
}
137101137109
let stats = "";
137102137110
if (c.totalLines !== 0) {
137103-
let conclusion = `${c.totalCoverage}% total lines covered`;
137104-
if (c.totalCoverage < c.totalCoverageThreshold) {
137105-
conclusion = `- ${conclusion}`;
137106-
} else {
137107-
conclusion = `+ ${conclusion}`;
137108-
}
137109-
stats += `${conclusion}
137111+
const conclusion = `${c.totalCoverage}% total lines covered`;
137112+
stats += `${makeConclusion(conclusion, c.totalCoverage < c.totalCoverageThreshold)}
137110137113
${c.totalLines} lines analyzed, ${c.totalCoveredLines} lines covered`;
137111137114
}
137112137115
if (c.freshLines !== 0) {
137116+
const conclusion = `${c.freshCoverage}% fresh lines covered`;
137113137117
stats += `
137114-
! ${c.freshCoverage}% fresh lines covered
137118+
${makeConclusion(conclusion, c.freshCoverage < c.freshCoverageThreshold)}
137115137119
${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
137116137120
}
137117137121
return wrapToDiffBlock([

scan/src/output.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,33 @@ ${message}
9090
\`\`\``
9191
}
9292

93+
function makeConclusion(
94+
conclusion: string,
95+
failedByThreshold: boolean
96+
): string {
97+
if (failedByThreshold) {
98+
return `- ${conclusion}`
99+
} else {
100+
return `+ ${conclusion}`
101+
}
102+
}
103+
93104
export function getCoverageStats(c: Coverage): string {
94105
if (c.totalLines === 0 && c.totalCoveredLines === 0) {
95106
return ''
96107
}
97108

98109
let stats = ''
99110
if (c.totalLines !== 0) {
100-
let conclusion = `${c.totalCoverage}% total lines covered`
101-
if (c.totalCoverage < c.totalCoverageThreshold) {
102-
conclusion = `- ${conclusion}`
103-
} else {
104-
conclusion = `+ ${conclusion}`
105-
}
106-
stats += `${conclusion}
111+
const conclusion = `${c.totalCoverage}% total lines covered`
112+
stats += `${makeConclusion(conclusion, c.totalCoverage < c.totalCoverageThreshold)}
107113
${c.totalLines} lines analyzed, ${c.totalCoveredLines} lines covered`
108114
}
109115

110116
if (c.freshLines !== 0) {
117+
const conclusion = `${c.freshCoverage}% fresh lines covered`
111118
stats += `
112-
! ${c.freshCoverage}% fresh lines covered
119+
${makeConclusion(conclusion, c.freshCoverage < c.freshCoverageThreshold)}
113120
${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`
114121
}
115122

vsts/vss-extension.dev.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "qodana-dev",
44
"name": "Qodana (Dev)",
5-
"version": "2024.3.155",
5+
"version": "2024.3.156",
66
"publisher": "JetBrains",
77
"targets": [
88
{

0 commit comments

Comments
 (0)