Skip to content

Commit

Permalink
Introduce withGroupAsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuan-kai Lin committed Dec 9, 2024
1 parent 8975792 commit 70aac4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export function withGroup<T>(groupName: string, f: () => T): T {
}
}

export async function withGroupAsync<T>(
groupName: string,
f: () => Promise<T>,
): Promise<T> {
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) {
Expand Down

0 comments on commit 70aac4e

Please sign in to comment.