Skip to content

Commit 77bc2a5

Browse files
committed
Write pr-diff-range JSON file
1 parent 1c15a48 commit 77bc2a5

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/analyze.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { setupCppAutobuild } from "./autobuild";
1212
import { CodeQL, getCodeQL } from "./codeql";
1313
import * as configUtils from "./config-utils";
1414
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
15+
import {
16+
DiffThunkRange,
17+
writeDiffRangesJsonFile,
18+
} from "./diff-filtering-utils";
1519
import { EnvVar } from "./environment";
1620
import { FeatureEnablement, Feature } from "./feature-flags";
1721
import { isScannedLanguage, Language } from "./languages";
@@ -284,12 +288,6 @@ export async function setupDiffInformedQueryRun(
284288
);
285289
}
286290

287-
interface DiffThunkRange {
288-
path: string;
289-
startLine: number;
290-
endLine: number;
291-
}
292-
293291
/**
294292
* Return the file line ranges that were added or modified in the pull request.
295293
*
@@ -537,6 +535,10 @@ extensions:
537535
`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`,
538536
);
539537

538+
// Write the diff ranges to a JSON file, for action-side alert filtering by the
539+
// upload-lib module.
540+
writeDiffRangesJsonFile(logger, ranges);
541+
540542
return diffRangeDir;
541543
}
542544

src/diff-filtering-utils.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
4+
import * as actionsUtil from "./actions-util";
5+
import { Logger } from "./logging";
6+
7+
export interface DiffThunkRange {
8+
path: string;
9+
startLine: number;
10+
endLine: number;
11+
}
12+
13+
function getDiffRangesJsonFilePath(): string {
14+
return path.join(actionsUtil.getTemporaryDirectory(), "pr-diff-range.json");
15+
}
16+
17+
export function writeDiffRangesJsonFile(
18+
logger: Logger,
19+
ranges: DiffThunkRange[],
20+
): void {
21+
const jsonContents = JSON.stringify(ranges, null, 2);
22+
const jsonFilePath = getDiffRangesJsonFilePath();
23+
fs.writeFileSync(jsonFilePath, jsonContents);
24+
logger.debug(
25+
`Wrote pr-diff-range JSON file to ${jsonFilePath}:\n${jsonContents}`,
26+
);
27+
}

0 commit comments

Comments
 (0)