|
| 1 | +has_app_changes = !git.modified_files.grep(/lib/).empty? |
| 2 | +has_test_changes = !git.modified_files.grep(/spec/).empty? |
| 3 | + |
| 4 | +# Sometimes it's a README fix, or something like that - which isn't relevant for |
| 5 | +# including in a project's CHANGELOG for example |
| 6 | +declared_trivial = pr_title.include? '#trivial' |
| 7 | + |
| 8 | +# Make it more obvious that a PR is a work in progress and shouldn't be merged yet |
| 9 | +warn('PR is classed as Work in Progress') if pr_title.include? '[WIP]' |
| 10 | + |
| 11 | +# Warn when there is a big PR |
| 12 | +warn('Big PR') if lines_of_code > 500 |
| 13 | + |
| 14 | +# Add a CHANGELOG entry for app changes |
| 15 | +if !modified_files.include?('CHANGELOG.md') && has_app_changes |
| 16 | + fail('Please include a CHANGELOG entry.') |
| 17 | +end |
| 18 | + |
| 19 | +# Warn about un-updated tests |
| 20 | +if has_app_changes && !has_test_changes |
| 21 | + warn 'Tests were not updated' |
| 22 | +end |
| 23 | + |
| 24 | +if github.pr_body.length < 5 |
| 25 | + fail 'Please provide a summary in the Pull Request description' |
| 26 | +end |
| 27 | + |
| 28 | +# TODO: This could be a danger plugin |
| 29 | +files_to_lint = (modified_files + added_files).select { |f| f.end_with? 'rb' } |
| 30 | +rubocop_results = files_to_lint.map { |f| JSON.parse(`bundle exec rubocop -f json #{f}`)['files'] }.flatten |
| 31 | +offending_files = rubocop_results.select { |f| f['offenses'].count > 0 } |
| 32 | + |
| 33 | +unless offending_files.empty? |
| 34 | + message = '### Rubocop violations' |
| 35 | + message << 'File | Line | Reason |\n' |
| 36 | + message << '| --- | ----- | ----- |\n' |
| 37 | + |
| 38 | + offending_files.each do |f| |
| 39 | + f['offenses'].each do |o| |
| 40 | + message << "#{f['path']} | #{o['location']['line']} | #{o['message']} \n" |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + markdown message |
| 45 | +end |
0 commit comments