@@ -46,6 +46,7 @@ import path from 'path'
46
46
import * as fs from 'fs'
47
47
import * as os from 'os'
48
48
import { COMMIT_EMAIL , COMMIT_USER , prFixesBody } from './output'
49
+ import { ExecOutput } from '@actions/exec'
49
50
50
51
export const ANALYSIS_FINISHED_REACTION = '+1'
51
52
export const ANALYSIS_STARTED_REACTION = 'eyes'
@@ -90,16 +91,35 @@ export function getInputs(): Inputs {
90
91
}
91
92
}
92
93
93
- function getPrSha ( ) : string {
94
+ async function getPrSha ( ) : Promise < string > {
94
95
if ( process . env . QODANA_PR_SHA ) {
95
96
return process . env . QODANA_PR_SHA
96
97
}
97
98
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
+ }
99
109
}
100
110
return ''
101
111
}
102
112
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
+
103
123
/**
104
124
* Runs the qodana command with the given arguments.
105
125
* @param inputs the action inputs.
@@ -113,7 +133,7 @@ export async function qodana(
113
133
if ( args . length === 0 ) {
114
134
args = getQodanaScanArgs ( inputs . args , inputs . resultsDir , inputs . cacheDir )
115
135
if ( inputs . prMode ) {
116
- const sha = getPrSha ( )
136
+ const sha = await getPrSha ( )
117
137
if ( sha !== '' ) {
118
138
args . push ( '--commit' , sha )
119
139
}
@@ -124,6 +144,7 @@ export async function qodana(
124
144
ignoreReturnCode : true ,
125
145
env : {
126
146
...process . env ,
147
+ QODANA_REVISION : getHeadSha ( ) ,
127
148
NONINTERACTIVE : '1'
128
149
}
129
150
} )
@@ -594,6 +615,13 @@ async function git(
594
615
return ( await exec . getExecOutput ( 'git' , args , options ) ) . exitCode
595
616
}
596
617
618
+ async function gitOutput (
619
+ args : string [ ] ,
620
+ options : exec . ExecOptions = { }
621
+ ) : Promise < ExecOutput > {
622
+ return await exec . getExecOutput ( 'git' , args , options )
623
+ }
624
+
597
625
async function createPr (
598
626
title : string ,
599
627
repo : string ,
0 commit comments