Skip to content

Commit

Permalink
⚡ Display analyzed subdirectory if there was any (QD-8271)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Jul 2, 2024
1 parent 7e0f596 commit d210d8d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions scan/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -87,6 +88,7 @@ test('test typical summary output', () => {
test('test empty summary output', () => {
const result = getSummary(
'Qodana for JS',
'',
outputEmptyFixture(),
'',
0,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand Down Expand Up @@ -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 !== "") {
Expand All @@ -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",
Expand All @@ -134646,7 +134646,7 @@ ${body}
}
return [
`# ${toolName}`,
"",
projectDir === "" ? "" : ["`", projectDir, "/`\n"].join(""),
`**${annotations.length} ${getProblemPlural(annotations.length)}** were found`,
"",
SUMMARY_TABLE_HEADER,
Expand Down Expand Up @@ -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}`);
Expand Down
4 changes: 3 additions & 1 deletion scan/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
FAIL_THRESHOLD_OUTPUT,
QodanaExitCode,
isExecutionSuccessful,
NONE
NONE,
extractArg
} from '../../common/qodana'
import {
ANALYSIS_FINISHED_REACTION,
Expand Down Expand Up @@ -106,6 +107,7 @@ async function main(): Promise<void> {
),
publishOutput(
exitCode === QodanaExitCode.FailThreshold,
extractArg('-i', '--project-dir', inputs.args),
inputs.resultsDir,
inputs.useAnnotations,
inputs.postComment,
Expand Down
9 changes: 7 additions & 2 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -137,6 +138,7 @@ export function getReportURL(resultsDir: string): string {
*/
export async function publishOutput(
failedByThreshold: boolean,
projectDir: string,
resultsDir: string,
useAnnotations: boolean,
postComment: boolean,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -248,6 +252,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string {
*/
export function getSummary(
toolName: string,
projectDir: string,
annotations: Annotation[],
coverageInfo: string,
packages: number,
Expand Down Expand Up @@ -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',
Expand All @@ -291,7 +296,7 @@ export function getSummary(

return [
`# ${toolName}`,
'',
projectDir === '' ? '' : ['`', projectDir, '/`\n'].join(''),
`**${annotations.length} ${getProblemPlural(
annotations.length
)}** were found`,
Expand Down

0 comments on commit d210d8d

Please sign in to comment.