<commit_before>class CommitMonitorHandlers::Commit::BugzillaCommentor
  include Sidekiq::Worker

  def self.handled_branch_modes
    [:regular]
  end

  delegate :product, :to => :CommitMonitor

  def perform(branch_id, commit, commit_details)
    branch = CommitMonitorBranch.where(:id => branch_id).first

    if branch.nil?
      logger.info("Branch #{branch_id} no longer exists.  Skipping.")
      return
    end
    if branch.pull_request?
      logger.info("Branch #{branch.name} is a pull request.  Skipping.")
      return
    end

    process_commit(branch, commit, commit_details["message"])
  end

  private

  def process_commit(branch, commit, message)
    prefix     = "New commit detected on #{branch.repo.name}/#{branch.name}:"
    commit_uri = branch.commit_uri_to(commit)
    comment    = "#{prefix}\n#{commit_uri}\n\n#{message}"

    message.each_line do |line|
      match = %r{^\s*https://bugzilla\.redhat\.com/show_bug\.cgi\?id=(?<bug_id>\d+)$}.match(line)
      write_to_bugzilla(match[:bug_id], comment) if match
    end
  end

  def write_to_bugzilla(bug_id, comment)
    log_prefix = "#{self.class.name}##{__method__}"
    logger.info("#{log_prefix} Updating bug id #{bug_id} in Bugzilla.")

    BugzillaService.call do |bz|
      output = bz.query(:product => product, :bug_id => bug_id).chomp
      if output.empty?
        logger.error "#{log_prefix} Unable to write for bug id #{bug_id}: Not a '#{product}' bug."
      else
        logger.info "#{log_prefix} Writing to bugzilla for bug id #{bug_id}"
        bz.modify(bug_id, :comment => comment)
      end
    end
  rescue => err
    logger.error "#{log_prefix} Unable to write for bug id #{bug_id}: #{err}"
  end
end
<commit_msg>Adjust BugzillaCommentor to match the other handlers.<commit_after>class CommitMonitorHandlers::Commit::BugzillaCommentor
  include Sidekiq::Worker

  def self.handled_branch_modes
    [:regular]
  end

  delegate :product, :to => :CommitMonitor

  attr_reader :branch, :commit, :message

  def perform(branch_id, commit, commit_details)
    @branch  = CommitMonitorBranch.where(:id => branch_id).first
    @commit  = commit
    @message = commit_details["message"]

    if @branch.nil?
      logger.info("Branch #{@branch_id} no longer exists.  Skipping.")
      return
    end
    if @branch.pull_request?
      logger.info("Branch #{@branch.name} is a pull request.  Skipping.")
      return
    end

    process_commit
  end

  private

  def process_commit
    prefix     = "New commit detected on #{branch.repo.name}/#{branch.name}:"
    commit_uri = branch.commit_uri_to(commit)
    comment    = "#{prefix}\n#{commit_uri}\n\n#{message}"

    message.each_line do |line|
      match = %r{^\s*https://bugzilla\.redhat\.com/show_bug\.cgi\?id=(?<bug_id>\d+)$}.match(line)
      write_to_bugzilla(match[:bug_id], comment) if match
    end
  end

  def write_to_bugzilla(bug_id, comment)
    log_prefix = "#{self.class.name}##{__method__}"
    logger.info("#{log_prefix} Updating bug id #{bug_id} in Bugzilla.")

    BugzillaService.call do |bz|
      output = bz.query(:product => product, :bug_id => bug_id).chomp
      if output.empty?
        logger.error "#{log_prefix} Unable to write for bug id #{bug_id}: Not a '#{product}' bug."
      else
        logger.info "#{log_prefix} Writing to bugzilla for bug id #{bug_id}"
        bz.modify(bug_id, :comment => comment)
      end
    end
  rescue => err
    logger.error "#{log_prefix} Unable to write for bug id #{bug_id}: #{err}"
  end
end

{'fraction_non_alphanumeric': 0.134226275292106, 'fraction_numerical': 0.0, 'mean_word_length': 3.360248447204969, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '4823216', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1150, 'n_words': 278}