<commit_before>NotificationPlugin = require "../../notification-plugin"

class PagerDuty extends NotificationPlugin
  stacktraceLines = (stacktrace) ->
    ("#{line.file}:#{line.lineNumber} - #{line.method}" for line in stacktrace when line.inProject)      

  pagerDutyDescription = (event) ->
    """
    #{event.trigger.message}</b> in #{event.project.name}

    #{event.error.exceptionClass} in #{event.error.context}
    #{event.error.message if event.error.message}

    View on bugsnag.com: #{event.error.url}

    #{stacktraceLines(event.error.stacktrace).join("\n")}

    View full stacktrace: #{event.error.url}

    """

  @receiveEvent: (config, event, callback) ->
    payload =
      service_key: config.serviceKey
      event_type: 'trigger'
      incident_key: event.error.url
      description: pagerDutyDescription(event)<commit_msg>change to structured data to pagerduty<commit_after>NotificationPlugin = require "../../notification-plugin"

class PagerDuty extends NotificationPlugin
  stacktraceLines = (stacktrace) ->
    ("#{line.file}:#{line.lineNumber} - #{line.method}" for line in stacktrace when line.inProject)      

  metaDataLines = (metaData) ->
    ("  * #{k} - #{v}" for k,v of metaData)      


  pagerDutyDetails = (event) ->
    details = 
      message : event.trigger.message
      project : event.project.name
      class : event.error.exceptionClass
      url : event.error.url
      stackTrace : stacktraceLines(event.error.stacktrace)
      metaData : event.error.metaData    
    details

  @receiveEvent: (config, event, callback) ->
    payload =
      service_key: config.serviceKey
      event_type: 'trigger'
      incident_key: event.error.url
      description: "#{event.error.exceptionClass} in #{event.error.context}"
      details: pagerDutyDetails(event)
{'fraction_non_alphanumeric': 0.13149171270718232, 'fraction_numerical': 0.0, 'mean_word_length': 3.3221957040572794, 'pattern_counts': {'":': 0, '<': 4, '<?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': '3720673', 'n_tokens_mistral': 542, 'n_tokens_neox': 533, 'n_words': 112}