Description
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:
- - - - - .
Your Environment
software | version |
---|---|
danger.js | 12.3.4 |