Skip to content

Conversation

@martinemde
Copy link
Contributor

Problem Description

The danger-packwerk gem's package_todo_yml_changes.check validation was failing when files were renamed in a PR. When a developer:

  1. Renamed a file (e.g., fulfillment_document_service.rbapplication_document_service.rb)
  2. Git recognized this as a rename operation
  3. Ran bin/pks update to update package_todo.yml with the new filename
  4. The Danger check would fail with an error like:
    Unable to find reference to violation {
      file: "packs/.../fulfillment_document_service.rb",
      to_package_name: "packs/...",
      type: "privacy"
    } in packs/.../package_todo.yml
    

Root Cause

When comparing violations from the "before" state (which referenced old filenames) to the "after" state (which referenced new filenames), the violation comparison logic didn't account for renamed files. The BasicReferenceOffense#== method compares all fields including the file field, so violations with different file paths wouldn't match even if they represented the same violation on a renamed file.

Solution

The fix normalizes file paths in violations when comparing them:

  1. Build a rename mapping - Create a hash mapping old file paths to new file paths from git.renamed_files
  2. Normalize violations before comparison - When comparing violations from the base commit to the head commit, update the file paths in base commit violations to use the new names
  3. This allows proper matching - Violations that only differ by a renamed file path will now be recognized as the same violation

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the danger-packwerk gem where validation of package_todo.yml files would fail when files were renamed. The fix normalizes file paths during violation comparison by building a rename mapping and updating old file paths to new ones before comparing violations.

  • Adds logic to build a rename mapping from Git's renamed files data
  • Implements violation normalization that updates old file paths to new paths before comparison
  • Adds comprehensive test coverage for both single and multiple file rename scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/danger-packwerk/private/todo_yml_changes.rb Implements core fix with rename mapping and violation normalization logic
spec/danger_packwerk/danger_package_todo_yml_changes_spec.rb Adds test coverage for single and multiple file rename scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@martinemde martinemde merged commit 30148a2 into main Oct 21, 2025
6 checks passed
@martinemde martinemde deleted the martinemde/fix-renamed-file-dangerfile-fail branch October 21, 2025 18:02
@github-project-automation github-project-automation bot moved this from Triage to Done in Modularity Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants