From d210d8d92744e0aac28262ffdd210433d133495e Mon Sep 17 00:00:00 2001 From: tiulpin Date: Tue, 2 Jul 2024 20:12:48 +0200 Subject: [PATCH] :zap: Display analyzed subdirectory if there was any (QD-8271) --- scan/__tests__/main.test.ts | 3 +++ scan/dist/index.js | 12 ++++++------ scan/src/main.ts | 4 +++- scan/src/output.ts | 9 +++++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/scan/__tests__/main.test.ts b/scan/__tests__/main.test.ts index 27f49b1e..6f4e0c52 100644 --- a/scan/__tests__/main.test.ts +++ b/scan/__tests__/main.test.ts @@ -74,6 +74,7 @@ test('test sarif with no problems to output annotations', () => { test('test typical summary output', () => { const result = getSummary( 'Qodana for JS', + 'frontend', annotationsDefaultFixture().reverse(), // reversed for testing the correct sorting in output '', 0, @@ -87,6 +88,7 @@ test('test typical summary output', () => { test('test empty summary output', () => { const result = getSummary( 'Qodana for JS', + '', outputEmptyFixture(), '', 0, @@ -283,6 +285,7 @@ export function defaultDockerRunCommandFixture(): string[] { export function markdownSummaryFixture(): string { return `# [Qodana](https://example.com/report) for JS +\`frontend/\` **4 new problems** were found diff --git a/scan/dist/index.js b/scan/dist/index.js index f30a7119..d4ac2490 100644 --- a/scan/dist/index.js +++ b/scan/dist/index.js @@ -134557,7 +134557,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`; } __name(getReportURL, "getReportURL"); exports2.getReportURL = getReportURL; - function publishOutput(failedByThreshold, resultsDir, useAnnotations, postComment, isPrMode, execute) { + function publishOutput(failedByThreshold, projectDir, resultsDir, useAnnotations, postComment, isPrMode, execute) { return __awaiter3(this, void 0, void 0, function* () { var _a, _b; if (!execute) { @@ -134579,7 +134579,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`; } 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, packages, licensesInfo, reportUrl, isPrMode); + problems.summary = getSummary(toolName, projectDir, 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), @@ -134616,7 +134616,7 @@ ${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, packages, licensesInfo, reportUrl, prMode) { + function getSummary(toolName, projectDir, annotations, coverageInfo, packages, licensesInfo, reportUrl, prMode) { const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC); let licensesBlock = ""; if (licensesInfo !== "") { @@ -134633,7 +134633,7 @@ ${body} if (annotations.length === 0) { return [ `# ${toolName}`, - "", + projectDir === "" ? "" : ["`", projectDir, "/`\n"].join(""), "**It seems all right \u{1F44C}**", "", "No new problems were found according to the checks applied", @@ -134646,7 +134646,7 @@ ${body} } return [ `# ${toolName}`, - "", + projectDir === "" ? "" : ["`", projectDir, "/`\n"].join(""), `**${annotations.length} ${getProblemPlural(annotations.length)}** were found`, "", SUMMARY_TABLE_HEADER, @@ -135469,7 +135469,7 @@ function main() { (0, utils_1.pushQuickFixes)(inputs.pushFixes, inputs.commitMessage), (0, utils_1.uploadArtifacts)(inputs.resultsDir, inputs.artifactName, inputs.uploadResult), (0, utils_1.uploadCaches)(inputs.cacheDir, inputs.primaryCacheKey, reservedCacheKey, canUploadCache), - (0, output_1.publishOutput)(exitCode === qodana_1.QodanaExitCode.FailThreshold, inputs.resultsDir, inputs.useAnnotations, inputs.postComment, inputs.prMode, (0, qodana_1.isExecutionSuccessful)(exitCode)) + (0, output_1.publishOutput)(exitCode === qodana_1.QodanaExitCode.FailThreshold, (0, qodana_1.extractArg)("-i", "--project-dir", inputs.args), inputs.resultsDir, inputs.useAnnotations, inputs.postComment, inputs.prMode, (0, qodana_1.isExecutionSuccessful)(exitCode)) ]); if (!(0, qodana_1.isExecutionSuccessful)(exitCode)) { setFailed(`qodana scan failed with exit code ${exitCode}`); diff --git a/scan/src/main.ts b/scan/src/main.ts index f376b3cf..73da9c51 100644 --- a/scan/src/main.ts +++ b/scan/src/main.ts @@ -21,7 +21,8 @@ import { FAIL_THRESHOLD_OUTPUT, QodanaExitCode, isExecutionSuccessful, - NONE + NONE, + extractArg } from '../../common/qodana' import { ANALYSIS_FINISHED_REACTION, @@ -106,6 +107,7 @@ async function main(): Promise { ), publishOutput( exitCode === QodanaExitCode.FailThreshold, + extractArg('-i', '--project-dir', inputs.args), inputs.resultsDir, inputs.useAnnotations, inputs.postComment, diff --git a/scan/src/output.ts b/scan/src/output.ts index 8df031d4..a0b59506 100644 --- a/scan/src/output.ts +++ b/scan/src/output.ts @@ -129,6 +129,7 @@ export function getReportURL(resultsDir: string): string { /** * Publish Qodana results to GitHub: comment, job summary, annotations. * @param failedByThreshold flag if the Qodana failThreshold was reached. + * @param projectDir The path to the project. * @param resultsDir The path to the results. * @param postComment whether to post a PR comment or not. * @param isPrMode @@ -137,6 +138,7 @@ export function getReportURL(resultsDir: string): string { */ export async function publishOutput( failedByThreshold: boolean, + projectDir: string, resultsDir: string, useAnnotations: boolean, postComment: boolean, @@ -173,6 +175,7 @@ export async function publishOutput( const toolName = problems.title.split('found by ')[1] ?? QODANA_CHECK_NAME problems.summary = getSummary( toolName, + projectDir, annotations, coverageInfo, packages, @@ -239,6 +242,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string { /** * Generates action summary string of annotations. * @param toolName The name of the tool to generate the summary from. + * @param projectDir The path to the project. * @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. @@ -248,6 +252,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string { */ export function getSummary( toolName: string, + projectDir: string, annotations: Annotation[], coverageInfo: string, packages: number, @@ -277,7 +282,7 @@ export function getSummary( if (annotations.length === 0) { return [ `# ${toolName}`, - '', + projectDir === '' ? '' : ['`', projectDir, '/`\n'].join(''), '**It seems all right 👌**', '', 'No new problems were found according to the checks applied', @@ -291,7 +296,7 @@ export function getSummary( return [ `# ${toolName}`, - '', + projectDir === '' ? '' : ['`', projectDir, '/`\n'].join(''), `**${annotations.length} ${getProblemPlural( annotations.length )}** were found`,