Skip to content

Commit

Permalink
🐛 Fix revision ids for analysing pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
hybloid authored Oct 10, 2024
2 parents f8f97ea + a389a9a commit cf1e8da
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
41 changes: 34 additions & 7 deletions scan/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135150,29 +135150,50 @@ 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);
}
}
}
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;
});
}
Expand Down Expand Up @@ -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");
Expand Down
34 changes: 31 additions & 3 deletions scan/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -90,16 +91,35 @@ export function getInputs(): Inputs {
}
}

function getPrSha(): string {
async function getPrSha(): Promise<string> {
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.
Expand All @@ -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)
}
Expand All @@ -124,6 +144,7 @@ export async function qodana(
ignoreReturnCode: true,
env: {
...process.env,
QODANA_REVISION: getHeadSha(),
NONINTERACTIVE: '1'
}
})
Expand Down Expand Up @@ -594,6 +615,13 @@ async function git(
return (await exec.getExecOutput('git', args, options)).exitCode
}

async function gitOutput(
args: string[],
options: exec.ExecOptions = {}
): Promise<ExecOutput> {
return await exec.getExecOutput('git', args, options)
}

async function createPr(
title: string,
repo: string,
Expand Down

0 comments on commit cf1e8da

Please sign in to comment.