|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -danger.import_dangerfile(gem: 'ruby-grape-danger') |
| 3 | +# Inline checks from ruby-grape-danger (avoids plugins requiring GitHub API token) |
| 4 | + |
| 5 | +has_app_changes = !git.modified_files.grep(/lib/).empty? |
| 6 | +has_spec_changes = !git.modified_files.grep(/spec/).empty? |
| 7 | + |
| 8 | +if has_app_changes && !has_spec_changes |
| 9 | + warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false) |
| 10 | +end |
| 11 | + |
| 12 | +if !has_app_changes && has_spec_changes |
| 13 | + message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false) |
| 14 | +end |
| 15 | + |
| 16 | +# Simplified changelog check (replaces danger-changelog plugin which requires github.* methods) |
| 17 | +# Note: toc.check! from danger-toc plugin removed (not essential for CI) |
| 18 | +has_changelog_changes = git.modified_files.include?('CHANGELOG.md') || git.added_files.include?('CHANGELOG.md') |
| 19 | +if has_app_changes && !has_changelog_changes |
| 20 | + warn('Please update CHANGELOG.md with a description of your changes.', sticky: false) |
| 21 | +end |
| 22 | + |
| 23 | +(git.modified_files + git.added_files - %w[Dangerfile]).each do |file| |
| 24 | + next unless File.file?(file) |
| 25 | + |
| 26 | + contents = File.read(file) |
| 27 | + if file.start_with?('spec') |
| 28 | + fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/ |
| 29 | + fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/ |
| 30 | + end |
| 31 | +end |
| 32 | + |
| 33 | +# Output as GitHub Actions annotations (since we can't post PR comments without token) |
| 34 | +if ENV['GITHUB_ACTIONS'] |
| 35 | + violation_report[:errors].each do |v| |
| 36 | + if v.file && v.line |
| 37 | + $stdout.puts "::error file=#{v.file},line=#{v.line}::#{v.message}" |
| 38 | + else |
| 39 | + $stdout.puts "::error::#{v.message}" |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + violation_report[:warnings].each do |v| |
| 44 | + if v.file && v.line |
| 45 | + $stdout.puts "::warning file=#{v.file},line=#{v.line}::#{v.message}" |
| 46 | + else |
| 47 | + $stdout.puts "::warning::#{v.message}" |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + violation_report[:messages].each do |v| |
| 52 | + if v.file && v.line |
| 53 | + $stdout.puts "::notice file=#{v.file},line=#{v.line}::#{v.message}" |
| 54 | + else |
| 55 | + $stdout.puts "::notice::#{v.message}" |
| 56 | + end |
| 57 | + end |
| 58 | +end |
0 commit comments