<commit_before>require 'ostruct'

module Poper
  class Runner
    def initialize(commit, repo_path = '.')
      @repo = Rugged::Repository.new(repo_path)
      @commit = @repo.lookup(commit)
    end

    def run
      commits.map { |c| check(c) }
             .flatten
             .compact
    end

    private

    def check(commit)
      rules.map do |rule|
        result = rule.check(commit.message)
        OpenStruct.new(commit: commit.oid, message: result) if result
      end
    end

    def rules
      Rule::Rule.all.map { |rule| rule.new }
    end

    def commits
      @commits ||= begin
        walker.reset
        walker.push(@repo.last_commit)
        walker.take_while { |c| c.oid != @commit.oid } << @commit
      end
    end

    def walker<commit_msg>Allow specifying refs (like 'HEAD~3') as commit parameters<commit_after>require 'ostruct'

module Poper
  class Runner
    def initialize(commit, repo_path = '.')
      @repo = Rugged::Repository.new(repo_path)
      merge_base = @repo.merge_base(commit, commit) # hack to make refs work
      @commit = @repo.lookup(merge_base)
    end

    def run
      commits.map { |c| check(c) }
             .flatten
             .compact
    end

    private

    def check(commit)
      rules.map do |rule|
        result = rule.check(commit.message)
        OpenStruct.new(commit: commit.oid, message: result) if result
      end
    end

    def rules
      Rule::Rule.all.map { |rule| rule.new }
    end

    def commits
      @commits ||= begin
        walker.reset
        walker.push(@repo.last_commit)
        walker.take_while { |c| c.oid != @commit.oid } << @commit
      end
    end

    def walker
{'fraction_non_alphanumeric': 0.1063321385902031, 'fraction_numerical': 0.0005973715651135006, 'mean_word_length': 2.0399274047186933, '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': '7277556', 'n_tokens_mistral': 545, 'n_tokens_neox': 523, 'n_words': 132}