Skip to content

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

Open
@nhanvt-eh

Description

@nhanvt-eh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions