module NdrDevSupport::RakeCI::CommitCop

This module encapsulates commit cop logic

Constants

COMMIT_COPS

Public Class Methods

changes(commit) click to toggle source

converts the deltas into a simpler changes hash of filename sets representation

# File lib/ndr_dev_support/rake_ci/commit_cop.rb, line 52
def self.changes(commit)
  changes = { added: Set.new, deleted: Set.new, modified: Set.new, renamed: Set.new }

  each_delta(commit) do |delta|
    if delta.status == :renamed
      changes[delta.status].add([delta.old_file[:path], delta.new_file[:path]])
    else
      # old_file and new_file are the same
      changes[delta.status].add(delta.old_file[:path])
    end
  end

  changes
end
each_delta(commit, &block) click to toggle source

enumerates over each delta of the commmit

# File lib/ndr_dev_support/rake_ci/commit_cop.rb, line 45
def self.each_delta(commit, &block)
  diffs = commit.parents.first.diff(commit)
  diffs.find_similar!
  diffs.each_delta(&block)
end
with_pattern() { || ... } click to toggle source

Isolates migration/structure pattern changes by resetting them after yielding

# File lib/ndr_dev_support/rake_ci/commit_cop.rb, line 68
def self.with_pattern
  default_migration_paths = migration_paths
  default_structure_dump_pattern = structure_dump_pattern

  yield

  self.migration_paths = default_migration_paths
  self.structure_dump_pattern = default_structure_dump_pattern
end