-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail_status.rb
More file actions
executable file
·114 lines (98 loc) · 4.45 KB
/
mail_status.rb
File metadata and controls
executable file
·114 lines (98 loc) · 4.45 KB
1
2
3
4
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env ruby
require_relative 'xcs-base'
require 'mail'
FROM = "admin@iceiosbuild.redmond.corp.microsoft.com"
if ARGV.length < 3
puts "Usage: ./mail_build_status.rb <bot_guid> <to_email> <cc_email>"
exit
end
bot_guid = ARGV[0]
to = ARGV[1].gsub(/"/, '').gsub(/,/, ';')
cc = ARGV[2].gsub(/"/, '').gsub(/,/, ';')
Mail.defaults do
delivery_method :sendmail
end
botrun = Bot.new(bot_guid).botrun
if botrun
build_output = botrun.extendedAttributes.output.build
name = botrun.extendedAttributes.botSnapshot.longName.sstrip
error = build_output.ErrorSummaries
warning = build_output.WarningSummaries
issue = build_output.AnalyzerWarningSummaries
error_cnt = build_output.ErrorCount
warning_cnt = build_output.WarningCount
issue_cnt = build_output.AnalyzerWarningCount
archive_path = build_output.ArchivePath
is_running = build_output.Running
commits = botrun.scmCommitGUIDs
printf "Error: %i, warning: %i, issue: %i\n", error_cnt, warning_cnt, issue_cnt
unless error_cnt == 0 and warning_cnt == 0 and issue_cnt == 0
puts "Preparing email"
inline_summary = Array.new
inline_summary.push "#{error_cnt} errors" if error_cnt > 0
inline_summary.push "#{warning_cnt} warnings" if warning_cnt > 0
inline_summary.push "#{issue_cnt} issues" if issue_cnt > 0
subject = "#{name.split.first} build status: #{inline_summary.join(', ')}"
body = Array.new
summary_table = Array.new
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Name", name
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Integration", botrun.integration
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Status", botrun.status
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Substatus", botrun.subStatus
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Execution time", execution_time(botrun.startTime, botrun.endTime)
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Error count", error_cnt
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Warning count", warning_cnt
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Analysis issues", issue_cnt
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Test count", build_output.TestsCount
summary_table.push sprintf "<tr><td>%s </td><td>%s</td></tr>", "Test failures", build_output.TestsFailedCount
summary_table = sprintf "<table>%s</table>", summary_table.join
body.push "#{name} has been built. Below are errors, warnings, and issues encountered during the build"
body.push "<h1>Summary</h1>"
body.push summary_table
body.push "<h1>Details</h1>"
if error
body.push "<h2>Errors</h2>"
error.each do |error|
body.push sprintf " <i>%s (%s)</i>: %s\n", error.IssueType, error.Target, error.Message
end
end
if warning
body.push "<h2>Warnings</h2>"
warning.each do |error|
body.push sprintf " <i>%s (%s)</i>: %s\n", error.IssueType, error.Target, error.Message
end
end
if issue
body.push "<h2>Analysis Issues</h2>"
issue.each do |error|
body.push sprintf " <i>%s (%s)</i>: %s\n", error.IssueType, error.Target, error.Message
end
end
unless commits.nil? or commits.empty?
body.push "<h1>Commits</h1>"
commit_table = Array.new
commit_table.push "<table>"
commits.each do |commit|
commit_rsp = get_entity(commit.to_h)
commit_table.push "<tr><td>#{commit_rsp.commitID[-7..-1]}</td><td>#{commit_rsp.message}</td></tr>"
end
commit_table.push "</table>"
body.push commit_table.join
end
Mail.deliver do
from FROM
to to
cc cc
subject subject
html_part do
content_type 'text/html; charset=UTF=8'
#body body.map { |l| if l.match />$/ then l + "<br>" else l end }.join
body body.join "<br>"
end
end
#puts "Mail delievered to #{info["to"]}, cc #{info["cc"]}"
puts "Mail delievered"
end
else
puts "Bot run not found"
end