From e7f67e2e61e4475bb40229e4713953453decb56a Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Fri, 28 Mar 2025 12:26:26 -0700 Subject: [PATCH] Redefine shouldPerformDiffInformedAnalysis() This commit renames the original shouldPerformDiffInformedAnalysis(), which returns `PullRequestBranches | undefined`, to getDiffInformedAnalysisBranches(). It also adds a new shouldPerformDiffInformedAnalysis() function that returns boolean. Separating these two functions makes it clear what the intended uses and return values should be for each. --- src/analyze-action.ts | 4 ++-- src/diff-informed-analysis-utils.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/analyze-action.ts b/src/analyze-action.ts index 37f125dad..177cef343 100644 --- a/src/analyze-action.ts +++ b/src/analyze-action.ts @@ -22,7 +22,7 @@ import { getCodeQL } from "./codeql"; import { Config, getConfig } from "./config-utils"; import { uploadDatabases } from "./database-upload"; import { uploadDependencyCaches } from "./dependency-caching"; -import { shouldPerformDiffInformedAnalysis } from "./diff-informed-analysis-utils"; +import { getDiffInformedAnalysisBranches } from "./diff-informed-analysis-utils"; import { EnvVar } from "./environment"; import { Features } from "./feature-flags"; import { Language } from "./languages"; @@ -270,7 +270,7 @@ async function run() { logger, ); - const branches = await shouldPerformDiffInformedAnalysis( + const branches = await getDiffInformedAnalysisBranches( codeql, features, logger, diff --git a/src/diff-informed-analysis-utils.ts b/src/diff-informed-analysis-utils.ts index 611be3622..2975d8c49 100644 --- a/src/diff-informed-analysis-utils.ts +++ b/src/diff-informed-analysis-utils.ts @@ -42,12 +42,26 @@ function getPullRequestBranches(): PullRequestBranches | undefined { /** * Check if the action should perform diff-informed analysis. + */ +export async function shouldPerformDiffInformedAnalysis( + codeql: CodeQL, + features: FeatureEnablement, + logger: Logger, +): Promise { + return ( + (await getDiffInformedAnalysisBranches(codeql, features, logger)) !== + undefined + ); +} + +/** + * Get the branches to use for diff-informed analysis. * * @returns If the action should perform diff-informed analysis, return * the base and head branches that should be used to compute the diff ranges. * Otherwise return `undefined`. */ -export async function shouldPerformDiffInformedAnalysis( +export async function getDiffInformedAnalysisBranches( codeql: CodeQL, features: FeatureEnablement, logger: Logger,