-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpostToSlack.rb
51 lines (40 loc) · 1.34 KB
/
postToSlack.rb
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
#!/usr/bin/ruby
require 'net/http'
require 'json'
require 'uri'
def PostIt(slackTeam, slackChannel, ReportTitle, platform)
file = File.read('TestResults/TestRun.json')
data = JSON.parse(file);
output = "* " + ReportTitle + " for " + platform + " *\n-----------------------" + "\n*Duration:* " + data["summary"]["duration"].to_s + " seconds" + "\n*Tests Run:* " + data["summary"]["example_count"].to_s + "\n*Failures:* " + data["summary"]["failure_count"].to_s
data["examples"].each do |example|
if example["status"] == "failed"
output += "\n:no_entry_sign: " + example["full_description"]
end
if example["status"] == "passed"
output += "\n:white_check_mark: " + example["full_description"]
end
end
params = {
text: output,
channel: slackChannel,
username: "Automation Slack Integration",
icon_emoji: ":zap:",
mrkdown: true
}
uri = URI.parse("https://hooks.slack.com/services/" + slackTeam)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri)
request.body = params.to_json
res = http.request(request)
puts res.body
end
module Slack
module IOS
v1 = ARGV[0]
v2 = ARGV[1]
v3 = ARGV[2]
v4 = ARGV[3]
PostIt(v1, v2, v3, v4)
end
end