Class: EmailNotification

Inherits:
Notification show all
Defined in:
lib/kwala/notifications/email.rb

Instance Method Summary collapse

Methods inherited from Notification

add_notification, context, context=, notifications, notify, #notify, #undefined_event

Instance Method Details

#unit_test(result, data, context) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kwala/notifications/email.rb', line 5

def unit_test(result, data, context)
  # TODO: Probably should move this to a configuration based
  from_addr = ""
  to_addr = [ "" ]
  smtp_server = ""
  smtp_port = 25

  # Get the time and set the status msg
  now = Time.now
  status_msg = "Unit tests run #{result.to_s} at"

  # just file name for now
  data ||= {}
  data = Array(data[:filtered_results]).map do |d|
    d[:file_name]
  end

  if !data.empty?
    failure_msg = <<-MSG
Test files that reported failures:
#{data.join("\n")}
MSG
  else
    failure_msg = ''
  end

  # Create the SMTP envelope
  msgstr = <<-END_OF_MESSAGE
From: Kwala Continuous Integration <EMAIL>
To: Edge Dev Mailing List <EMAIL>
Subject: [Kwala] edge build #{context.vcs_num} #{result}
Date: #{now.strftime("%a, %d %b %Y %X +0900")}
Message-Id: <#{now.strftime("%m%d%Y%H%M%S")}@EMAIL>

Result Summary:  #{result.to_s}
See Results at https://BASEURL/kwala/

#{failure_msg}

Commit Info:
#{context.vcs_info}
  END_OF_MESSAGE

  # Send the message
  Net::SMTP.start(smtp_server, smtp_port) do |smtp|
    smtp.send_message(msgstr, from_addr, *to_addr)
  end
end