MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / getPRDiffRanges

Function getPRDiffRanges

code-scan-action/src/github.ts:103–123  ·  view source on GitHub ↗

* Fetch PR diff and extract valid line ranges for each file. * This is used to validate and clamp comment line numbers.

(
  octokit: Octokit,
  context: PullRequestContext,
)

Source from the content-addressed store, hash-verified

101 * This is used to validate and clamp comment line numbers.
102 */
103async function getPRDiffRanges(
104 octokit: Octokit,
105 context: PullRequestContext,
106): Promise<FileLineRanges> {
107 try {
108 const { data: diff } = await octokit.pulls.get({
109 owner: context.owner,
110 repo: context.repo,
111 pull_number: context.number,
112 mediaType: { format: 'diff' },
113 });
114
115 // The diff is returned as a string when using mediaType: { format: 'diff' }
116 return extractValidLineRanges(diff as unknown as string);
117 } catch (error) {
118 core.warning(
119 `Failed to fetch PR diff for line validation: ${error instanceof Error ? error.message : String(error)}`,
120 );
121 return new Map();
122 }
123}
124
125/**
126 * Clamp a comment's line numbers to valid diff ranges.

Callers 1

Calls 2

extractValidLineRangesFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…