<commit_before>require 'travis/addons/handlers/base'
require 'travis/addons/handlers/notifier'
require 'travis/addons/model/broadcast'

module Travis
  module Addons
    module Handlers
      class Email < Notifiers
        EVENTS = 'build:finished'
        KEY = :email

        class Notifier < Notifier
          def handle?
            Travis::Addons.logger.send(:info, "Email<Notifiers: #{recipients.to_s}")
            puts("Email<Notifiers: #{recipients.to_s}")
            !pull_request? && config.enabled? && config.send_on?(:email, action) && recipients.present?
          end

          def handle
            run_task(:email, payload, recipients: recipients, broadcasts: broadcasts)
          end

          def recipients
            @recipients ||= begin
              emails = configured_emails || default_emails
              emails -= unsubscribed_emails
              emails - ::Email.joins(:user).where(email: emails).merge(User.with_preference(:build_emails, false)).pluck(:email).uniq
            end
          end

          private

            def configured_emails
              emails = config.values(:recipients)
              emails.try(:any?) && emails
            end

            def default_emails
              emails = [commit.author_email, commit.committer_email]
              user_ids = object.repository.permissions.pluck(:user_id)
              ::Email.where(email: emails, user_id: user_ids).pluck(:email).uniq
            end

            def unsubscribed_emails
              user_ids = object.repository.email_unsubscribes.pluck(:user_id)<commit_msg>more debug info<commit_after>require 'travis/addons/handlers/base'
require 'travis/addons/handlers/notifier'
require 'travis/addons/model/broadcast'

module Travis
  module Addons
    module Handlers
      class Email < Notifiers
        EVENTS = 'build:finished'
        KEY = :email

        class Notifier < Notifier
          def handle?
            Travis::Addons.logger.send(:info, "Email < Notifiers - recipients: #{recipients.to_s}")
            Travis::Addons.logger.send(:info, "Email < Notifiers - config: #{config.to_s}")
            !pull_request? && config.enabled? && config.send_on?(:email, action) && recipients.present?
          end

          def handle
            run_task(:email, payload, recipients: recipients, broadcasts: broadcasts)
          end

          def recipients
            @recipients ||= begin
              emails = configured_emails || default_emails
              emails -= unsubscribed_emails
              emails - ::Email.joins(:user).where(email: emails).merge(User.with_preference(:build_emails, false)).pluck(:email).uniq
            end
          end

          private

            def configured_emails
              emails = config.values(:recipients)
              emails.try(:any?) && emails
            end

            def default_emails
              emails = [commit.author_email, commit.committer_email]
              user_ids = object.repository.permissions.pluck(:user_id)
              ::Email.where(email: emails, user_id: user_ids).pluck(:email).uniq
            end

            def unsubscribed_emails
              user_ids = object.repository.email_unsubscribes.pluck(:user_id)
{'fraction_non_alphanumeric': 0.0994133991972831, 'fraction_numerical': 0.0, 'mean_word_length': 2.13953488372093, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6628027', 'n_tokens_mistral': 903, 'n_tokens_neox': 891, 'n_words': 172}