<commit_before>require_relative "./evm_test_helper"

if defined?(RSpec) && defined?(RSpec::Core::RakeTask)
namespace :test do
  namespace :replication do
    desc "Setup environment for replication specs"
    task :setup => :initialize do
      EvmTestSetupReplication.new.write_released_migrations
    end
  end

  desc "Run all replication specs"
  RSpec::Core::RakeTask.new(:replication => :initialize) do |t|
    EvmTestHelper.init_rspec_task(t)
    t.pattern = EvmTestHelper::REPLICATION_UTIL_SPECS
  end
end
end # ifdef

class EvmTestSetupReplication
  TEST_BRANCH = "evm_test_setup_replication_branch".freeze

  def write_released_migrations
    file_contents = released_migrations.sort.join("\n")
    File.write(Rails.root.join("spec/replication/util/data/euwe_migrations"), file_contents)
  end

  private

  def released_migrations
    unless system(fetch_command)
      return []
    end
    files = `git ls-tree -r --name-only #{TEST_BRANCH} db/migrate/`
    return [] unless $CHILD_STATUS.success?

    migrations = files.split.map do |path|
      filename = path.split("/")[-1]
      filename.split('_')[0]
    end

    # eliminate any non-timestamp entries
    migrations.keep_if { |timestamp| timestamp =~ /\d+/ }
  ensure
    `git branch -D #{TEST_BRANCH}`
  end

  def fetch_command
    "git fetch #{'--depth=1 ' if ENV['CI']}http://github.com/ManageIQ/manageiq.git refs/heads/euwe:#{TEST_BRANCH}"
  end
end
<commit_msg>Add setup_db to rake task dependency<commit_after>require_relative "./evm_test_helper"

if defined?(RSpec) && defined?(RSpec::Core::RakeTask)
namespace :test do
  namespace :replication do
    desc "Setup environment for replication specs"
    task :setup => :setup_db do
      EvmTestSetupReplication.new.write_released_migrations
    end
  end

  desc "Run all replication specs"
  RSpec::Core::RakeTask.new(:replication => :initialize) do |t|
    EvmTestHelper.init_rspec_task(t)
    t.pattern = EvmTestHelper::REPLICATION_UTIL_SPECS
  end
end
end # ifdef

class EvmTestSetupReplication
  TEST_BRANCH = "evm_test_setup_replication_branch".freeze

  def write_released_migrations
    file_contents = released_migrations.sort.join("\n")
    File.write(Rails.root.join("spec/replication/util/data/euwe_migrations"), file_contents)
  end

  private

  def released_migrations
    unless system(fetch_command)
      return []
    end
    files = `git ls-tree -r --name-only #{TEST_BRANCH} db/migrate/`
    return [] unless $CHILD_STATUS.success?

    migrations = files.split.map do |path|
      filename = path.split("/")[-1]
      filename.split('_')[0]
    end

    # eliminate any non-timestamp entries
    migrations.keep_if { |timestamp| timestamp =~ /\d+/ }
  ensure
    `git branch -D #{TEST_BRANCH}`
  end

  def fetch_command
    "git fetch #{'--depth=1 ' if ENV['CI']}http://github.com/ManageIQ/manageiq.git refs/heads/euwe:#{TEST_BRANCH}"
  end
end

{'fraction_non_alphanumeric': 0.11598205039696237, 'fraction_numerical': 0.0020711080428028996, 'mean_word_length': 3.878787878787879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6864400', 'n_tokens_mistral': 1001, 'n_tokens_neox': 988, 'n_words': 205}