quintocumber 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e610f9d458216be13fbb2f93ac16aa505d4705be
4
- data.tar.gz: 3365c5045a3bac69b13296db6cfae8d398cb8ee9
3
+ metadata.gz: f286f29c0794ce5ba2c73c68f0ebc5affda82b35
4
+ data.tar.gz: 8638379409f533461b03352caac6df3617eff085
5
5
  SHA512:
6
- metadata.gz: 6253863357ceb3ea86bdc01dd1a84caa032ae96d595a242339e1bf861d8fd67880c8cc00a8185fb46a8d3f84ed9c77932577fb94241f3bc8a2bfb4aa95712860
7
- data.tar.gz: b9abac84ff2c64845cc60aa2ecc2edcfd2782f7577ad215df136f7bb8f7cff15a5ac00a4233a709f901a29a23cbff9ff227d0e3d2cec11c56c995c224318b9dc
6
+ metadata.gz: fa083be43ee100b8a291ae0b9c7fcde99741f0f690ad3b01884c5569f73afc18acef044c90203f95338e63dd14eaa64552cbe80dabff357c9de56c53433aa217
7
+ data.tar.gz: 81717c9ee1ac57df4405c6ff07a8034c5d2cc2d430602ac332d7089a36ee2e557a38e9c36b42ae9f3855f62c7fcebafa57f180090602fe5d50f7475a80074ded
data/.gitignore CHANGED
@@ -5,3 +5,7 @@ quintocumber-*.gem
5
5
  pkg/
6
6
  coverage
7
7
  .vscode/
8
+
9
+ # Bundler
10
+ vendor
11
+ .bundle
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'httparty'
4
4
  require 'aws-sdk'
5
+ require 'json'
5
6
 
6
7
  tests_failed = []
7
8
 
@@ -9,7 +10,7 @@ def pagerduty_payload(failed_length, reports_list_str)
9
10
  {
10
11
  payload: {
11
12
  summary: failed_length.to_s + " #{PROJECT_NAME} test(s) failed",
12
- source: "#{PROJECT_NAME}",
13
+ source: PROJECT_NAME.to_s,
13
14
  severity: 'critical',
14
15
  custom_details: "Failed test(s):\n- #{reports_list_str}"
15
16
  },
@@ -75,8 +76,60 @@ def report_to_pagerduty(report_url, tests_failed)
75
76
  body: payload.to_json
76
77
  end
77
78
 
79
+ def notify_slack(webhook_url, payload)
80
+ HTTParty.post webhook_url.to_s,
81
+ headers: { 'Content-Type' => 'application/json' },
82
+ body: payload.to_json
83
+ end
84
+
85
+ def slack_text(report_url, tests_failed)
86
+ txt = if tests_failed.empty?
87
+ 'Success! All tests passed.'
88
+ else
89
+ "Failure! There are #{tests_failed.length} failed tests: "\
90
+ "\n\t#{tests_failed.join("\n\t")}"\
91
+ end
92
+ txt
93
+ end
94
+
95
+ def slack_pretext(report_url)
96
+ pretext = if report_url
97
+ "Full report at #{report_url}"
98
+ else
99
+ 'Report was not published.'
100
+ end
101
+ pretext
102
+ end
103
+
104
+ def slack_color(tests_failed)
105
+ color = if tests_failed.empty?
106
+ 'good'
107
+ else
108
+ 'danger'
109
+ end
110
+ color
111
+ end
112
+
113
+ def slack_payload(report_url, tests_failed)
114
+ {
115
+ attachments: [
116
+ pretext: slack_pretext(report_url),
117
+ text: slack_text(report_url, tests_failed),
118
+ color: slack_color(tests_failed)
119
+ ]
120
+ }
121
+ end
122
+
123
+ def report_to_slack(report_url, tests_failed)
124
+ return unless ENV['SLACK_WEBHOOK_URL']
125
+ puts 'Sending test report link to Slack'
126
+ payload = slack_payload(report_url, tests_failed)
127
+ notify_slack(ENV['SLACK_WEBHOOK_URL'], payload)
128
+ end
129
+
78
130
  at_exit do
79
131
  report_url = generate_report_and_upload_to_s3
80
- puts "Report url: #{report_url}"
132
+ puts "Report url: #{report_url}" if report_url
133
+ report_to_slack(report_url, tests_failed)
81
134
  report_to_pagerduty(report_url, tests_failed)
82
135
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Quintocumber
4
- VERSION = '1.1.4'
4
+ VERSION = '1.1.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quintocumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Queiroz