diff --git a/common/qodana.ts b/common/qodana.ts index d0d6db1..f15099e 100644 --- a/common/qodana.ts +++ b/common/qodana.ts @@ -13,7 +13,7 @@ export const QODANA_REPORT_URL_NAME = 'qodana.cloud' export const QODANA_OPEN_IN_IDE_NAME = 'open-in-ide.json' export const QODANA_LICENSES_MD = 'thirdPartySoftwareList.md' -export const QODANA_LICENSES_JSON = 'thirdPartySoftwareList.json' +export const QODANA_LICENSES_JSON = 'third-party-libraries.json' export const EXECUTABLE = 'qodana' export const VERSION = version diff --git a/scan/__tests__/main.test.ts b/scan/__tests__/main.test.ts index fb18f98..348d0bd 100644 --- a/scan/__tests__/main.test.ts +++ b/scan/__tests__/main.test.ts @@ -45,6 +45,7 @@ test('test typical summary output', () => { 'Qodana for JS', annotationsDefaultFixture().reverse(), // reversed for testing the correct sorting in output '', + 0, 'There is no licenses information available', 'https://example.com/report', true @@ -57,6 +58,7 @@ test('test empty summary output', () => { 'Qodana for JS', outputEmptyFixture(), '', + 0, '', '', false @@ -264,7 +266,7 @@ export function markdownSummaryFixture(): string { 💡 Qodana analysis was run in the pull request mode: only the changed files were checked ☁️ [View the detailed Qodana report](https://example.com/report)
-Dependencies licenses +Detected 0 dependencies There is no licenses information available
diff --git a/scan/dist/index.js b/scan/dist/index.js index cc2799d..2179ce0 100644 --- a/scan/dist/index.js +++ b/scan/dist/index.js @@ -24462,7 +24462,7 @@ var init_qodana = __esm({ QODANA_REPORT_URL_NAME = "qodana.cloud"; QODANA_OPEN_IN_IDE_NAME = "open-in-ide.json"; QODANA_LICENSES_MD = "thirdPartySoftwareList.md"; - QODANA_LICENSES_JSON = "thirdPartySoftwareList.json"; + QODANA_LICENSES_JSON = "third-party-libraries.json"; EXECUTABLE = "qodana"; VERSION = version2; COVERAGE_THRESHOLD = 50; @@ -125870,7 +125870,7 @@ var require_output = __commonJS({ }); }; Object.defineProperty(exports2, "__esModule", { value: true }); - exports2.prFixesBody = exports2.getProblemPlural = exports2.getSummary = exports2.publishOutput = exports2.getReportURL = exports2.getCoverageStats = exports2.COMMIT_EMAIL = exports2.COMMIT_USER = void 0; + exports2.prFixesBody = exports2.getDepencencyPlural = exports2.getProblemPlural = exports2.getSummary = exports2.publishOutput = exports2.getReportURL = exports2.getCoverageStats = exports2.COMMIT_EMAIL = exports2.COMMIT_USER = void 0; var core2 = __importStar3(require_core()); var fs2 = __importStar3(require("fs")); var qodana_12 = (init_qodana(), __toCommonJS(qodana_exports)); @@ -125965,16 +125965,18 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`; const reportUrl = getReportURL(resultsDir); const coverageInfo = getCoverageStats((0, qodana_12.getCoverageFromSarif)(`${resultsDir}/${qodana_12.QODANA_SHORT_SARIF_NAME}`), qodana_12.COVERAGE_THRESHOLD); let licensesInfo = ""; + let packages = 0; const licensesJson = `${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_JSON}`; if (fs2.existsSync(licensesJson)) { const licenses = JSON.parse(fs2.readFileSync(licensesJson, { encoding: "utf8" })); if (licenses.length > 0) { + packages = licenses.length; licensesInfo = fs2.readFileSync(`${resultsDir}/projectStructure/${qodana_12.QODANA_LICENSES_MD}`, { encoding: "utf8" }); } } const annotations = (_a = problems.annotations) !== null && _a !== void 0 ? _a : []; const toolName = (_b = problems.title.split("found by ")[1]) !== null && _b !== void 0 ? _b : QODANA_CHECK_NAME; - problems.summary = getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, isPrMode); + problems.summary = getSummary(toolName, annotations, coverageInfo, packages, licensesInfo, reportUrl, isPrMode); yield Promise.all([ (0, utils_12.putReaction)(utils_12.ANALYSIS_FINISHED_REACTION, utils_12.ANALYSIS_STARTED_REACTION), (0, utils_12.postResultsToPRComments)(toolName, problems.summary, postComment), @@ -126011,11 +126013,11 @@ ${body} return Array.from(problems.entries()).sort((a, b) => b[1] - a[1]).map(([title, count]) => `| \`${title}\` | ${level} | ${count} |`).join("\n"); } __name(getRowsByLevel, "getRowsByLevel"); - function getSummary(toolName, annotations, coverageInfo, licensesInfo, reportUrl, prMode) { + function getSummary(toolName, annotations, coverageInfo, packages, licensesInfo, reportUrl, prMode) { const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC); let licensesBlock = ""; if (licensesInfo !== "") { - licensesBlock = wrapToToggleBlock("Dependencies licenses", licensesInfo); + licensesBlock = wrapToToggleBlock(`Detected ${packages} ${getDepencencyPlural(packages)}`, licensesInfo); } let prModeBlock = ""; if (prMode) { @@ -126066,6 +126068,11 @@ ${body} } __name(getProblemPlural, "getProblemPlural"); exports2.getProblemPlural = getProblemPlural; + function getDepencencyPlural(count) { + return `dependenc${count !== 1 ? "ies" : "y"}`; + } + __name(getDepencencyPlural, "getDepencencyPlural"); + exports2.getDepencencyPlural = getDepencencyPlural; function prFixesBody(jobUrl) { return ` \u{1F590} Hey there! diff --git a/scan/src/output.ts b/scan/src/output.ts index 9d883f3..a657c4a 100644 --- a/scan/src/output.ts +++ b/scan/src/output.ts @@ -138,12 +138,14 @@ export async function publishOutput( COVERAGE_THRESHOLD ) let licensesInfo = '' + let packages = 0 const licensesJson = `${resultsDir}/projectStructure/${QODANA_LICENSES_JSON}` if (fs.existsSync(licensesJson)) { const licenses = JSON.parse( fs.readFileSync(licensesJson, {encoding: 'utf8'}) ) if (licenses.length > 0) { + packages = licenses.length licensesInfo = fs.readFileSync( `${resultsDir}/projectStructure/${QODANA_LICENSES_MD}`, {encoding: 'utf8'} @@ -157,6 +159,7 @@ export async function publishOutput( toolName, annotations, coverageInfo, + packages, licensesInfo, reportUrl, isPrMode @@ -222,6 +225,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string { * @param toolName The name of the tool to generate the summary from. * @param annotations The annotations to generate the summary from. * @param coverageInfo The coverage is a Markdown text to generate the summary from. + * @param packages The number of dependencies in the analyzed project. * @param licensesInfo The licenses a Markdown text to generate the summary from. * @param reportUrl The URL to the Qodana report. * @param prMode Whether the analysis was run in the pull request mode. @@ -230,6 +234,7 @@ export function getSummary( toolName: string, annotations: Annotation[], coverageInfo: string, + packages: number, licensesInfo: string, reportUrl: string, prMode: boolean @@ -237,7 +242,10 @@ export function getSummary( const contactBlock = wrapToToggleBlock('Contact Qodana team', SUMMARY_MISC) let licensesBlock = '' if (licensesInfo !== '') { - licensesBlock = wrapToToggleBlock('Dependencies licenses', licensesInfo) + licensesBlock = wrapToToggleBlock( + `Detected ${packages} ${getDepencencyPlural(packages)}`, + licensesInfo + ) } let prModeBlock = '' if (prMode) { @@ -308,6 +316,15 @@ export function getProblemPlural(count: number): string { return `new problem${count !== 1 ? 's' : ''}` } +/** + * Generates a plural form of the word "dependency" depending on the given count. + * @param count A number representing the count of dependencies + * @returns A formatted string with the correct plural form of "dependency" + */ +export function getDepencencyPlural(count: number): string { + return `dependenc${count !== 1 ? 'ies' : 'y'}` +} + /* * The pull request with quick-fixes body template. */ diff --git a/vsts/QodanaScan/index.js b/vsts/QodanaScan/index.js index 63ecc4a..cd223cc 100644 --- a/vsts/QodanaScan/index.js +++ b/vsts/QodanaScan/index.js @@ -223,7 +223,7 @@ var init_qodana = __esm({ QODANA_REPORT_URL_NAME = "qodana.cloud"; QODANA_OPEN_IN_IDE_NAME = "open-in-ide.json"; QODANA_LICENSES_MD = "thirdPartySoftwareList.md"; - QODANA_LICENSES_JSON = "thirdPartySoftwareList.json"; + QODANA_LICENSES_JSON = "third-party-libraries.json"; EXECUTABLE = "qodana"; VERSION = version; COVERAGE_THRESHOLD = 50;