<commit_before>require 'rollbar'
require 'minitest/reporters'

module MinitestRollbar
  class << self
    attr_accessor :access_token
    attr_accessor :use_default_grouping
  end

  class RollbarReporter < Minitest::Reporters::BaseReporter
    def initialize(options = {})
      super
      @sequential_exception_count = 0
      # Inspect will return ExceptionType + Message.
      # E.g #<Selenium::WebDriver::Error::NoSuchWindowError: Window not found. The browser window may have been closed.>
      # Use this as a criteria for log batch grouping
      @previous_exception_inspect_result = nil
      @previous_exception = nil

      raise 'Must set rollbar access token' if MinitestRollbar.access_token.nil?
      Rollbar.configure do |config|
        config.access_token = MinitestRollbar.access_token
        config.verify_ssl_peer = false
      end
    end

    def record(result)
      super
      if result.error?
        current_exception = result.failure.exception
        current_exception_inspect_result = current_exception.inspect

        if @previous_exception_inspect_result.nil?
          record_new_error(current_exception)
        elsif current_exception_inspect_result == @previous_exception_inspect_result
          increment_error_counting
        else # New exception
          report_error_to_rollbar notifier
          record_new_error current_exception
        end
      else
        unless @previous_exception.nil?
          report_error_to_rollbar notifier
          reset_error_counting
        end
      end
    end

    def report
      super
      if @sequential_exception_count > 0
        report_error_to_rollbar notifier
        reset_error_counting
      end
    end

    private

    def notifier
      MinitestRollbar.use_default_grouping.nil? ?
          Rollbar.scope({count: @sequential_exception_count,  fingerprint: @previous_exception_inspect_result}):
          Rollbar.scope({count: @sequential_exception_count})
    end

    def report_error_to_rollbar(notifier)
      notifier.error(@previous_exception)
    end

    def reset_error_counting
      @previous_exception_inspect_result = nil
      @previous_exception = nil
      @sequential_exception_count = 0
    end

    def increment_error_counting<commit_msg>ysw - Add configuration for enable_verify_ssl_peer<commit_after>require 'rollbar'
require 'minitest/reporters'
module MinitestRollbar
  class << self
    attr_accessor :access_token
    attr_accessor :use_default_grouping
    attr_accessor :enable_verify_ssl_peer
  end

  class RollbarReporter < Minitest::Reporters::BaseReporter
    def initialize(options = {})
      super
      @sequential_exception_count = 0
      # Inspect will return ExceptionType + Message.
      # E.g #<Selenium::WebDriver::Error::NoSuchWindowError: Window not found. The browser window may have been closed.>
      # Use this as a criteria for log batch grouping
      @previous_exception_inspect_result = nil
      @previous_exception = nil

      raise 'Must set rollbar access token' if MinitestRollbar.access_token.nil?
      Rollbar.configure do |config|
        config.access_token = M<PASSWORD>bar.access_token
        config.verify_ssl_peer = false

        unless MinitestRollbar.enable_verify_ssl_peer.nil?
          config.verify_ssl_peer = MinitestRollbar.enable_verify_ssl_peer
        end

      end
    end

    def record(result)
      super
      if result.error?
        current_exception = result.failure.exception
        current_exception_inspect_result = current_exception.inspect

        if @previous_exception_inspect_result.nil?
          record_new_error(current_exception)
        elsif current_exception_inspect_result == @previous_exception_inspect_result
          increment_error_counting
        else # New exception
          report_error_to_rollbar notifier
          record_new_error current_exception
        end
      else
        unless @previous_exception.nil?
          report_error_to_rollbar notifier
          reset_error_counting
        end
      end
    end

    def report
      super
      if @sequential_exception_count > 0
        report_error_to_rollbar notifier
        reset_error_counting
      end
    end

    private

    def notifier
        if(MinitestRollbar.use_default_grouping.nil?)
          Rollbar.scope({count: @sequential_exception_count,  fingerprint: @previous_exception_inspect_result})
        else
          Rollbar.scope({count: @sequential_exception_count})
        end
    end

    def report_error_to_rollbar(notifier)
      notifier.error(@previous_exception)
    end

    def reset_error_counting
      @previous_exception_inspect_result = nil
      @previous_exception = nil
      @sequential_exception_count = 0
    end

    def increment_error_counting
{'fraction_non_alphanumeric': 0.05067001675041876, 'fraction_numerical': 0.001256281407035176, 'mean_word_length': 2.94467382328654, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 8, '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': '2866412', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1341, 'n_words': 288}