<commit_before>require "faraday"
require "json"

module Travis
  module Worker
    module Job
      class Script
        CompileError = Class.new(StandardError)

        include Retryable

        def initialize(payload)
          @payload = payload
        end

        def script
          response = retryable(tries: 3, on: Faraday::Error::TimeoutError) do
            connection.post("/script", JSON.dump(data), {
              "Content-Type" => "application/json",
              "Accept" => "text/plain",
            })
          end

          if response.status == 500
            raise CompileError, "An error occurred while compiling the build script: #{response.body}"
          end

          response.body
        rescue Faraday::Error::TimeoutError
          raise CompileError, "The build script API timed out"
        end

        private

        def connection
          @connection ||= Faraday.new(
            url: Travis::Worker.config[:build].fetch(:url),
            headers: {
              "Authorization" => "token #{Travis::Worker.config[:build].fetch(:api_token)}",
              "User-Agent" => "travis-worker",
            },
            timeout: Travis::Worker.config[:timeouts].fetch(:build_script),
          )
        end

        def data
          @payload.merge(
            hosts: Travis::Worker.config[:hosts],
            paranoid: Travis::Worker.config[:paranoid],
            skip_resolv_updates: Travis::Worker.config[:skip_resolv_updates],
            skip_etch_hosts_fix: Travis::Worker.config[:skip_etc_hosts_fix],
            cache_options: Travis::Worker.config[:cache_options]<commit_msg>script: fix typo 'etch_hosts' -> 'etc_hosts'<commit_after>require "faraday"
require "json"

module Travis
  module Worker
    module Job
      class Script
        CompileError = Class.new(StandardError)

        include Retryable

        def initialize(payload)
          @payload = payload
        end

        def script
          response = retryable(tries: 3, on: Faraday::Error::TimeoutError) do
            connection.post("/script", JSON.dump(data), {
              "Content-Type" => "application/json",
              "Accept" => "text/plain",
            })
          end

          if response.status == 500
            raise CompileError, "An error occurred while compiling the build script: #{response.body}"
          end

          response.body
        rescue Faraday::Error::TimeoutError
          raise CompileError, "The build script API timed out"
        end

        private

        def connection
          @connection ||= Faraday.new(
            url: Travis::Worker.config[:build].fetch(:url),
            headers: {
              "Authorization" => "token #{Travis::Worker.config[:build].fetch(:api_token)}",
              "User-Agent" => "travis-worker",
            },
            timeout: Travis::Worker.config[:timeouts].fetch(:build_script),
          )
        end

        def data
          @payload.merge(
            hosts: Travis::Worker.config[:hosts],
            paranoid: Travis::Worker.config[:paranoid],
            skip_resolv_updates: Travis::Worker.config[:skip_resolv_updates],
            skip_etc_hosts_fix: Travis::Worker.config[:skip_etc_hosts_fix],
            cache_options: Travis::Worker.config[:cache_options]
{'fraction_non_alphanumeric': 0.11114476075105996, 'fraction_numerical': 0.0024227740763173833, 'mean_word_length': 2.0442396313364055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7565662', 'n_tokens_mistral': 909, 'n_tokens_neox': 858, 'n_words': 187}