Skip to content

Commit

Permalink
Write pr-diff-range JSON file
Browse files Browse the repository at this point in the history
  • Loading branch information
cklin committed Feb 14, 2025
1 parent 1c15a48 commit 77bc2a5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { setupCppAutobuild } from "./autobuild";
import { CodeQL, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
import {
DiffThunkRange,
writeDiffRangesJsonFile,
} from "./diff-filtering-utils";
import { EnvVar } from "./environment";
import { FeatureEnablement, Feature } from "./feature-flags";
import { isScannedLanguage, Language } from "./languages";
Expand Down Expand Up @@ -284,12 +288,6 @@ export async function setupDiffInformedQueryRun(
);
}

interface DiffThunkRange {
path: string;
startLine: number;
endLine: number;
}

/**
* Return the file line ranges that were added or modified in the pull request.
*
Expand Down Expand Up @@ -537,6 +535,10 @@ extensions:
`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`,
);

// Write the diff ranges to a JSON file, for action-side alert filtering by the
// upload-lib module.
writeDiffRangesJsonFile(logger, ranges);

return diffRangeDir;
}

Expand Down
27 changes: 27 additions & 0 deletions src/diff-filtering-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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}`,
);
}

0 comments on commit 77bc2a5

Please sign in to comment.