<commit_before>module Houston
  module Alerts
    class Alert < ActiveRecord::Base
      include Houston::Props

      attr_accessor :updated_by

      self.table_name = "alerts"
      self.inheritance_column = nil

      belongs_to :project, class_name: "::Project"
      belongs_to :checked_out_by, class_name: "::User"
      has_and_belongs_to_many :commits, class_name: "::Commit"
      has_many :pull_requests, through: :commits, class_name: "Github::PullRequest"

      after_initialize { self.opened_at ||= Time.now }

      default_scope { unsuppressed.where(destroyed_at: nil).order(:deadline) }

      validates :type, :key, :summary, :url, :opened_at, :number, presence: true
      validates :priority, presence: true, inclusion: {:in => %w{high urgent}}

      before_save :update_checked_out_by, :if => :checked_out_by_email_changed?
      before_save :update_project, :if => :project_slug_changed?
      before_save :update_deadline, :if => :opened_at_or_priority_changed?

      after_create do
        Houston.observer.fire "alert:create", alert: self
        Houston.observer.fire "alert:#{type}:create", alert: self
      end

      after_update do<commit_msg>[skip] Made Alert#project and Alert#checked_out_by optional (1m)<commit_after>module Houston
  module Alerts
    class Alert < ActiveRecord::Base
      include Houston::Props

      attr_accessor :updated_by

      self.table_name = "alerts"
      self.inheritance_column = nil

      belongs_to :project, class_name: "::Project", optional: true
      belongs_to :checked_out_by, class_name: "::User", optional: true
      has_and_belongs_to_many :commits, class_name: "::Commit"
      has_many :pull_requests, through: :commits, class_name: "Github::PullRequest"

      after_initialize { self.opened_at ||= Time.now }

      default_scope { unsuppressed.where(destroyed_at: nil).order(:deadline) }

      validates :type, :key, :summary, :url, :opened_at, :number, presence: true
      validates :priority, presence: true, inclusion: {:in => %w{high urgent}}

      before_save :update_checked_out_by, :if => :checked_out_by_email_changed?
      before_save :update_project, :if => :project_slug_changed?
      before_save :update_deadline, :if => :opened_at_or_priority_changed?

      after_create do
        Houston.observer.fire "alert:create", alert: self
        Houston.observer.fire "alert:#{type}:create", alert: self
      end

      after_update do
{'fraction_non_alphanumeric': 0.1090610906109061, 'fraction_numerical': 0.0004100041000410004, 'mean_word_length': 3.949290060851927, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 11, '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': '649894', 'n_tokens_mistral': 784, 'n_tokens_neox': 753, 'n_words': 171}