Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Large File Deletion: linesOfCode Reports Zero Changes #1478

Open
nhanvt-eh opened this issue Mar 3, 2025 · 3 comments
Open

[BUG] Large File Deletion: linesOfCode Reports Zero Changes #1478

nhanvt-eh opened this issue Mar 3, 2025 · 3 comments
Labels

Comments

@nhanvt-eh
Copy link

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:

  1. Use danger.git.linesOfCode in your Dangerfile to track line changes.
  2. Create a PR that deletes a large file (e.g., for me, it was a file with 10,000 lines of code).
  3. 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.
Image

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
@nhanvt-eh nhanvt-eh added the bug label Mar 3, 2025
@nhanvt-eh nhanvt-eh changed the title [BUG] [BUG] Large File Deletion: linesOfCode Reports Zero Changes Mar 3, 2025
@orta
Copy link
Member

orta commented Mar 4, 2025

That's both reasonable from Github's side and a bit of a shame, perhaps there's a higher level API route for that which could be used in those cases

@nhanvt-eh
Copy link
Author

That's both reasonable from Github's side and a bit of a shame, perhaps there's a higher level API route for that which could be used in those cases

The API also returns additions, deletions, changes. Could we adapt danger.git.linesOfCode to somehow work with these instead of just patch? 🤔

@fbartho
Copy link
Member

fbartho commented Mar 4, 2025

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?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants