<commit_before>require 'set'
require 'pathname'

module Cbratest
  require_relative "cobratest/gemfile_scraper"
  require_relative "cobratest/affected_component_finder"
  require_relative "cobratest/transitive_affected_component_finder"
  require_relative "cobratest/tests_to_run_selector"

  class Runner
    def initialize(verbose_output)
      @verbose_output = verbose_output
    end

    def run(root_path)
      path = root_path || current_path
      app = GemfileScraper.new(path)

      outputs "All components"
      cobra_deps = app.transitive_cobra_dependencies.to_set
      components = cobra_deps << app.to_s
      outputs component_out(components.to_a)


      outputs "\nChanges since last commit"
      root_dir = `cd #{path} && git rev-parse --show-toplevel`.chomp
      changes = `cd #{root_dir} && git status -s -u`.split("\n").map { |file| File.join(root_dir, file.sub(/^.../, "")) }
      outputs changes


      outputs "\nDirectly affected components"
      affected = AffectedComponentFinder.new.find(components, changes)
      outputs affected_out(affected)

      outputs "\nTransitively affected components"
      all_affected = TransitiveAffectedComponentFinder.new.find(affected)
      outputs affected_out(all_affected)

      outputs "\nTest scripts to run"
      outputs all_in_need_of_running = TestsToRunSelector.new.list(all_affected), true
    end

    private

    def outputs(arg, even_non_verbose = false)
      output(arg) if even_non_verbose || @verbose_output
    end<commit_msg>Make cobra test work for dirs with spaces<commit_after>require 'set'
require 'pathname'

module Cbratest
  require_relative "cobratest/gemfile_scraper"
  require_relative "cobratest/affected_component_finder"
  require_relative "cobratest/transitive_affected_component_finder"
  require_relative "cobratest/tests_to_run_selector"

  class Runner
    def initialize(verbose_output)
      @verbose_output = verbose_output
    end

    def run(root_path)
      path = root_path || current_path
      app = GemfileScraper.new(path)

      outputs "All components"
      cobra_deps = app.transitive_cobra_dependencies.to_set
      components = cobra_deps << app.to_s
      outputs component_out(components.to_a)


      outputs "\nChanges since last commit"
      root_dir = `cd "#{path}" && git rev-parse --show-toplevel`.chomp
      changes = `cd "#{root_dir}" && git status -s -u`.split("\n").map { |file| File.join(root_dir, file.sub(/^.../, "")) }
      outputs changes


      outputs "\nDirectly affected components"
      affected = AffectedComponentFinder.new.find(components, changes)
      outputs affected_out(affected)

      outputs "\nTransitively affected components"
      all_affected = TransitiveAffectedComponentFinder.new.find(affected)
      outputs affected_out(all_affected)

      outputs "\nTest scripts to run"
      outputs all_in_need_of_running = TestsToRunSelector.new.list(all_affected), true
    end

    private

    def outputs(arg, even_non_verbose = false)
      output(arg) if even_non_verbose || @verbose_output
    end
{'fraction_non_alphanumeric': 0.08978529603122967, 'fraction_numerical': 0.0, 'mean_word_length': 3.7162576687116564, 'pattern_counts': {'":': 0, '<': 7, '<?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': '716474', 'n_tokens_mistral': 984, 'n_tokens_neox': 929, 'n_words': 202}