<commit_before>require 'English'
require 'find'
require 'thread'
require 'yaml'

module Downstreams
  class Detector
    def initialize(cookbooks_path, packer_templates_path)
      @cookbooks_path = cookbooks_path
      @packer_templates_path = packer_templates_path
    end

    def detect(filenames)
      # * walk the @packer_templates_path, get list of packer templates
      # * for each packer template, if it contains a chef-solo provisioner,
      #   read the members of the run_list
      # * for each member of the run_list, evaluate/read the relevant
      #   recipe, looking for `include_recipe`.
      # * follow the `include_recipe` bits until (condition??)
      # * if a git commit path is inside a found cookbook, then append
      #   the affected template to a list (which is returned later)
      to_trigger = []
      filenames.map! { |f| f.gsub(%r{^[./]+}, '') }

      packer_templates.each do |template, run_list_cookbooks|
        run_list_cookbooks.each do |cb|
          cb_files = Array(cookbooks.files(cb))
          next if cb_files.empty?
          to_trigger << template unless (filenames & cb_files).empty?
        end
      end

      to_trigger
    end

    private

    attr_reader :cookbooks_path, :packer_templates_path

    def packer_templates
      @packer_templates ||= PackerTemplates.load(
        cookbooks_path, packer_templates_path
      )
    end

    def cookbooks
      @cookbooks ||= Cookbooks.load(cookbooks_path)
    end
  end
end

exit(LilChef.hacketytest!) if $PROGRAM_NAME == __FILE__<commit_msg>Remove old busted line whoopsie<commit_after>require 'English'
require 'find'
require 'thread'
require 'yaml'

module Downstreams
  class Detector
    def initialize(cookbooks_path, packer_templates_path)
      @cookbooks_path = cookbooks_path
      @packer_templates_path = packer_templates_path
    end

    def detect(filenames)
      # * walk the @packer_templates_path, get list of packer templates
      # * for each packer template, if it contains a chef-solo provisioner,
      #   read the members of the run_list
      # * for each member of the run_list, evaluate/read the relevant
      #   recipe, looking for `include_recipe`.
      # * follow the `include_recipe` bits until (condition??)
      # * if a git commit path is inside a found cookbook, then append
      #   the affected template to a list (which is returned later)
      to_trigger = []
      filenames.map! { |f| f.gsub(%r{^[./]+}, '') }

      packer_templates.each do |template, run_list_cookbooks|
        run_list_cookbooks.each do |cb|
          cb_files = Array(cookbooks.files(cb))
          next if cb_files.empty?
          to_trigger << template unless (filenames & cb_files).empty?
        end
      end

      to_trigger
    end

    private

    attr_reader :cookbooks_path, :packer_templates_path

    def packer_templates
      @packer_templates ||= PackerTemplates.load(
        cookbooks_path, packer_templates_path
      )
    end

    def cookbooks
      @cookbooks ||= Cookbooks.load(cookbooks_path)
    end
  end
end
{'fraction_non_alphanumeric': 0.07847606642787365, 'fraction_numerical': 0.0, 'mean_word_length': 2.8886075949367087, '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': '4483009', 'n_tokens_mistral': 945, 'n_tokens_neox': 929, 'n_words': 267}