<commit_before>class CommitMonitorHandlers::CommitRange::RubocopChecker
  include Sidekiq::Worker
  sidekiq_options :queue => :miq_bot_glacial

  include BranchWorkerMixin

  def self.handled_branch_modes
    [:pr]
  end

  attr_reader :results, :github

  def perform(branch_id, _new_commits)
    return unless find_branch(branch_id, :pr)

    process_branch
  end

  private

  def process_branch
    unmerged_results = []
    unmerged_results << Linter::Rubocop.new(branch).run
    unmerged_results << Linter::Haml.new(branch).run
    unmerged_results.compact!
    if unmerged_results.empty?
      @results = {"files" => []}
    else
      results = merge_linter_results(*unmerged_results)
      @results = RubocopResultsFilter.new(results, diff_details).filtered
    end

    write_to_github
  rescue Rugged::IndexError
    # Failed to create merge index, no point in trying to lint files for an unmergable PR
  end

  def merge_linter_results(*results)
    return if results.empty?

    new_results = results[0].dup

    results[1..-1].each do |result|
      %w(offense_count target_file_count inspected_file_count).each do |m|
        new_results['summary'][m] += result['summary'][m]
      end
      new_results['files'] += result['files']
    end

    new_results
  end

  def rubocop_comments
    MessageBuilder.new(results, branch).comments
  end

  def write_to_github
    logger.info("Updating PR #{pr_number} with rubocop comment.")

    branch.repo.with_github_service do |github|
      @github = github
      replace_rubocop_comments
    end
  end

  def replace_rubocop_comments
    github.replace_issue_comments(pr_number, rubocop_comments) do |old_comment|
      rubocop_comment?(old_comment)
    end
  end

  def rubocop_comment?(comment)
    comment.body.start_with?("<rubocop />")
  end
end
<commit_msg>Diff details is still necessary for filtering comments<commit_after>class CommitMonitorHandlers::CommitRange::RubocopChecker
  include Sidekiq::Worker
  sidekiq_options :queue => :miq_bot_glacial

  include BranchWorkerMixin

  def self.handled_branch_modes
    [:pr]
  end

  attr_reader :results, :github

  def perform(branch_id, _new_commits)
    return unless find_branch(branch_id, :pr)

    process_branch
  end

  private

  def process_branch
    unmerged_results = []
    unmerged_results << Linter::Rubocop.new(branch).run
    unmerged_results << Linter::Haml.new(branch).run
    unmerged_results.compact!
    if unmerged_results.empty?
      @results = {"files" => []}
    else
      results      = merge_linter_results(*unmerged_results)
      diff_details = diff_details_for_merge
      @results     = RubocopResultsFilter.new(results, diff_details).filtered
    end

    write_to_github
  rescue Rugged::IndexError
    # Failed to create merge index, no point in trying to lint files for an unmergable PR
  end

  def merge_linter_results(*results)
    return if results.empty?

    new_results = results[0].dup

    results[1..-1].each do |result|
      %w(offense_count target_file_count inspected_file_count).each do |m|
        new_results['summary'][m] += result['summary'][m]
      end
      new_results['files'] += result['files']
    end

    new_results
  end

  def rubocop_comments
    MessageBuilder.new(results, branch).comments
  end

  def write_to_github
    logger.info("Updating PR #{pr_number} with rubocop comment.")

    branch.repo.with_github_service do |github|
      @github = github
      replace_rubocop_comments
    end
  end

  def replace_rubocop_comments
    github.replace_issue_comments(pr_number, rubocop_comments) do |old_comment|
      rubocop_comment?(old_comment)
    end
  end

  def rubocop_comment?(comment)
    comment.body.start_with?("<rubocop />")
  end
end

{'fraction_non_alphanumeric': 0.08792089791555319, 'fraction_numerical': 0.0016034206306787815, 'mean_word_length': 3.7141057934508814, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '3228307', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1190, 'n_words': 255}