@@ -2,7 +2,6 @@ import * as fs from "fs";
2
2
import * as path from "path" ;
3
3
import { performance } from "perf_hooks" ;
4
4
5
- import * as github from "@actions/github" ;
6
5
import * as io from "@actions/io" ;
7
6
import del from "del" ;
8
7
import * as yaml from "js-yaml" ;
@@ -16,6 +15,8 @@ import { getJavaTempDependencyDir } from "./dependency-caching";
16
15
import { addDiagnostic , makeDiagnostic } from "./diagnostics" ;
17
16
import {
18
17
DiffThunkRange ,
18
+ PullRequestBranches ,
19
+ shouldPerformDiffInformedAnalysis ,
19
20
writeDiffRangesJsonFile ,
20
21
} from "./diff-informed-analysis-utils" ;
21
22
import { EnvVar } from "./environment" ;
@@ -255,64 +256,6 @@ async function finalizeDatabaseCreation(
255
256
} ;
256
257
}
257
258
258
- interface PullRequestBranches {
259
- base : string ;
260
- head : string ;
261
- }
262
-
263
- function getPullRequestBranches ( ) : PullRequestBranches | undefined {
264
- const pullRequest = github . context . payload . pull_request ;
265
- if ( pullRequest ) {
266
- return {
267
- base : pullRequest . base . ref ,
268
- // We use the head label instead of the head ref here, because the head
269
- // ref lacks owner information and by itself does not uniquely identify
270
- // the head branch (which may be in a forked repository).
271
- head : pullRequest . head . label ,
272
- } ;
273
- }
274
-
275
- // PR analysis under Default Setup does not have the pull_request context,
276
- // but it should set CODE_SCANNING_REF and CODE_SCANNING_BASE_BRANCH.
277
- const codeScanningRef = process . env . CODE_SCANNING_REF ;
278
- const codeScanningBaseBranch = process . env . CODE_SCANNING_BASE_BRANCH ;
279
- if ( codeScanningRef && codeScanningBaseBranch ) {
280
- return {
281
- base : codeScanningBaseBranch ,
282
- // PR analysis under Default Setup analyzes the PR head commit instead of
283
- // the merge commit, so we can use the provided ref directly.
284
- head : codeScanningRef ,
285
- } ;
286
- }
287
- return undefined ;
288
- }
289
-
290
- /**
291
- * Check if the action should perform diff-informed analysis.
292
- *
293
- * @returns If the action should perform diff-informed analysis, return
294
- * the base and head branches that should be used to compute the diff ranges.
295
- * Otherwise return `undefined`.
296
- */
297
- async function shouldPerformDiffInformedAnalysis (
298
- codeql : CodeQL ,
299
- features : FeatureEnablement ,
300
- logger : Logger ,
301
- ) : Promise < PullRequestBranches | undefined > {
302
- if ( ! ( await features . getValue ( Feature . DiffInformedQueries , codeql ) ) ) {
303
- return undefined ;
304
- }
305
-
306
- const branches = getPullRequestBranches ( ) ;
307
- if ( ! branches ) {
308
- logger . info (
309
- "Not performing diff-informed analysis " +
310
- "because we are not analyzing a pull request." ,
311
- ) ;
312
- }
313
- return branches ;
314
- }
315
-
316
259
/**
317
260
* Set up the diff-informed analysis feature.
318
261
*
0 commit comments