Skip to content

Commit

Permalink
Merge branch 'main' into iurko/fix-coverage-threshoulds-respect
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIurko authored Jan 31, 2025
2 parents 5b739d2 + e9c04b4 commit 4a05242
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
5 changes: 4 additions & 1 deletion scan/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test('test typical summary output', () => {
const result = getSummary(
'Qodana for JS',
'frontend',
'web',
annotationsDefaultFixture().reverse(), // reversed for testing the correct sorting in output
'',
0,
Expand All @@ -95,6 +96,7 @@ test('test empty summary output', () => {
const result = getSummary(
'Qodana for JS',
'',
'',
outputEmptyFixture(),
'',
0,
Expand Down Expand Up @@ -289,7 +291,8 @@ export function defaultDockerRunCommandFixture(): string[] {

export function markdownSummaryFixture(): string {
return `# [Qodana](https://example.com/report) for JS
\`frontend/\`
Analyzed project: \`frontend/\`
Analyzed directory: \`web/\`
**4 new problems** were found
Expand Down
19 changes: 10 additions & 9 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137143,7 +137143,7 @@ ${c.freshLines} lines analyzed, ${c.freshCoveredLines} lines covered`;
return "";
}
__name(getReportURL, "getReportURL");
function publishOutput(failedByThreshold, projectDir, resultsDir, useAnnotations, postComment, isPrMode, execute) {
function publishOutput(failedByThreshold, projectDir, sourceDir, resultsDir, useAnnotations, postComment, isPrMode, execute) {
return __awaiter3(this, void 0, void 0, function* () {
var _a, _b;
if (!execute) {
Expand All @@ -137165,10 +137165,10 @@ ${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, projectDir, annotations, coverageInfo, packages, licensesInfo, reportUrl, isPrMode);
problems.summary = getSummary(toolName, projectDir, sourceDir, 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),
(0, utils_12.postResultsToPRComments)(toolName, problems.summary, sourceDir, postComment),
core2.summary.addRaw(problems.summary).write(),
(0, annotations_1.publishAnnotations)(toolName, problems, failedByThreshold, useAnnotations)
]);
Expand Down Expand Up @@ -137201,7 +137201,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, projectDir, annotations, coverageInfo, packages, licensesInfo, reportUrl, prMode) {
function getSummary(toolName, projectDir, sourceDir, annotations, coverageInfo, packages, licensesInfo, reportUrl, prMode) {
const contactBlock = wrapToToggleBlock("Contact Qodana team", SUMMARY_MISC);
let licensesBlock = "";
if (licensesInfo !== "" && licensesInfo.length < DEPENDENCY_CHARS_LIMIT) {
Expand All @@ -137215,10 +137215,11 @@ ${body}
const firstToolName = toolName.split(" ")[0];
toolName = toolName.replace(firstToolName, `[${firstToolName}](${reportUrl})`);
}
const analysisScope = (projectDir === "" ? "" : ["Analyzed project: `", projectDir, "/`\n"].join("")).concat(sourceDir === "" ? "" : ["Analyzed directory: `", sourceDir, "/`\n"].join(""));
if (annotations.length === 0) {
return [
`# ${toolName}`,
projectDir === "" ? "" : ["`", projectDir, "/`\n"].join(""),
analysisScope,
"**It seems all right \u{1F44C}**",
"",
"No new problems were found according to the checks applied",
Expand All @@ -137231,7 +137232,7 @@ ${body}
}
return [
`# ${toolName}`,
projectDir === "" ? "" : ["`", projectDir, "/`\n"].join(""),
analysisScope,
`**${annotations.length} ${getProblemPlural(annotations.length)}** were found`,
"",
SUMMARY_TABLE_HEADER,
Expand Down Expand Up @@ -137843,13 +137844,13 @@ var require_utils10 = __commonJS({
return `${serverUrl}/${repo.owner}/${repo.repo}/actions/runs/${runId}`;
}
__name(getWorkflowRunUrl, "getWorkflowRunUrl");
function postResultsToPRComments(toolName, content, postComment) {
function postResultsToPRComments(toolName, content, sourceDir, postComment) {
return __awaiter3(this, void 0, void 0, function* () {
const pr = github.context.payload.pull_request;
if (!postComment || !pr) {
return;
}
const comment_tag_pattern = `<!-- JetBrains/qodana-action@v${qodana_12.VERSION} : ${toolName} -->`;
const comment_tag_pattern = `<!-- JetBrains/qodana-action@v${qodana_12.VERSION} : ${toolName}, ${sourceDir} -->`;
const body = `${content}
${comment_tag_pattern}`;
const client = github.getOctokit(getInputs().githubToken);
Expand Down Expand Up @@ -138117,7 +138118,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, (0, qodana_1.extractArg)("-i", "--project-dir", inputs.args), 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), (0, qodana_1.extractArg)("-d", "--source-directory", 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
1 change: 1 addition & 0 deletions scan/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async function main(): Promise<void> {
publishOutput(
exitCode === QodanaExitCode.FailThreshold,
extractArg('-i', '--project-dir', inputs.args),
extractArg('-d', '--source-directory', inputs.args),
inputs.resultsDir,
inputs.useAnnotations,
inputs.postComment,
Expand Down
25 changes: 22 additions & 3 deletions scan/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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 sourceDir The path to the analyzed directory inside the project.
* @param resultsDir The path to the results.
* @param postComment whether to post a PR comment or not.
* @param isPrMode
Expand All @@ -159,6 +160,7 @@ export function getReportURL(resultsDir: string): string {
export async function publishOutput(
failedByThreshold: boolean,
projectDir: string,
sourceDir: string,
resultsDir: string,
useAnnotations: boolean,
postComment: boolean,
Expand Down Expand Up @@ -196,6 +198,7 @@ export async function publishOutput(
problems.summary = getSummary(
toolName,
projectDir,
sourceDir,
annotations,
coverageInfo,
packages,
Expand All @@ -206,7 +209,12 @@ export async function publishOutput(

await Promise.all([
putReaction(ANALYSIS_FINISHED_REACTION, ANALYSIS_STARTED_REACTION),
postResultsToPRComments(toolName, problems.summary, postComment),
postResultsToPRComments(
toolName,
problems.summary,
sourceDir,
postComment
),
core.summary.addRaw(problems.summary).write(),
publishAnnotations(toolName, problems, failedByThreshold, useAnnotations)
])
Expand Down Expand Up @@ -263,6 +271,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 sourceDir The path to analyzed directory inside 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 @@ -273,6 +282,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string {
export function getSummary(
toolName: string,
projectDir: string,
sourceDir: string,
annotations: Annotation[],
coverageInfo: string,
packages: number,
Expand All @@ -299,10 +309,19 @@ export function getSummary(
`[${firstToolName}](${reportUrl})`
)
}
const analysisScope = (
projectDir === ''
? ''
: ['Analyzed project: `', projectDir, '/`\n'].join('')
).concat(
sourceDir === ''
? ''
: ['Analyzed directory: `', sourceDir, '/`\n'].join('')
)
if (annotations.length === 0) {
return [
`# ${toolName}`,
projectDir === '' ? '' : ['`', projectDir, '/`\n'].join(''),
analysisScope,
'**It seems all right 👌**',
'',
'No new problems were found according to the checks applied',
Expand All @@ -316,7 +335,7 @@ export function getSummary(

return [
`# ${toolName}`,
projectDir === '' ? '' : ['`', projectDir, '/`\n'].join(''),
analysisScope,
`**${annotations.length} ${getProblemPlural(
annotations.length
)}** were found`,
Expand Down
5 changes: 4 additions & 1 deletion scan/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,13 @@ export function getWorkflowRunUrl(): string {
* Post a new comment to the pull request.
* @param toolName The name of the tool to mention in comment.
* @param content The comment to post.
* @param sourceDir The analyzed directory inside project
* @param postComment Whether to post a comment or not.
*/
export async function postResultsToPRComments(
toolName: string,
content: string,
sourceDir: string,
postComment: boolean
): Promise<void> {
const pr = github.context.payload.pull_request as
Expand All @@ -405,7 +407,8 @@ export async function postResultsToPRComments(
if (!postComment || !pr) {
return
}
const comment_tag_pattern = `<!-- JetBrains/qodana-action@v${VERSION} : ${toolName} -->`
// source dir needed in case of monorepo with projects analyzed by the same tool
const comment_tag_pattern = `<!-- JetBrains/qodana-action@v${VERSION} : ${toolName}, ${sourceDir} -->`
const body = `${content}\n${comment_tag_pattern}`
const client = github.getOctokit(getInputs().githubToken)
const comment_id = await findCommentByTag(client, comment_tag_pattern)
Expand Down

0 comments on commit 4a05242

Please sign in to comment.