Dangerfile: Fix segfault when computing change size with renamed files
We're quite regularly seeing failures in our Dangerfile CI job that looks like the following:
[!] Invalid `Dangerfile` file: \e[31m
[!] Invalid `Dangerfile` file: undefined method `[]' for nil:NilClass\e[0m
# from danger/rules/changes_size/Dangerfile:8
# -------------------------------------------
#
> git.info_for_file(file)[:insertions]
# end
# -------------------------------------------
\e[0m
# from danger/rules/changes_size/Dangerfile:8
# -------------------------------------------
# %r{\\Adoc/.*(\\.(md|png|gif|jpg))\\z} => :docs,
> %r{\\A(CONTRIBUTING|LICENSE|README|REVIEWING|STYLE)(\\.md)?\\z} => :docs,
#
# -------------------------------------------
This failure happens when we're trying to find out how many lines of code have changed while filtering out some specific files like generated Protobuf files.
Most notably, this failure seems to happen whenever the commit under
test contains renamed files. What probably happens is that it cannot
find the old name of the renamed file anymore, and consequentially it
will fail with a nil
pointer exception.
Fix this bug by explicitly checking for the case where we haven't found a specific file in Git.