<commit_before>require 'metriks'

module Travis
  class Hub
    class Handler
      class Request < Handler
        # Handles request messages which are created by the listener
        # when a github event comes in.
        def type
          payload['type']
        end

        def credentials
          payload['credentials']
        end

        def data
          # TODO hot compat. remove :request once listener pushes :payload
          @data ||= MultiJson.decode(payload['request'] || payload['payload'])
        end

        def handle
          ::Request.receive(type, data, credentials['token']) if authenticate
        end
        instrument :handle, :scope => :type
        new_relic :handle

        private

          def authenticate
            Thread.current[:current_user] = User.authenticate_by(credentials)
          end
          instrument :authenticate, :scope => :type
<commit_msg>stop raising an exception when both :request and :payload are empty<commit_after>require 'metriks'

module Travis
  class Hub
    class Handler
      class Request < Handler
        # Handles request messages which are created by the listener
        # when a github event comes in.
        def type
          payload['type']
        end

        def credentials
          payload['credentials']
        end

        def data
          # TODO hot compat. remove :request once listener pushes :payload
          # TODO why do we get empty requests (without 'request' or 'payload' being set)?
          @data ||= MultiJson.decode(payload['request'] || payload['payload'] || '{}')
        end

        def handle
          ::Request.receive(type, data, credentials['token']) if authenticate && !data.empty?
        end
        instrument :handle, :scope => :type
        new_relic :handle

        private

          def authenticate
            Thread.current[:current_user] = User.authenticate_by(credentials)
          end
          instrument :authenticate, :scope => :type

{'fraction_non_alphanumeric': 0.08123107971745712, 'fraction_numerical': 0.0, 'mean_word_length': 2.079192546583851, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3377418', 'n_tokens_mistral': 501, 'n_tokens_neox': 474, 'n_words': 170}