Skip to content

Dangerfile: Don't check old names of renamed files

Will Chandler (ex-GitLab) requested to merge wc/danger-remove-old-names into master

Our changes_size Dangerfile currently uses the added_files and modified_files methods to get a list of all files to check. However, modified_files may return the old name of a renamed file. When this occurs, the diff property for that file may be nil, causing the danger job to error out with:

  bundler: failed to load command: danger (/builds/gitlab-org/gitaly/_build/cache/ruby/ruby/3.0.0/bin/danger)
  /builds/gitlab-org/gitaly/_build/cache/ruby/ruby/3.0.0/gems/danger-9.2.0/lib/danger/danger_core/plugins/dangerfile_git_plugin.rb:144:in `info_for_file': \e[31m (Danger::DSLError)
  [!] Invalid `Dangerfile` file: \e[31m
  [!] Invalid `Dangerfile` file: undefined method `[]' for nil:NilClass\e[0m
   #  from danger/rules/changes_size/Dangerfile:8
   #  -------------------------------------------
   #
   >    info = git.info_for_file(file)
   #
   #  -------------------------------------------
  \e[0m
   #  from danger/rules/changes_size/Dangerfile:8

See here for full output.

A fix for this was attempted in !5279 (merged), but in this case file is nil, rather than info.

To prevent this from occurring, capture the list of renames and remove the old names from the list of files to check. A previously failing pipeline that now passes can be viewed here.

Merge request reports