<commit_before>APP_NAME = "your app name here"

desc "Cruise Control build task"
task :cruise do
  RAILS_ENV = ENV['RAILS_ENV'] = 'test'
  require 'metric_fu'
  MetricFu::Configuration.run do |config|
    #define which metrics you want to use
    #config.metrics  = [:saikuro, :stats, :flog, :flay, :reek, :rcov]
    config.metrics  = [:rcov]
    config.graphs   = [:rcov]
    # config.flay     = { :dirs_to_flay => ['app', 'lib']  }
    # config.flog     = { :dirs_to_flog => ['app', 'lib']  }
    # config.reek     = { :dirs_to_reek => ['app', 'lib']  }
    # config.saikuro  = { :output_directory => 'scratch_directory/saikuro',
    #                     :input_directory => ['app', 'lib'],
    #                     :cyclo => "",
    #                     :filter_cyclo => "0",
    #                     :warn_cyclo => "5",
    #                     :error_cyclo => "7",
    #                     :formater => "text"} #this needs to be set to "text"
    config.rcov     = { :test_files => ['test/**/*_test.rb',
                                        'spec/**/*_spec.rb'],
                        :rcov_opts => ["--sort coverage",
                                       "--no-html",
                                       "--text-coverage",
                                       "--no-color",
                                       "--profile",
                                       "--rails",
                                       "--exclude /gems/,/Library/,/rubygems/,spec",
                                       "-Ilib:test"]}
  end
  CruiseControl::invoke_rake_task 'test:load:config'
  CruiseControl::invoke_rake_task 'db:migrate'
  CruiseControl::invoke_rake_task 'db:test:prepare'
  CruiseControl::invoke_rake_task 'test'
  CruiseControl::invoke_rake_task 'metrics:all'
  CruiseControl::invoke_rake_task 'verify_rcov'
end

namespace :test do
  namespace :load do
    desc "loads database.yml and any other relevant configs for the test environment"
    task :config do
      `cp /home/deploy/.cruise/projects/#{APP_NAME}/shared/config/database.yml /home/deploy/.cruise/projects/#{APP_NAME}/work/config/database.yml`
    end
  end
end

desc "Verify that rcov coverage has not decreased since previous successful build"

def get_coverage(file_location)
  total_coverage = 0
  File.open(file_location).each_line do |line|
    if line =~ /Total Coverage: (\d+\.\d+)%\s/
      total_coverage = $1.to_f
      break
    end
  end
  return total_coverage
end

task :verify_rcov do
  project_root = "/home/deploy/.cruise/projects/#{APP_NAME}"
  html_location = "output/rcov.html"
  out = ENV['CC_BUILD_ARTIFACTS']<commit_msg>run specs and tests for CC<commit_after>APP_NAME = "your app name here"

desc "Cruise Control build task"
task :cruise do
  RAILS_ENV = ENV['RAILS_ENV'] = 'test'
  require 'metric_fu'
  MetricFu::Configuration.run do |config|
    #define which metrics you want to use
    #config.metrics  = [:saikuro, :stats, :flog, :flay, :reek, :rcov]
    config.metrics  = [:rcov]
    config.graphs   = [:rcov]
    # config.flay     = { :dirs_to_flay => ['app', 'lib']  }
    # config.flog     = { :dirs_to_flog => ['app', 'lib']  }
    # config.reek     = { :dirs_to_reek => ['app', 'lib']  }
    # config.saikuro  = { :output_directory => 'scratch_directory/saikuro',
    #                     :input_directory => ['app', 'lib'],
    #                     :cyclo => "",
    #                     :filter_cyclo => "0",
    #                     :warn_cyclo => "5",
    #                     :error_cyclo => "7",
    #                     :formater => "text"} #this needs to be set to "text"
    config.rcov     = { :test_files => ['test/**/*_test.rb',
                                        'spec/**/*_spec.rb'],
                        :rcov_opts => ["--sort coverage",
                                       "--no-html",
                                       "--text-coverage",
                                       "--no-color",
                                       "--profile",
                                       "--rails",
                                       "--exclude /gems/,/Library/,/rubygems/,spec",
                                       "-Ilib:test"]}
  end
  CruiseControl::invoke_rake_task 'test:load:config'
  CruiseControl::invoke_rake_task 'db:migrate'
  CruiseControl::invoke_rake_task 'db:test:prepare'
  CruiseControl::invoke_rake_task 'default'
  CruiseControl::invoke_rake_task 'metrics:all'
  CruiseControl::invoke_rake_task 'verify_rcov'
end

namespace :test do
  namespace :load do
    desc "loads database.yml and any other relevant configs for the test environment"
    task :config do
      `cp /home/deploy/.cruise/projects/#{APP_NAME}/shared/config/database.yml /home/deploy/.cruise/projects/#{APP_NAME}/work/config/database.yml`
    end
  end
end

desc "Verify that rcov coverage has not decreased since previous successful build"

def get_coverage(file_location)
  total_coverage = 0
  File.open(file_location).each_line do |line|
    if line =~ /Total Coverage: (\d+\.\d+)%\s/
      total_coverage = $1.to_f
      break
    end
  end
  return total_coverage
end

task :verify_rcov do
  project_root = "/home/deploy/.cruise/projects/#{APP_NAME}"
  html_location = "output/rcov.html"
  out = ENV['CC_BUILD_ARTIFACTS']
{'fraction_non_alphanumeric': 0.13484848484848486, 'fraction_numerical': 0.001893939393939394, 'mean_word_length': 1.8669923995656894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5071588', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1635, 'n_words': 344}