From 70aac4e01872a007132dc4c6f56ea9fecffac25c Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Mon, 9 Dec 2024 08:48:15 -0800 Subject: [PATCH] Introduce withGroupAsync() --- src/analyze.ts | 21 ++++++++++++--------- src/logging.ts | 12 ++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/analyze.ts b/src/analyze.ts index cd986bf6f..fed0ae6c8 100644 --- a/src/analyze.ts +++ b/src/analyze.ts @@ -18,7 +18,7 @@ import { addDiagnostic, makeDiagnostic } from "./diagnostics"; import { EnvVar } from "./environment"; import { FeatureEnablement, Feature } from "./feature-flags"; import { isScannedLanguage, Language } from "./languages"; -import { Logger, withGroup } from "./logging"; +import { Logger, withGroupAsync } from "./logging"; import { DatabaseCreationTimings, EventReport } from "./status-report"; import { ToolsFeature } from "./tools-features"; import { endTracingForCluster } from "./tracer-config"; @@ -256,14 +256,17 @@ export async function setupDiffInformedQueryRun( if (!(await features.getValue(Feature.DiffInformedQueries, codeql))) { return undefined; } - return await withGroup("Generating diff range extension pack", async () => { - const diffRanges = await getPullRequestEditedDiffRanges( - baseRef, - headRef, - logger, - ); - return writeDiffRangeDataExtensionPack(logger, diffRanges); - }); + return await withGroupAsync( + "Generating diff range extension pack", + async () => { + const diffRanges = await getPullRequestEditedDiffRanges( + baseRef, + headRef, + logger, + ); + return writeDiffRangeDataExtensionPack(logger, diffRanges); + }, + ); } interface DiffThunkRange { diff --git a/src/logging.ts b/src/logging.ts index f7ae8fa85..ddfb4a148 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -41,6 +41,18 @@ export function withGroup(groupName: string, f: () => T): T { } } +export async function withGroupAsync( + groupName: string, + f: () => Promise, +): Promise { + core.startGroup(groupName); + try { + return await f(); + } finally { + core.endGroup(); + } +} + /** Format a duration for use in logs. */ export function formatDuration(durationMs: number) { if (durationMs < 1000) {