<commit_before>Handlebars = require 'handlebars'

module.exports = class Alert
  constructor: (@config) ->
    # Support separate templates for events and metric events
    {template, metricTemplate} = @config
    @template = Handlebars.compile template if template
    @metricTemplate = Handlebars.compile metricTemplate if metricTemplate

  defaultEvent: (event) ->
    eventString = [
      "Event alert for #{event.name}!"
      "```#{JSON.stringify event}```"
    ].join '\n'

  renderEvent: (event) ->
    return unless @template

    @template event

  formatEvent: (event) ->
    @renderEvent(event) or @defaultEvent event

  sendEvent: (event) ->
    eventString = @renderEvent event
    console.log eventString or event

  defaultMetricsEvent: (event) ->
    eventString = [
      "Metrics alert for #{event.name}!"
      "```#{JSON.stringify event}```"
    ].join '\n'

  renderMetricsEvent: (event) ->
    return unless @metricTemplate

    @metricTemplate event

  formatMetricsEvent: (event) ->
    @renderMetricsEvent(event) or @defaultMetricsEvent event

  sendMetricsEvent: (event) ->
    eventString = @renderMetricsEvent event
    console.log eventString or event<commit_msg>Using helpers in base class as well<commit_after>Handlebars = require 'handlebars'

module.exports = class Alert
  constructor: (@config) ->
    # Support separate templates for events and metric events
    {template, metricTemplate} = @config
    @template = Handlebars.compile template if template
    @metricTemplate = Handlebars.compile metricTemplate if metricTemplate

  defaultEvent: (event) ->
    eventString = [
      "Event alert for #{event.name}!"
      "```#{JSON.stringify event}```"
    ].join '\n'

  renderEvent: (event) ->
    return unless @template

    @template event

  formatEvent: (event) ->
    @renderEvent(event) or @defaultEvent event

  sendEvent: (event) ->
    console.log @formatEvent event

  defaultMetricsEvent: (event) ->
    eventString = [
      "Metrics alert for #{event.name}!"
      "```#{JSON.stringify event}```"
    ].join '\n'

  renderMetricsEvent: (event) ->
    return unless @metricTemplate

    @metricTemplate event

  formatMetricsEvent: (event) ->
    @renderMetricsEvent(event) or @defaultMetricsEvent event

  sendMetricsEvent: (event) ->
    console.log @formatMetricsEvent event
{'fraction_non_alphanumeric': 0.11578044596912522, 'fraction_numerical': 0.0, 'mean_word_length': 3.54775828460039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5360486', 'n_tokens_mistral': 656, 'n_tokens_neox': 633, 'n_words': 187}