<commit_before>class SimpleMailer < ActionMailer::Base
  default :from => "Circle Builds <<EMAIL>>"
  include ApplicationHelper
  helper :application

  # Sends an email for a build:
  # - work out who should be emailed based on their preferences
  # - decide what type of email (depends on the branch, previous success)
  # - email them
  def build_email(build_id)

    @build = Build.find(build_id)
    @project = @build.the_project
    @users = @project.users.select {|u| u.sent_first_build_email}
    @emails = @users.map { |u| u.email }.find_all { |e| e.include? "@" }

    # Don't fail when clojure tests have no users
    if Rails.env.test? && @emails == []
      @emails = "<EMAIL>"
    end

    if Rails.env.production? && !@project.visible
      @emails = "<EMAIL>"
    end

    subject = "[#{@project.github_project_name}] Test #{@build.build_num} #{@build.failed ? "failed" : "succeeded"}"

    if @emails.count > 0
      if @build.failed
        @logs = @build.logs
        @failing_log = @logs.last
        @other_logs = @logs[0..-2]
        if @failing_log and @failing_log.success?
          logger.error "Failing log didn't fail: #{@failing_log.to_s}"
        end
        mail(:to => @emails, :subject => subject, :template_name => "fail").deliver
      else
        mail(:to => [], :subject => subject, :template_name => "success").deliver
      end
    end
  end

  # send the first email to user, if necessary
  def maybe_send_first_email (user)
    if not user.send_first_build_email and user.build_in_every_project?
      send_first_email(user)
    end
  end

  def send_first_email(user)
    @projects = user.projects

    mail(:to => user.email,
         :subject => "All your projects have built",
         :template_name => "first_build").deliver
    user.sent_first_build_email = true
    user.save!
  end

  def build_error_email(build_id, error)
    @build = Build.find(build_id)
    @error = error.to_s
    mail(:to => "<EMAIL>",
         :subject => "#{Rails.env}: build exception").deliver
  end
<commit_msg>Don't pay attention to the send first build email flag yet. Fix a stupid bug preventing some email from sending.<commit_after>class SimpleMailer < ActionMailer::Base
  default :from => "Circle Builds <<EMAIL>>"
  include ApplicationHelper
  helper :application

  # Sends an email for a build:
  # - work out who should be emailed based on their preferences
  # - decide what type of email (depends on the branch, previous success)
  # - email them
  def build_email(build_id)

    @build = Build.find(build_id)
    @project = @build.the_project
    @users = @project.users# .select {|u| u.sent_first_build_email}
    @emails = @users.map { |u| u.email }.find_all { |e| e.include? "@" }

    # Don't fail when clojure tests have no users
    if Rails.env.test? && @emails == []
      @emails = "<EMAIL>"
    end

    if Rails.env.production? && !@project.visible
      @emails = "<EMAIL>"
    end

    subject = "[#{@project.github_project_name}] Test #{@build.build_num} #{@build.failed ? "failed" : "succeeded"}"

    if @emails.length > 0
      if @build.failed
        @logs = @build.logs
        @failing_log = @logs.last
        @other_logs = @logs[0..-2]
        if @failing_log and @failing_log.success?
          logger.error "Failing log didn't fail: #{@failing_log.to_s}"
        end
        mail(:to => @emails, :subject => subject, :template_name => "fail").deliver
      else
        mail(:to => @emails, :subject => subject, :template_name => "success").deliver
      end
    end
  end

  # send the first email to user, if necessary
  def maybe_send_first_email (user)
    if not user.send_first_build_email and user.build_in_every_project?
      send_first_email(user)
    end
  end

  def send_first_email(user)
    @projects = user.projects

    mail(:to => user.email,
         :subject => "All your projects have built",
         :template_name => "first_build").deliver
    user.sent_first_build_email = true
    user.save!
  end

  def build_error_email(build_id, error)
    @build = Build.find(build_id)
    @error = error.to_s
    mail(:to => "<EMAIL>",
         :subject => "#{Rails.env}: build exception").deliver
  end

{'fraction_non_alphanumeric': 0.12682111296871268, 'fraction_numerical': 0.0014330069262001434, 'mean_word_length': 2.947219604147031, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, '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': '2984718', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1353, 'n_words': 367}