<commit_before>require 'rake'
require 'rake/testtask'
require 'fileutils'
require 'pathname'
require 'open-uri'
require 'redis-store/testing/redis_replication_runner'
require 'date'

class RedisStoreTesting
  include Rake::DSL

  def self.install_tasks(options = {})
    new(options[:dir]).install
  end

  def initialize(dir = nil)
    @dir    = Pathname.new(dir ||= Dir.pwd).realpath
    @runner = RedisReplicationRunner.new(@dir)
  end

  def install
    namespace :redis do
      redis_about
      redis_install
      redis_make
      redis_download

      namespace :test do
        redis_test_suite
        redis_test_run
        redis_test_prepare
      end

      namespace :replication do
        redis_replication_start
        redis_replication_stop
        redis_replication_console
      end
    end

    changelog

    run_tests_locally

    task default: 'redis:test:suite'
  end

  protected

  def changelog
    task :changelog, :from, :to do |_t, args|
      from = args[:from] || `git describe --tags --abbrev=0`.strip
      to = args[:to] || 'HEAD'
      log = `git log #{from}..#{to} --pretty=format:'%an|%B___'`

      puts "#{project_title} (#{Date.today})"
      puts '-' * 80
      puts

      log.split(/___/).each do |commit|
        pieces = commit.split('|').reverse
        author = pieces.pop.strip
        message = pieces.join.strip

        next if message =~ /^\s*Merge pull request/
        next if message =~ /No changelog/

        ticket = message.scan(/SEGMENTS-\d+/)[0]
        next if ticket.nil?
        next if message =~ /^\s*Merge branch/ && ticket.nil?

        first_line = false

        message.each_line do |line|
          if !first_line
            first_line = true
            puts "*   #{line}"
          elsif line.strip.empty?
            puts
          else
            puts "    #{line}"
          end
        end

        puts "    #{author}"
        puts
      end
    end
  end

  def run_tests_locally
    desc 'Run tests for all supported dependency versions'
    task :test do
      Rake::Task['redis:test:suite'].invoke if appraisal_gemfiles.empty?

      appraisal_gemfiles.each do |gemfile|
        sh "BUNDLE_GEMFILE=#{gemfile} bundle exec rake"<commit_msg>Fix changelog<commit_after>require 'rake'
require 'rake/testtask'
require 'fileutils'
require 'pathname'
require 'open-uri'
require 'redis-store/testing/redis_replication_runner'
require 'date'

class RedisStoreTesting
  include Rake::DSL

  def self.install_tasks(options = {})
    new(options[:dir]).install
  end

  def initialize(dir = nil)
    @dir    = Pathname.new(dir ||= Dir.pwd).realpath
    @runner = RedisReplicationRunner.new(@dir)
  end

  def install
    namespace :redis do
      redis_about
      redis_install
      redis_make
      redis_download

      namespace :test do
        redis_test_suite
        redis_test_run
        redis_test_prepare
      end

      namespace :replication do
        redis_replication_start
        redis_replication_stop
        redis_replication_console
      end
    end

    changelog

    run_tests_locally

    task default: 'redis:test:suite'
  end

  protected

  def changelog
    task :changelog, :from, :to do |_t, args|
      from = args[:from] || `git describe --tags --abbrev=0`.strip
      to = args[:to] || 'HEAD'
      log = `git log #{from}..#{to} --pretty=format:'%an|%B___'`

      puts "#{project_title} (#{Date.today})"
      puts '-' * 80
      puts

      log.split(/___/).each do |commit|
        pieces = commit.split('|').reverse
        author = pieces.pop.strip
        message = pieces.join.strip

        next if message =~ /^\s*Merge pull request/
        next if message =~ /No changelog/
        next if message =~ /^\s*Merge branch/ && ticket.nil?

        first_line = false

        message.each_line do |line|
          if !first_line
            first_line = true
            puts "*   #{line}"
          elsif line.strip.empty?
            puts
          else
            puts "    #{line}"
          end
        end

        puts "    #{author}"
        puts
      end
    end
  end

  def run_tests_locally
    desc 'Run tests for all supported dependency versions'
    task :test do
      Rake::Task['redis:test:suite'].invoke if appraisal_gemfiles.empty?

      appraisal_gemfiles.each do |gemfile|
        sh "BUNDLE_GEMFILE=#{gemfile} bundle exec rake"
{'fraction_non_alphanumeric': 0.10351919561243145, 'fraction_numerical': 0.0015996343692870202, 'mean_word_length': 2.16028880866426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3495868', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1388, 'n_words': 337}