Skip to content

Commit

Permalink
Danger-bot: More meaningful maximum PR size message (#3517)
Browse files Browse the repository at this point in the history
  • Loading branch information
omgitsbillryan authored Nov 7, 2019
1 parent ae1cf2d commit f14a8f5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Dangerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ EXCLUSIONS = ['Gemfile.lock', '.json', 'spec/fixtures/', '.txt', 'spec/support/v
# takes form {"some/file.rb"=>{:insertions=>4, :deletions=>1}}
changed_files = git.diff.stats[:files]

excluded_changed_files = changed_files.select { |key| EXCLUSIONS.any? { |exclusion| key.include?(exclusion) } }
filtered_changed_files = changed_files.reject { |key| EXCLUSIONS.any? { |exclusion| key.include?(exclusion) } }
lines_of_code = filtered_changed_files.sum { |_file, changes| (changes[:insertions] + changes[:deletions]) }

if lines_of_code > MAX_PR_SIZE
warn("PR is exceeds `#{MAX_PR_SIZE}` LoC. Consider breaking up into multiple smaller ones.")
msg = <<~HTML
You changed `#{lines_of_code}` LoC. This exceeds our desired maximum of `#{MAX_PR_SIZE}`. Big PRs are difficult to review and often become stale. Consider breaking this PR up into smaller ones.
**Calculation Summary**
- #{filtered_changed_files.collect { |key, val| "#{key} (+#{val[:insertions]}/-#{val[:deletions]} )" }.join("\n- ")}
**Exclusions**
- #{excluded_changed_files.collect { |key, val| "#{key} (+#{val[:insertions]}/-#{val[:deletions]} )" }.join("\n- ")}
HTML
warn(msg)
end

# Warn when a PR includes a simultaneous DB migration and application code changes
Expand Down

0 comments on commit f14a8f5

Please sign in to comment.