chat_notifier 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11bbd1390ca03c1f99d0ff66a5e3a361f259f40704575db73ae255e67e48b94b
4
- data.tar.gz: 24781a89995cf1384962fb46b5a60d8ed5095e442af92162a85e5e82489007ee
3
+ metadata.gz: 622357edb937d16bc4374115ad8d67e022fca33fee0544106af820797848fe17
4
+ data.tar.gz: 15d105331090d2dc981d56dd4a598040dab9ba392fb66c496469c851df06bac8
5
5
  SHA512:
6
- metadata.gz: a2584238466e94fc1efba40198f83761464f6bf399b9e99b8b640eb21a074a13699fe18bb42a4c1be049e1d0ccdb5950d721ce1342c04f1bfbc277f4195be189
7
- data.tar.gz: f6e4ac759352ba03f7a21a283f3e43eb4202f0fad8ddd7125b1024713fe96bdac3b283a9bc3f5555495005c96bc92b5438307f55cf1b318556b79674c7143f32
6
+ metadata.gz: 74bb8fd9d9fded6a20097d8bdc04bd1f6178f61ec28ffb191579f73833f8eeaadbd6012034abea92f23db803db23d963d3a0e96b007f14883d7304eaa76d98fa
7
+ data.tar.gz: c87f9c544e476ba0f5afe182cb1f729a7687fea615fff51398ec288b1b85a7779cfa3d2b7e988298af28ba3c09b3de7506ea1374add5e665d8afe90d39522500
data/CHANGELOG.md CHANGED
@@ -5,8 +5,24 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## 0.1.0
8
+ ## [0.2.1] - 2024-07-01
9
9
 
10
10
  ### Added
11
11
 
12
- - Initial code
12
+ - Version and release management with reissue gem.
13
+
14
+ ### Changed
15
+
16
+ - Slack chatter looks for NOTIFY_SLACK ENV variables instead of just SLACK
17
+
18
+ ## [0.2.0] - 2023-04-24
19
+
20
+ ### Changed
21
+
22
+ - Renamed ENV variables to prefix `NOTIFY_`
23
+
24
+ ## [0.1.0] - 2023-04-19
25
+
26
+ ### Added
27
+
28
+ - Initial code
data/README.md CHANGED
@@ -4,16 +4,51 @@ Notify a chat room with data from your test run.
4
4
 
5
5
  ## Installation
6
6
 
7
- ```
7
+ ```ruby
8
8
  gem "chat_notifier", git: "https://github.com/SOFware/chat_notifier.git"
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
+ ### Minitest
14
+
15
+ Your minitest suite should pick up the formatter automatically.
16
+
17
+ ### RSpec
18
+
13
19
  Add to your `spec_helper.rb` or `rails_helper.rb`:
14
20
 
15
- ```
21
+ ```ruby
16
22
  require "chat_notifier/rspec_formatter"
23
+
24
+ config.add_formatter "ChatNotifier::RspecFormatter" if ENV["CI"]
25
+ ```
26
+
27
+ Add to your config/application.rb within your namespaced module
28
+
29
+ ```ruby
30
+ def self.sha
31
+ `git rev-parse --short HEAD`.chomp
32
+ end
33
+
34
+ def self.branch
35
+ `git branch --show-current`.chomp
36
+ end
37
+ ```
38
+
39
+ Add these variables to your env files
40
+
41
+ ```
42
+ NOTIFY_SLACK_WEBHOOK_URL
43
+ NOTIFY_SLACK_NOTIFY_CHANNEL
44
+ NOTIFY_CURRENT_REPOSITORY_URL
45
+ NOTIFY_TEST_RUN_ID
46
+ ```
47
+
48
+ If you are _not_ using Rails, you will need to add this ENV variable:
49
+
50
+ ```
51
+ NOTIFY_APP_NAME
17
52
  ```
18
53
 
19
54
  ### Debug your Slack setup
@@ -22,14 +57,16 @@ Create rake task to test the connection to your Slack channel
22
57
 
23
58
  ```ruby
24
59
  namespace :chat_notifier do
60
+ desc "Tests chat notifier"
25
61
  task debug: :environment do
26
- unless ENV["SLACK_WEBHOOK_URL"]
27
- puts "You MUST set the environment variables for:\nSLACK_WEBHOOK_URL"
62
+ unless ENV["NOTIFY_SLACK_WEBHOOK_URL"]
63
+ puts "You MUST set the environment variables for:\nNOTIFY_SLACK_WEBHOOK_URL"
28
64
  return
29
65
  end
30
66
  ENV["DEBUG"] = "1"
31
- ENV["CURRENT_REPOSITORY_URL"] = "https://example.com"
32
- ENV["TEST_RUN_ID"] = "9999"
67
+ ENV["NOTIFY_CURRENT_REPOSITORY_URL"] = "https://example.com"
68
+ ENV["NOTIFY_TEST_RUN_ID"] = "9999"
69
+ ENV["NOTIFY_APP_NAME"] = "Example App" # Defaults to your Rails app name
33
70
  require "chat_notifier"
34
71
 
35
72
  failure = ChatNotifier::DebugExceptionLocation.new(location: "fake/path.rb")
