<commit_before>class Event < ActiveRecord::Base
  belongs_to :heritage

  validates :uuid, uniqueness: true, presence: true
  validates :heritage, presence: true
  validates :level, inclusion: { in: %w(good warn error)}

  after_initialize :set_uuid
  before_validation :set_level
  after_create :send_notifications

  def set_uuid
    self.uuid ||= SecureRandom.uuid
  end

  def set_level
    self.level ||= "good"
    self.level = self.level.to_s
  end

  def send_notifications
    Rails.logger.info(user_message)
    return if heritage.slack_url.blank?
    notifier = Slack::Notifier.new(heritage.slack_url, username: "Barcelona")
    notifier.ping("", attachments: [{color: slack_color, text: user_message}])
  end

  def slack_color
    { "good"  => "good",
      "warn"  => "warning",
      "error" => "danger" }[level]
  end

  def user_message
    "[#{heritage.name}] #{message}"
  end
end
<commit_msg>Send notification when event is created<commit_after>class Event < ActiveRecord::Base
  belongs_to :heritage

  validates :uuid, uniqueness: true, presence: true
  validates :heritage, presence: true
  validates :level, inclusion: { in: %w(good warn error)}

  after_initialize :set_uuid
  before_validation :set_level
  after_create :send_notifications

  def set_uuid
    self.uuid ||= SecureRandom.uuid
  end

  def set_level
    self.level ||= "good"
    self.level = self.level.to_s
  end

  def send_notifications
    Rails.logger.info(user_message)
    heritage.district.publish_sns(user_message, level: slack_color)

    # TODO Remove these lines after we setup notifcation topic in our districts
    return if heritage.slack_url.blank?
    notifier = Slack::Notifier.new(heritage.slack_url, username: "Barcelona")
    notifier.ping("", attachments: [{color: slack_color, text: user_message}])
  end

  def slack_color
    { "good"  => "good",
      "warn"  => "warning",
      "error" => "danger" }[level]
  end

  def user_message
    "[#{heritage.name}] #{message}"
  end
end

{'fraction_non_alphanumeric': 0.11255627813906953, 'fraction_numerical': 0.0, 'mean_word_length': 3.8899755501222493, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6675277', 'n_tokens_mistral': 678, 'n_tokens_neox': 650, 'n_words': 166}