From e8297ea25db82a143325b1392ffc123859b51b97 Mon Sep 17 00:00:00 2001 From: Dima Golovinov Date: Thu, 10 Oct 2024 15:28:00 +0200 Subject: [PATCH 1/2] :bug: Fix revision ids for analysing pull requests --- scan/src/utils.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/scan/src/utils.ts b/scan/src/utils.ts index ed58b909..0315cb98 100644 --- a/scan/src/utils.ts +++ b/scan/src/utils.ts @@ -46,6 +46,7 @@ import path from 'path' import * as fs from 'fs' import * as os from 'os' import {COMMIT_EMAIL, COMMIT_USER, prFixesBody} from './output' +import {ExecOutput} from '@actions/exec' export const ANALYSIS_FINISHED_REACTION = '+1' export const ANALYSIS_STARTED_REACTION = 'eyes' @@ -90,16 +91,35 @@ export function getInputs(): Inputs { } } -function getPrSha(): string { +async function getPrSha(): Promise { if (process.env.QODANA_PR_SHA) { return process.env.QODANA_PR_SHA } if (github.context.payload.pull_request !== undefined) { - return github.context.payload.pull_request.base.sha + const output = await gitOutput([ + 'merge-base', + github.context.payload.pull_request.base.sha, + github.context.payload.pull_request.head.sha + ]) + if (output.exitCode === 0) { + return output.stdout.trim() + } else { + return github.context.payload.pull_request.base.sha + } } return '' } +function getHeadSha(): string { + if (process.env.QODANA_REVISION) { + return process.env.QODANA_REVISION + } + if (github.context.payload.pull_request !== undefined) { + return github.context.payload.pull_request.head.sha + } + return github.context.sha +} + /** * Runs the qodana command with the given arguments. * @param inputs the action inputs. @@ -113,7 +133,7 @@ export async function qodana( if (args.length === 0) { args = getQodanaScanArgs(inputs.args, inputs.resultsDir, inputs.cacheDir) if (inputs.prMode) { - const sha = getPrSha() + const sha = await getPrSha() if (sha !== '') { args.push('--commit', sha) } @@ -124,6 +144,7 @@ export async function qodana( ignoreReturnCode: true, env: { ...process.env, + QODANA_REVISION: getHeadSha(), NONINTERACTIVE: '1' } }) @@ -594,6 +615,13 @@ async function git( return (await exec.getExecOutput('git', args, options)).exitCode } +async function gitOutput( + args: string[], + options: exec.ExecOptions = {} +): Promise { + return await exec.getExecOutput('git', args, options) +} + async function createPr( title: string, repo: string, From a389a9a8cb46f9c6f2d01c2d5f653d85e584db45 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 10 Oct 2024 13:28:55 +0000 Subject: [PATCH 2/2] :bricks: Update `scan/dist/index.js` --- scan/dist/index.js | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/scan/dist/index.js b/scan/dist/index.js index da42bcf7..40372a72 100644 --- a/scan/dist/index.js +++ b/scan/dist/index.js @@ -135150,21 +135150,42 @@ var require_utils10 = __commonJS({ } __name(getInputs, "getInputs"); function getPrSha() { - if (process.env.QODANA_PR_SHA) { - return process.env.QODANA_PR_SHA; + return __awaiter3(this, void 0, void 0, function* () { + if (process.env.QODANA_PR_SHA) { + return process.env.QODANA_PR_SHA; + } + if (github2.context.payload.pull_request !== void 0) { + const output = yield gitOutput([ + "merge-base", + github2.context.payload.pull_request.base.sha, + github2.context.payload.pull_request.head.sha + ]); + if (output.exitCode === 0) { + return output.stdout.trim(); + } else { + return github2.context.payload.pull_request.base.sha; + } + } + return ""; + }); + } + __name(getPrSha, "getPrSha"); + function getHeadSha() { + if (process.env.QODANA_REVISION) { + return process.env.QODANA_REVISION; } if (github2.context.payload.pull_request !== void 0) { - return github2.context.payload.pull_request.base.sha; + return github2.context.payload.pull_request.head.sha; } - return ""; + return github2.context.sha; } - __name(getPrSha, "getPrSha"); + __name(getHeadSha, "getHeadSha"); function qodana(inputs_1) { return __awaiter3(this, arguments, void 0, function* (inputs, args = []) { if (args.length === 0) { args = (0, qodana_12.getQodanaScanArgs)(inputs.args, inputs.resultsDir, inputs.cacheDir); if (inputs.prMode) { - const sha = getPrSha(); + const sha = yield getPrSha(); if (sha !== "") { args.push("--commit", sha); } @@ -135172,7 +135193,7 @@ var require_utils10 = __commonJS({ } return (yield exec.getExecOutput(qodana_12.EXECUTABLE, args, { ignoreReturnCode: true, - env: Object.assign(Object.assign({}, process.env), { NONINTERACTIVE: "1" }) + env: Object.assign(Object.assign({}, process.env), { QODANA_REVISION: getHeadSha(), NONINTERACTIVE: "1" }) })).exitCode; }); } @@ -135469,6 +135490,12 @@ ${comment_tag_pattern}`; }); } __name(git, "git"); + function gitOutput(args_1) { + return __awaiter3(this, arguments, void 0, function* (args, options = {}) { + return yield exec.getExecOutput("git", args, options); + }); + } + __name(gitOutput, "gitOutput"); function createPr(title, repo, base, head) { return __awaiter3(this, void 0, void 0, function* () { const prBodyFile = path_1.default.join(os.tmpdir(), "pr-body.txt");