Describe the bug
I'm utilizing DangerJS within our GitHub Actions workflow to enforce code change limits. Specifically, I'm using danger.git.linesOfCode to calculate the number of lines modified, with the intention of ignoring changes matching certain patterns.
However, I have discovered that danger.git.linesOfCode is producing inaccurate results when large files are deleted in a pull request (PR). This is due to the GitHub API not consistently returning the patch data for these deleted files, which danger.git.linesOfCode relies upon for its calculations.
To Reproduce
Steps to reproduce the behavior:
- Use
danger.git.linesOfCode in your Dangerfile to track line changes.
- Create a PR that deletes a large file (e.g., for me, it was a file with 10,000 lines of code).
- Observe that danger.git.linesOfCode incorrectly reports zero lines changed for the removed file (which contained 10,000+ lines). Smaller files report correct line changes
Expected behavior
danger.git.linesOfCode should accurately report the number of deleted lines for large files
Screenshots
Upon investigation, the issue appears to stem from the GitHub API's response when retrieving file changes for a PR. The API call repos/${repo}/pulls/${prID}/files?page=${page}&per_page=${perPage} is used to fetch file data. For large file deletions, the patch field is missing from the API response.

This missing patch data directly impacts the calculation performed by danger.git.linesOfCode, as shown in the following code flow:
|
const linesOfCode = async (pattern?: string) => { |
-
|
const diffForFile = async (filename: string) => { |
-
|
const structuredDiffForFile = async (filename: string): Promise<StructuredDiff | null> => { |
-
|
getFullDiff: ghAPI.getPullRequestDiff, |
-
|
getPullRequestDiff = async (): Promise<string> => { |
.
Your Environment
| software |
version |
| danger.js |
12.3.4 |
Describe the bug
I'm utilizing DangerJS within our GitHub Actions workflow to enforce code change limits. Specifically, I'm using
danger.git.linesOfCodeto calculate the number of lines modified, with the intention of ignoring changes matching certain patterns.However, I have discovered that
danger.git.linesOfCodeis producing inaccurate results when large files are deleted in a pull request (PR). This is due to the GitHub API not consistently returning thepatchdata for these deleted files, whichdanger.git.linesOfCoderelies upon for its calculations.To Reproduce
Steps to reproduce the behavior:
danger.git.linesOfCodein your Dangerfile to track line changes.Expected behavior
danger.git.linesOfCodeshould accurately report the number of deleted lines for large filesScreenshots

Upon investigation, the issue appears to stem from the GitHub API's response when retrieving file changes for a PR. The API call
repos/${repo}/pulls/${prID}/files?page=${page}&per_page=${perPage}is used to fetch file data. For large file deletions, thepatchfield is missing from the API response.This missing
patchdata directly impacts the calculation performed bydanger.git.linesOfCode, as shown in the following code flow:danger-js/source/platforms/git/gitJSONToGitDSL.ts
Line 158 in 1cdf428
danger-js/source/platforms/git/gitJSONToGitDSL.ts
Line 221 in 1cdf428
danger-js/source/platforms/git/gitJSONToGitDSL.ts
Line 195 in 1cdf428
danger-js/source/platforms/github/GitHubGit.ts
Line 58 in 1cdf428
danger-js/source/platforms/github/GitHubAPI.ts
Line 373 in 1cdf428
Your Environment