* 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, )
| 101 | * This is used to validate and clamp comment line numbers. |
| 102 | */ |
| 103 | async 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. |
no test coverage detected
searching dependent graphs…