<commit_before>require 'metriks'

module Travis
  class Hub
    class Handler
      class Request < Handler
        def handle
          increment_counter
          if authenticated?
            increment_counter(:authenticated => true)
            debug "Creating Request with payload #{scm_payload.inspect}"
            ::Request.create_from(scm_payload, token)
            increment_counter(:created => true)
          end
        rescue StandardError => e
          increment_counter(:failed => true)
          raise
        end

        protected

          def authenticated?
            debug "Authenticating #{login} with token #{token}"
            ::Token.find_by_token(token).user.login == login
          end

          def login
            payload[:credentials][:login]
          end

          def token
            payload[:credentials][:token]
          end

          def scm_payload
            payload[:request]
          end

          def increment_counter(opts = {})
            meter_name = 'travis.hub.build_requests.received'
            meter_name = "#{meter_name}.authenticated" if opts[:authenticated]
            meter_name = "#{meter_name}.created"       if opts[:created]
            meter_name = "#{meter_name}.failed"        if opts[:failed]
            Metriks.meter(meter_name).mark
          end
      end
    end
  end
end<commit_msg>change the increment_counter method, make it simplier<commit_after>require 'metriks'

module Travis
  class Hub
    class Handler
      class Request < Handler
        def handle
          increment_counter
          if authenticated?
            increment_counter(:authenticated)
            debug "Creating Request with payload #{scm_payload.inspect}"
            ::Request.create_from(scm_payload, token)
            increment_counter(:created)
          end
        rescue StandardError => e
          increment_counter(:failed)
          raise
        end

        protected

          def authenticated?
            debug "Authenticating #{login} with token #{token}"
            ::Token.find_by_token(token).user.login == login
          end

          def login
            payload[:credentials][:login]
          end

          def token
            payload[:credentials][:token]
          end

          def scm_payload
            payload[:request]
          end

          def increment_counter(name = nil)
            meter_name = 'travis.hub.build_requests.received'
            meter_name = "#{meter_name}.#{name.to_s}" if name
            Metriks.meter(meter_name).mark
          end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07772220084647942, 'fraction_numerical': 0.0, 'mean_word_length': 1.7282266526757608, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1764619', 'n_tokens_mistral': 680, 'n_tokens_neox': 655, 'n_words': 159}