@@ -7,16 +7,16 @@ module ChatNotifier
7
7
 
8
8
  class << self
9
9
  def handles?(settings)
10
- !settings.keys.grep(/SLACK/).empty?
10
+ !settings.keys.grep(/NOTIFY_SLACK/).empty?
11
11
  end
12
12
  end
13
13
 
14
14
  def webhook_url
15
- settings.fetch("SLACK_WEBHOOK_URL", nil)
15
+ settings.fetch("NOTIFY_SLACK_WEBHOOK_URL", nil)
16
16
  end
17
17
 
18
18
  def channel
19
- settings.fetch("SLACK_NOTIFY_CHANNEL", nil)
19
+ settings.fetch("NOTIFY_SLACK_NOTIFY_CHANNEL", nil)
20
20
  end
21
21
 
22
22
  def payload(data)
@@ -4,7 +4,7 @@ module ChatNotifier
4
4
  class Repository
5
5
  class Github < self
6
6
  def url
7
- settings.fetch("CURRENT_REPOSITORY_URL", nil)
7
+ settings.fetch("NOTIFY_CURRENT_REPOSITORY_URL", nil)
8
8
  end
9
9
 
10
10
  def link(sha)
@@ -8,7 +8,7 @@ module ChatNotifier
8
8
  end
9
9
 
10
10
  def run_id
11
- settings.fetch("TEST_RUN_ID")
11
+ settings.fetch("NOTIFY_TEST_RUN_ID")
12
12
  end
13
13
  end
14
14
  end
@@ -22,7 +22,7 @@ module ChatNotifier
22
22
  end
23
23
 
24
24
  def url
25
- settings.fetch("CURRENT_REPOSITORY_URL")
25
+ settings.fetch("NOTIFY_CURRENT_REPOSITORY_URL")
26
26
  end
27
27
 
28
28
  def test_run_url
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChatNotifier
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/chat_notifier.rb CHANGED
@@ -12,6 +12,18 @@ module ChatNotifier
12
12
  DebugSummary = Data.define(:failed_examples)
13
13
 
14
14
  class << self
15
+ require "logger"
16
+ @logger = Logger.new($stdout)
17
+ attr_accessor :logger
18
+
19
+ def app
20
+ if defined?(::Rails)
21
+ Rails.application.class.module_parent
22
+ else
23
+ ENV.fetch("NOTIFY_APP_NAME")
24
+ end
25
+ end
26
+
15
27
  # In order to test this locally see `rake chat_notifier:debug`
16
28
  def debug!(env, summary:, notifier: :Debug)
17
29
  repository = Repository.for(env)
@@ -24,9 +36,9 @@ module ChatNotifier
24
36
  )
25
37
  messenger = Messenger.for(
26
38
  summary,
27
- app: Rails.application.class.module_parent,
28
- repository: repository,
29
- environment: environment
39
+ app:,
40
+ repository:,
41
+ environment:
30
42
  )
31
43
 
32
44
  chatter.post(messenger)
@@ -43,13 +55,17 @@ module ChatNotifier
43
55
 
44
56
  messenger = Messenger.for(
45
57
  summary,
46
- app: Rails.application.class.module_parent,
58
+ app:,
47
59
  repository:,
48
60
  environment:
49
61
  )
50
62
 
51
63
  chatter.each do |box|
52
- box.conditional_post(messenger)
64
+ begin
65
+ box.conditional_post(messenger)
66
+ rescue => exception
67
+ logger.error("ChatNotifier: #{box.webhook_url} #{exception.class}: #{exception.message}")
68
+ end
53
69
  end
54
70
  end
55
71
  end
@@ -0,0 +1,14 @@
1
+ module Minitest
2
+ def self.plugin_chat_notifier_init(options)
3
+ Minitest.reporter << ChatNotifierPlugin.new(options[:io], options)
4
+ end
5
+
6
+ class ChatNotifierPlugin < SummaryReporter
7
+ ExceptionLocation = Data.define(:location)
8
+ Summary = Data.define(:failed_examples)
9
+ def report
10
+ summary = Summary[(results.map{ |result| ExceptionLocation[result.source_location] })]
11
+ ChatNotifier.call(summary:)
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chat_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Gay
8
+ - Savannah Albanez
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2023-04-19 00:00:00.000000000 Z
12
+ date: 2024-07-01 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: Send test results to chat
14
15
  email:
15
16
  - jim@saturnflyer.com
17
+ - sealbanez@gmail.com
16
18
  executables: []
17
19
  extensions: []
18
20
  extra_rdoc_files: []
@@ -33,6 +35,7 @@ files:
33
35
  - lib/chat_notifier/test_environment/debug.rb
34
36
  - lib/chat_notifier/test_environment/github.rb
35
37
  - lib/chat_notifier/version.rb
38
+ - lib/minitest/chat_notifier_plugin.rb
36
39
  homepage:
37
40
  licenses: []
38
41
  metadata:
@@ -53,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
56
  - !ruby/object:Gem::Version
54
57
  version: '0'
55
58
  requirements: []
56
- rubygems_version: 3.4.6
59
+ rubygems_version: 3.5.9
57
60
  signing_key:
58
61
  specification_version: 4
59
62
  summary: Notify chat of test results