@@ -2,7 +2,6 @@ import * as fs from "fs";
22import * as path from "path" ;
33import { performance } from "perf_hooks" ;
44
5- import * as github from "@actions/github" ;
65import * as io from "@actions/io" ;
76import del from "del" ;
87import * as yaml from "js-yaml" ;
@@ -16,6 +15,8 @@ import { getJavaTempDependencyDir } from "./dependency-caching";
1615import { addDiagnostic , makeDiagnostic } from "./diagnostics" ;
1716import {
1817 DiffThunkRange ,
18+ PullRequestBranches ,
19+ shouldPerformDiffInformedAnalysis ,
1920 writeDiffRangesJsonFile ,
2021} from "./diff-informed-analysis-utils" ;
2122import { EnvVar } from "./environment" ;
@@ -255,64 +256,6 @@ async function finalizeDatabaseCreation(
255256 } ;
256257}
257258
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-
316259/**
317260 * Set up the diff-informed analysis feature.
318261 *
0 commit comments