Skip to content

Commit

Permalink
🐛 Show fresh coverage green if a threshold was met (QD-10150)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Iurko <[email protected]>
  • Loading branch information
2 people authored and tiulpin committed Feb 5, 2025
1 parent 0f22726 commit fbe40c5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
7 changes: 5 additions & 2 deletions scan/__tests__/data/some.sarif.json
Original file line number Diff line number Diff line change
Expand Up @@ -8261,13 +8261,16 @@
"qodanaFailureConditions": {
"testCoverageThresholds": {
"totalCoverage": 40,
"freshCoverage": 40
"freshCoverage": 30
}
},
"coverage": {
"totalCoverage": 45.0,
"totalLines": 124.0,
"totalCoveredLines": 56.0
"totalCoveredLines": 56.0,
"freshCoverage": 33.0,
"freshLines": 9.0,
"freshCoveredLines": 3.0
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion scan/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ function passedCoverageFixture(): string {
@@ Code coverage @@
+ 45% total lines covered
124 lines analyzed, 56 lines covered
+ 33% fresh lines covered
9 lines analyzed, 3 lines covered
# Calculated according to the filters of your coverage tool
\`\`\``
}
Expand All @@ -371,7 +373,7 @@ function failedCoverageFixture(): string {
@@ Code coverage @@
- 0% total lines covered
100 lines analyzed, 0 lines covered
! 0% fresh lines covered
- 0% fresh lines covered
100 lines analyzed, 0 lines covered
# Calculated according to the filters of your coverage tool
\`\`\``
Expand Down
20 changes: 12 additions & 8 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137094,24 +137094,28 @@ ${message}
\`\`\``;
}
__name(wrapToDiffBlock, "wrapToDiffBlock");
function makeConclusion(conclusion, failedByThreshold) {
if (failedByThreshold) {
return `- ${conclusion}`;
} else {
return `+ ${conclusion}`;
}
}
__name(makeConclusion, "makeConclusion");
function getCoverageStats(c) {
if (c.totalLines === 0 && c.totalCoveredLines === 0) {
return "";
}
let stats = "";
if (c.totalLines !== 0) {
let conclusion = `${c.totalCoverage}% total lines covered`;
if (c.totalCoverage < c.totalCoverageThreshold) {
conclusion = `- ${conclusion}`;
} else {
conclusion = `+ ${conclusion}`;
}
stats += `${conclusion}
const conclusion = `${c.totalCoverage}% total lines covered`;
stats += `${makeConclusion(conclusion, c.totalCoverage < c.totalCoverageThreshold)}
${c.totalLines} lines analyzed, ${c.totalCoveredLines} lines covered`;
}
if (c.freshLines !== 0) {
const conclusion = `${c.freshCoverage}% fresh lines covered`;
stats += `
! ${c.freshCoverage}% fresh lines covered
${makeConclusion(conclusion, c.freshCoverage < c.freshCoverageThreshold)}
${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
}
return wrapToDiffBlock([
Expand Down
23 changes: 15 additions & 8 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,33 @@ ${message}
\`\`\``
}

function makeConclusion(
conclusion: string,
failedByThreshold: boolean
): string {
if (failedByThreshold) {
return `- ${conclusion}`
} else {
return `+ ${conclusion}`
}
}

export function getCoverageStats(c: Coverage): string {
if (c.totalLines === 0 && c.totalCoveredLines === 0) {
return ''
}

let stats = ''
if (c.totalLines !== 0) {
let conclusion = `${c.totalCoverage}% total lines covered`
if (c.totalCoverage < c.totalCoverageThreshold) {
conclusion = `- ${conclusion}`
} else {
conclusion = `+ ${conclusion}`
}
stats += `${conclusion}
const conclusion = `${c.totalCoverage}% total lines covered`
stats += `${makeConclusion(conclusion, c.totalCoverage < c.totalCoverageThreshold)}
${c.totalLines} lines analyzed, ${c.totalCoveredLines} lines covered`
}

if (c.freshLines !== 0) {
const conclusion = `${c.freshCoverage}% fresh lines covered`
stats += `
! ${c.freshCoverage}% fresh lines covered
${makeConclusion(conclusion, c.freshCoverage < c.freshCoverageThreshold)}
${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`
}

Expand Down
2 changes: 1 addition & 1 deletion vsts/vss-extension.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "qodana-dev",
"name": "Qodana (Dev)",
"version": "2024.3.155",
"version": "2024.3.156",
"publisher": "JetBrains",
"targets": [
{
Expand Down

0 comments on commit fbe40c5

Please sign in to comment.