You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
If I remember correctly (am not at desk) Danger.git is a platform-independent abstraction.
I definitely think your suggestion would be a useful utility. Platform specific abstractions should live in the relevant platform or provider adapter files. Happy to review a PR.
If you implement it in the one for GitHub, as a follow-up, I’d be open to the discussion of whether this should be an extension point for all platforms/providers. (Does this kind of thing sound useful for GitLab?)
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 thepatch
data for these deleted files, whichdanger.git.linesOfCode
relies upon for its calculations.To Reproduce
Steps to reproduce the behavior:
danger.git.linesOfCode
in your Dangerfile to track line changes.Expected behavior
danger.git.linesOfCode
should 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, thepatch
field is missing from the API response.This missing
patch
data 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
The text was updated successfully, but these errors were encountered: