Skip to content

Commit cf1e8da

Browse files
authored
🐛 Fix revision ids for analysing pull requests
2 parents f8f97ea + a389a9a commit cf1e8da

File tree

2 files changed

+65
-10
lines changed

2 files changed

+65
-10
lines changed

scan/dist/index.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135150,29 +135150,50 @@ var require_utils10 = __commonJS({
135150135150
}
135151135151
__name(getInputs, "getInputs");
135152135152
function getPrSha() {
135153-
if (process.env.QODANA_PR_SHA) {
135154-
return process.env.QODANA_PR_SHA;
135153+
return __awaiter3(this, void 0, void 0, function* () {
135154+
if (process.env.QODANA_PR_SHA) {
135155+
return process.env.QODANA_PR_SHA;
135156+
}
135157+
if (github2.context.payload.pull_request !== void 0) {
135158+
const output = yield gitOutput([
135159+
"merge-base",
135160+
github2.context.payload.pull_request.base.sha,
135161+
github2.context.payload.pull_request.head.sha
135162+
]);
135163+
if (output.exitCode === 0) {
135164+
return output.stdout.trim();
135165+
} else {
135166+
return github2.context.payload.pull_request.base.sha;
135167+
}
135168+
}
135169+
return "";
135170+
});
135171+
}
135172+
__name(getPrSha, "getPrSha");
135173+
function getHeadSha() {
135174+
if (process.env.QODANA_REVISION) {
135175+
return process.env.QODANA_REVISION;
135155135176
}
135156135177
if (github2.context.payload.pull_request !== void 0) {
135157-
return github2.context.payload.pull_request.base.sha;
135178+
return github2.context.payload.pull_request.head.sha;
135158135179
}
135159-
return "";
135180+
return github2.context.sha;
135160135181
}
135161-
__name(getPrSha, "getPrSha");
135182+
__name(getHeadSha, "getHeadSha");
135162135183
function qodana(inputs_1) {
135163135184
return __awaiter3(this, arguments, void 0, function* (inputs, args = []) {
135164135185
if (args.length === 0) {
135165135186
args = (0, qodana_12.getQodanaScanArgs)(inputs.args, inputs.resultsDir, inputs.cacheDir);
135166135187
if (inputs.prMode) {
135167-
const sha = getPrSha();
135188+
const sha = yield getPrSha();
135168135189
if (sha !== "") {
135169135190
args.push("--commit", sha);
135170135191
}
135171135192
}
135172135193
}
135173135194
return (yield exec.getExecOutput(qodana_12.EXECUTABLE, args, {
135174135195
ignoreReturnCode: true,
135175-
env: Object.assign(Object.assign({}, process.env), { NONINTERACTIVE: "1" })
135196+
env: Object.assign(Object.assign({}, process.env), { QODANA_REVISION: getHeadSha(), NONINTERACTIVE: "1" })
135176135197
})).exitCode;
135177135198
});
135178135199
}
@@ -135469,6 +135490,12 @@ ${comment_tag_pattern}`;
135469135490
});
135470135491
}
135471135492
__name(git, "git");
135493+
function gitOutput(args_1) {
135494+
return __awaiter3(this, arguments, void 0, function* (args, options = {}) {
135495+
return yield exec.getExecOutput("git", args, options);
135496+
});
135497+
}
135498+
__name(gitOutput, "gitOutput");
135472135499
function createPr(title, repo, base, head) {
135473135500
return __awaiter3(this, void 0, void 0, function* () {
135474135501
const prBodyFile = path_1.default.join(os.tmpdir(), "pr-body.txt");

scan/src/utils.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import path from 'path'
4646
import * as fs from 'fs'
4747
import * as os from 'os'
4848
import {COMMIT_EMAIL, COMMIT_USER, prFixesBody} from './output'
49+
import {ExecOutput} from '@actions/exec'
4950

5051
export const ANALYSIS_FINISHED_REACTION = '+1'
5152
export const ANALYSIS_STARTED_REACTION = 'eyes'
@@ -90,16 +91,35 @@ export function getInputs(): Inputs {
9091
}
9192
}
9293

93-
function getPrSha(): string {
94+
async function getPrSha(): Promise<string> {
9495
if (process.env.QODANA_PR_SHA) {
9596
return process.env.QODANA_PR_SHA
9697
}
9798
if (github.context.payload.pull_request !== undefined) {
98-
return github.context.payload.pull_request.base.sha
99+
const output = await gitOutput([
100+
'merge-base',
101+
github.context.payload.pull_request.base.sha,
102+
github.context.payload.pull_request.head.sha
103+
])
104+
if (output.exitCode === 0) {
105+
return output.stdout.trim()
106+
} else {
107+
return github.context.payload.pull_request.base.sha
108+
}
99109
}
100110
return ''
101111
}
102112

113+
function getHeadSha(): string {
114+
if (process.env.QODANA_REVISION) {
115+
return process.env.QODANA_REVISION
116+
}
117+
if (github.context.payload.pull_request !== undefined) {
118+
return github.context.payload.pull_request.head.sha
119+
}
120+
return github.context.sha
121+
}
122+
103123
/**
104124
* Runs the qodana command with the given arguments.
105125
* @param inputs the action inputs.
@@ -113,7 +133,7 @@ export async function qodana(
113133
if (args.length === 0) {
114134
args = getQodanaScanArgs(inputs.args, inputs.resultsDir, inputs.cacheDir)
115135
if (inputs.prMode) {
116-
const sha = getPrSha()
136+
const sha = await getPrSha()
117137
if (sha !== '') {
118138
args.push('--commit', sha)
119139
}
@@ -124,6 +144,7 @@ export async function qodana(
124144
ignoreReturnCode: true,
125145
env: {
126146
...process.env,
147+
QODANA_REVISION: getHeadSha(),
127148
NONINTERACTIVE: '1'
128149
}
129150
})
@@ -594,6 +615,13 @@ async function git(
594615
return (await exec.getExecOutput('git', args, options)).exitCode
595616
}
596617

618+
async function gitOutput(
619+
args: string[],
620+
options: exec.ExecOptions = {}
621+
): Promise<ExecOutput> {
622+
return await exec.getExecOutput('git', args, options)
623+
}
624+
597625
async function createPr(
598626
title: string,
599627
repo: string,

0 commit comments

Comments
 (0)