<commit_before># The Sinatra App that handles incoming events.
class Service::App < Sinatra::Base

  set :hostname, lambda { %x{hostname} }

  # Hooks the given Service to a Sinatra route.
  #
  # svc - Service instance.
  #
  # Returns nothing.
  def self.service(svc)
    post "/#{svc.hook_name}/:event" do
      data = nil
      begin
        data    = JSON.parse(params[:data])
        payload = parse_payload(params[:payload])
        if svc.receive(:push, data, payload)
          status 200
          ""
        else
          status 404
          status "#{svc.hook_name} Service does not respond to 'push' events"
        end
      rescue Service::ConfigurationError => boom
        status 400
        boom.message
      rescue Service::TimeoutError => boom
        status 504
        report_exception svc, data, boom
        "Service Timeout"
      rescue Object => boom
        report_exception svc, data, boom
        status 500
        "ERROR"
      end
    end
  end

  get "/" do
    "ok"
  end

  # Parses the incoming payload and massages any properties.
  #
  # json - JSON String.
  #
  # Returns a Hash payload.
  def parse_payload(json)
    payload = JSON.parse(json)
    payload['ref_name'] = payload['ref'].to_s.sub(/\Arefs\/(heads|tags)\//, '')
    payload<commit_msg>failed connections should not get logged -- user error<commit_after># The Sinatra App that handles incoming events.
class Service::App < Sinatra::Base

  set :hostname, lambda { %x{hostname} }

  # Hooks the given Service to a Sinatra route.
  #
  # svc - Service instance.
  #
  # Returns nothing.
  def self.service(svc)
    post "/#{svc.hook_name}/:event" do
      data = nil
      begin
        data    = JSON.parse(params[:data])
        payload = parse_payload(params[:payload])
        if svc.receive(:push, data, payload)
          status 200
          ""
        else
          status 404
          status "#{svc.hook_name} Service does not respond to 'push' events"
        end
      rescue Faraday::Error::ConnectionFailed => boom
        status 400
        boom.message
      rescue Service::ConfigurationError => boom
        status 400
        boom.message
      rescue Service::TimeoutError => boom
        status 504
        report_exception svc, data, boom
        "Service Timeout"
      rescue Object => boom
        report_exception svc, data, boom
        status 500
        "ERROR"
      end
    end
  end

  get "/" do
    "ok"
  end

  # Parses the incoming payload and massages any properties.
  #
  # json - JSON String.
  #
  # Returns a Hash payload.
  def parse_payload(json)
    payload = JSON.parse(json)
    payload['ref_name'] = payload['ref'].to_s.sub(/\Arefs\/(heads|tags)\//, '')
    payload
{'fraction_non_alphanumeric': 0.10114012504597278, 'fraction_numerical': 0.012136815005516733, 'mean_word_length': 2.1517960602549246, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '6902687', 'n_tokens_mistral': 828, 'n_tokens_neox': 797, 'n_words': 242}