mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 17:50:07 +08:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import * as fs from "fs";
|
|
import * as path from "path";
|
|
|
|
import * as actionsUtil from "./actions-util";
|
|
import { Logger } from "./logging";
|
|
|
|
export interface DiffThunkRange {
|
|
path: string;
|
|
startLine: number;
|
|
endLine: number;
|
|
}
|
|
|
|
function getDiffRangesJsonFilePath(): string {
|
|
return path.join(actionsUtil.getTemporaryDirectory(), "pr-diff-range.json");
|
|
}
|
|
|
|
export function writeDiffRangesJsonFile(
|
|
logger: Logger,
|
|
ranges: DiffThunkRange[],
|
|
): void {
|
|
const jsonContents = JSON.stringify(ranges, null, 2);
|
|
const jsonFilePath = getDiffRangesJsonFilePath();
|
|
fs.writeFileSync(jsonFilePath, jsonContents);
|
|
logger.debug(
|
|
`Wrote pr-diff-range JSON file to ${jsonFilePath}:\n${jsonContents}`,
|
|
);
|
|
}
|
|
|
|
export function readDiffRangesJsonFile(
|
|
logger: Logger,
|
|
): DiffThunkRange[] | undefined {
|
|
const jsonFilePath = getDiffRangesJsonFilePath();
|
|
if (!fs.existsSync(jsonFilePath)) {
|
|
logger.debug(`Diff ranges JSON file does not exist at ${jsonFilePath}`);
|
|
return undefined;
|
|
}
|
|
const jsonContents = fs.readFileSync(jsonFilePath, "utf8");
|
|
logger.debug(
|
|
`Read pr-diff-range JSON file from ${jsonFilePath}:\n${jsonContents}`,
|
|
);
|
|
return JSON.parse(jsonContents) as DiffThunkRange[];
|
|
}
|