<commit_before>module Buildbox
  class Build
    attr_reader :uuid

    def initialize(options)
      @uuid       = options[:uuid]
      @repository = options[:repository]
      @commit     = options[:commit]
      @config     = options[:config]
    end

    def start(&block)
      @block   = block

      unless build_path.exist?
        setup_build_path
        clone_repository
      end

      fetch_and_checkout
      build

      true
    end

    private

    def setup_build_path
      run %{mkdir -p "#{build_path}"}
    end

    def clone_repository
      run %{git clone "#{@repository}" .}
    end

    def fetch_and_checkout
      run %{git clean -fd}
      run %{git fetch -v}
      run %{git checkout -qf "#{@commit}"}
    end

    def build
      @config[:build][:commands].each { |command| run command }
    end

    def folder_name
      @repository.gsub(/[^a-zA-Z0-9]/, '-')
    end

    def build_path
      Buildbox.root_path.join folder_name
    end

    def run(command)
      path = build_path if build_path.exist?

      result = Buildbox::Command.new(path).run(command) do |result, chunk|
        @block.call(result)
      end

      @block.call(result)
<commit_msg>Be more quiter in the initial build.<commit_after>module Buildbox
  class Build
    attr_reader :uuid

    def initialize(options)
      @uuid       = options[:uuid]
      @repository = options[:repository]
      @commit     = options[:commit]
      @config     = options[:config]
    end

    def start(&block)
      @block   = block

      unless build_path.exist?
        setup_build_path
        clone_repository
      end

      fetch_and_checkout
      build

      true
    end

    private

    def setup_build_path
      run %{mkdir -p "#{build_path}"}
    end

    def clone_repository
      run %{git clone "#{@repository}" . -q}
    end

    def fetch_and_checkout
      run %{git clean -fd}
      run %{git fetch}
      run %{git checkout -qf "#{@commit}"}
    end

    def build
      @config[:build][:commands].each { |command| run command }
    end

    def folder_name
      @repository.gsub(/[^a-zA-Z0-9]/, '-')
    end

    def build_path
      Buildbox.root_path.join folder_name
    end

    def run(command)
      path = build_path if build_path.exist?

      result = Buildbox::Command.new(path).run(command) do |result, chunk|
        @block.call(result)
      end

      @block.call(result)

{'fraction_non_alphanumeric': 0.1041926110419261, 'fraction_numerical': 0.0016604400166044002, 'mean_word_length': 2.0739795918367347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2843052', 'n_tokens_mistral': 784, 'n_tokens_neox': 735, 'n_words': 188}