File: check_commit.rake

package info (click to toggle)
ruby-rubocop-ast 1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,256 kB
  • sloc: ruby: 15,071; yacc: 90; makefile: 9
file content (32 lines) | stat: -rw-r--r-- 865 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

begin
  require 'rubocop/rake_task'
rescue LoadError
  return
end
require 'English'

def commit_paths(commit_range)
  commit_range = "#{commit_range}~..HEAD" if commit_range.include?('..')
  `git diff-tree --no-commit-id --name-only -r #{commit_range}`.split("\n")
ensure
  exit($CHILD_STATUS.exitstatus) if $CHILD_STATUS.exitstatus != 0
end

desc 'Check files modified in commit (default: HEAD) with rspec and rubocop'
RuboCop::RakeTask.new(:check_commit, :commit) do |t, args|
  commit = args[:commit] || 'HEAD'
  paths = commit_paths(commit)
  paths.reject { |p| p.start_with?(/docs|Gemfile|README|CHANGELOG/) }
  specs = paths.select { |p| p.start_with?('spec') }

  if specs.empty?
    puts 'Caution: No spec was changed!'
  else
    puts "Checking: #{paths.join(' ')}"
    system 'rspec', *paths
  end

  t.patterns = paths
end