slack-notification 0.1.2 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +79 -0
- data/.travis.yml +19 -0
- data/Gemfile +3 -1
- data/Gemfile.lock +64 -0
- data/README.md +11 -8
- data/Rakefile +4 -2
- data/lib/slack_notification.rb +33 -13
- data/slack-notification.gemspec +10 -4
- metadata +76 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbc24a8c1366a7b1d6aa22dca33fb413325aa02666291a5b1a118e0475415aca
|
4
|
+
data.tar.gz: 8d09df6f567db50f153c02031a989e2a0e5991134dc64bfb5ccf5b04361fcc5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df8ea03b0f4a9f35d747df0e9478baef099f4386545fc59d29afda5aa360fec20f7aa8cc495d6ca02a504f3cc5357dedb661aee393727bea2c96f4028436564e
|
7
|
+
data.tar.gz: 5bb078e5be860b4517e97081bab14d82c445d60fb824ce0ef8e1c07b06a37a47f30cbe1775f4dc981feecc2950664c1e6433dd73ac8660e2b69495831bdf42d3
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: enable
|
4
|
+
Exclude:
|
5
|
+
- bin/**/*
|
6
|
+
- config/**/*
|
7
|
+
- db/**/*
|
8
|
+
- vendor/**/*
|
9
|
+
- tmp/**/*
|
10
|
+
|
11
|
+
Layout/AccessModifierIndentation:
|
12
|
+
EnforcedStyle: outdent
|
13
|
+
Layout/ArrayAlignment:
|
14
|
+
Enabled: true
|
15
|
+
Layout/EmptyLineAfterGuardClause:
|
16
|
+
Enabled: true
|
17
|
+
Layout/EmptyLinesAroundAccessModifier:
|
18
|
+
Enabled: true
|
19
|
+
Layout/FirstHashElementIndentation:
|
20
|
+
EnforcedStyle: consistent
|
21
|
+
Layout/HashAlignment:
|
22
|
+
Enabled: true
|
23
|
+
Layout/LineLength:
|
24
|
+
Max: 100
|
25
|
+
Layout/SpaceInsideBlockBraces:
|
26
|
+
EnforcedStyle: space
|
27
|
+
EnforcedStyleForEmptyBraces: no_space
|
28
|
+
Layout/SpaceInsideHashLiteralBraces:
|
29
|
+
EnforcedStyle: space
|
30
|
+
EnforcedStyleForEmptyBraces: no_space
|
31
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
32
|
+
EnforcedStyle: no_space
|
33
|
+
|
34
|
+
Lint/UnusedMethodArgument:
|
35
|
+
Enabled: true
|
36
|
+
Lint/UselessAssignment:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Metrics/MethodLength:
|
40
|
+
Enabled: true
|
41
|
+
Metrics/ClassLength:
|
42
|
+
Enabled: true
|
43
|
+
Max: 125
|
44
|
+
Metrics/ModuleLength:
|
45
|
+
Max: 125
|
46
|
+
Metrics/ParameterLists:
|
47
|
+
Enabled: true
|
48
|
+
Metrics/CyclomaticComplexity:
|
49
|
+
Enabled: true
|
50
|
+
Metrics/AbcSize:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Naming/MemoizedInstanceVariableName:
|
54
|
+
Enabled: false
|
55
|
+
Naming/MethodParameterName:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/AndOr:
|
59
|
+
Enabled: true
|
60
|
+
Style/ClassCheck:
|
61
|
+
Enabled: true
|
62
|
+
Style/Documentation:
|
63
|
+
Enabled: false
|
64
|
+
Style/FrozenStringLiteralComment:
|
65
|
+
Enabled: true
|
66
|
+
Style/GuardClause:
|
67
|
+
Enabled: true
|
68
|
+
Style/NumericLiterals:
|
69
|
+
Enabled: true
|
70
|
+
Style/StringLiterals:
|
71
|
+
Enabled: true
|
72
|
+
EnforcedStyle: single_quotes
|
73
|
+
|
74
|
+
Security/Eval:
|
75
|
+
Enabled: true
|
76
|
+
Security/JSONLoad:
|
77
|
+
Enabled: true
|
78
|
+
Security/YAMLLoad:
|
79
|
+
Enabled: true
|
data/.travis.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.5.1
|
4
|
+
branches:
|
5
|
+
except:
|
6
|
+
- "/^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-.*)?/"
|
7
|
+
notifications:
|
8
|
+
email:
|
9
|
+
on_success: change
|
10
|
+
on_failure: always
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter || (print "Will not report" && true)
|
13
|
+
- chmod +x ./cc-test-reporter || true
|
14
|
+
- ./cc-test-reporter before-build || true
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
- bundle exec rubocop
|
18
|
+
after_script:
|
19
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT || true
|
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack-notification (0.1.8)
|
5
|
+
slack-notifier (~> 2.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
docile (1.3.2)
|
13
|
+
parallel (1.20.1)
|
14
|
+
parser (3.0.0.0)
|
15
|
+
ast (~> 2.4.1)
|
16
|
+
rainbow (3.0.0)
|
17
|
+
rake (12.3.3)
|
18
|
+
regexp_parser (2.0.3)
|
19
|
+
rexml (3.2.4)
|
20
|
+
rspec (3.9.0)
|
21
|
+
rspec-core (~> 3.9.0)
|
22
|
+
rspec-expectations (~> 3.9.0)
|
23
|
+
rspec-mocks (~> 3.9.0)
|
24
|
+
rspec-core (3.9.1)
|
25
|
+
rspec-support (~> 3.9.1)
|
26
|
+
rspec-expectations (3.9.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-mocks (3.9.1)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-support (3.9.2)
|
33
|
+
rubocop (0.93.1)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 2.7.1.5)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
regexp_parser (>= 1.8)
|
38
|
+
rexml
|
39
|
+
rubocop-ast (>= 0.6.0)
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
42
|
+
rubocop-ast (1.4.1)
|
43
|
+
parser (>= 2.7.1.5)
|
44
|
+
ruby-progressbar (1.11.0)
|
45
|
+
simplecov (0.18.5)
|
46
|
+
docile (~> 1.1)
|
47
|
+
simplecov-html (~> 0.11)
|
48
|
+
simplecov-html (0.12.2)
|
49
|
+
slack-notifier (2.3.2)
|
50
|
+
unicode-display_width (1.7.0)
|
51
|
+
|
52
|
+
PLATFORMS
|
53
|
+
ruby
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
bundler (~> 2.0)
|
57
|
+
rake (~> 12.3, >= 12.3.3)
|
58
|
+
rspec (~> 3.8, >= 3.8.0)
|
59
|
+
rubocop (~> 0.93, >= 0.93.1)
|
60
|
+
simplecov (~> 0.16, >= 0.16.1)
|
61
|
+
slack-notification!
|
62
|
+
|
63
|
+
BUNDLED WITH
|
64
|
+
2.1.2
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# SlackNotification
|
2
2
|
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/slack-notification.svg)](https://rubygems.org/gems/slack-notification)
|
4
|
+
[![Build Status](https://travis-ci.org/jfiander/slack-notification.svg)](https://travis-ci.org/jfiander/slack-notification)
|
5
|
+
|
3
6
|
This is a simplified API for sending Slack messages from (e.g.) a Rails application.
|
4
7
|
|
5
8
|
## Installation
|
@@ -26,13 +29,13 @@ gem install slack-notification
|
|
26
29
|
|
27
30
|
```ruby
|
28
31
|
SlackNotification.new(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
channel: 'channel-name-here', type: :success, title: 'Something Happened',
|
33
|
+
fallback: "Plain-text version of the message.",
|
34
|
+
fields: [
|
32
35
|
{ title: 'Field one', value: value_one, short: true },
|
33
36
|
{ title: 'Field two', value: value_two, short: true },
|
34
37
|
{ title: 'Longer field that needs more space.', value: value_three, short: false }
|
35
|
-
|
38
|
+
]
|
36
39
|
).notify!
|
37
40
|
```
|
38
41
|
|
@@ -55,15 +58,15 @@ Available notification types:
|
|
55
58
|
|
56
59
|
Fields can be formatted in several ways:
|
57
60
|
|
58
|
-
String: The fields value becomes the message title, and no fields are submitted.
|
59
|
-
Hash: Format: `{ title_1: :value_1, [...] }`
|
60
|
-
Array: Array of hashes, each of format: `{ title: 'Field name', value: field_value, short: true }`
|
61
|
+
- String: The fields value becomes the message title, and no fields are submitted.
|
62
|
+
- Hash: Format: `{ title_1: :value_1, [...] }`
|
63
|
+
- Array: Array of hashes, each of format: `{ title: 'Field name', value: field_value, short: true }`
|
61
64
|
|
62
65
|
### Configuration
|
63
66
|
|
64
67
|
Channels can be made available by setting ENV variables beginning with `SLACK_URL_`.
|
65
68
|
|
66
|
-
If you are using Rails credentials,
|
69
|
+
If you are using Rails credentials, `.slack` will take priority over ENV variables, if present.
|
67
70
|
|
68
71
|
The title field will default to `ENV['SLACK_DEFAULT_TITLE']`, if present.
|
69
72
|
|
data/Rakefile
CHANGED
data/lib/slack_notification.rb
CHANGED
@@ -18,9 +18,9 @@ class SlackNotification
|
|
18
18
|
@data = {}
|
19
19
|
@data['title'] = @title || ENV['SLACK_DEFAULT_TITLE'] || 'Notification'
|
20
20
|
@data['fallback'] = @fallback || @data['title']
|
21
|
-
@data['fields'] = @fields if @fields
|
21
|
+
@data['fields'] = @fields if @fields
|
22
22
|
@data['color'] = slack_color
|
23
|
-
@data['footer'] =
|
23
|
+
@data['footer'] = footer if footer
|
24
24
|
@data
|
25
25
|
end
|
26
26
|
|
@@ -31,9 +31,27 @@ class SlackNotification
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def notifier
|
34
|
-
|
34
|
+
# :nocov:
|
35
|
+
raise "Missing notifier url for #{@channel}." unless slack_urls[@channel]
|
35
36
|
|
36
37
|
Slack::Notifier.new(slack_urls[@channel])
|
38
|
+
# :nocov:
|
39
|
+
end
|
40
|
+
|
41
|
+
def footer
|
42
|
+
return @footer unless @footer.nil?
|
43
|
+
|
44
|
+
# :nocov:
|
45
|
+
if ENV.key?('ASSET_ENVIRONMENT')
|
46
|
+
@footer = ENV['ASSET_ENVIRONMENT']
|
47
|
+
elsif defined?(Rails)
|
48
|
+
@footer = Rails.env
|
49
|
+
elsif ENV.key?('SLACK_FOOTER')
|
50
|
+
@footer = ENV['SLACK_FOOTER']
|
51
|
+
end
|
52
|
+
# :nocov:
|
53
|
+
|
54
|
+
@footer
|
37
55
|
end
|
38
56
|
|
39
57
|
def validated_fields(fields)
|
@@ -56,7 +74,7 @@ private
|
|
56
74
|
end
|
57
75
|
|
58
76
|
def slack_color
|
59
|
-
return '#CCCCCC'
|
77
|
+
return '#CCCCCC' unless @type
|
60
78
|
|
61
79
|
{
|
62
80
|
success: '#1086FF', info: '#99CEFF',
|
@@ -66,15 +84,15 @@ private
|
|
66
84
|
|
67
85
|
def validated_channel(channel = nil)
|
68
86
|
channel = channel.delete('#')
|
69
|
-
unknown_channel
|
87
|
+
unknown_channel(channel) unless slack_urls.keys.include?(channel)
|
70
88
|
|
71
|
-
channel
|
72
|
-
channel = 'test'
|
89
|
+
channel ||= 'notifications'
|
90
|
+
channel = 'test' if defined?(Rails) && !Rails.env.production?
|
73
91
|
channel
|
74
92
|
end
|
75
93
|
|
76
|
-
def unknown_channel
|
77
|
-
raise ArgumentError,
|
94
|
+
def unknown_channel(channel)
|
95
|
+
raise ArgumentError, "Unknown channel: #{channel}"
|
78
96
|
end
|
79
97
|
|
80
98
|
def slack_urls
|
@@ -86,18 +104,20 @@ private
|
|
86
104
|
end
|
87
105
|
|
88
106
|
def credentials_urls?
|
89
|
-
defined?(Rails) && Rails.application.credentials.
|
107
|
+
defined?(Rails) && !Rails.application.credentials.slack.nil?
|
90
108
|
end
|
91
109
|
|
92
110
|
def credentials_urls
|
93
|
-
|
94
|
-
|
111
|
+
# :nocov:
|
112
|
+
Rails.application.credentials.slack.transform_keys do |key|
|
113
|
+
key.to_s.gsub('_', '-')
|
95
114
|
end
|
115
|
+
# :nocov:
|
96
116
|
end
|
97
117
|
|
98
118
|
def validated_type(type = nil)
|
99
119
|
valid_types = %i[success info warning failure]
|
100
|
-
return type if type.
|
120
|
+
return type if type.nil? || valid_types.include?(type)
|
101
121
|
|
102
122
|
raise ArgumentError, 'Unrecognized notification type.'
|
103
123
|
end
|
data/slack-notification.gemspec
CHANGED
@@ -5,7 +5,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'slack-notification'
|
8
|
-
spec.version = '0.1.
|
8
|
+
spec.version = '0.1.8'
|
9
|
+
spec.date = '2021-02-08'
|
9
10
|
spec.authors = ['Julian Fiander']
|
10
11
|
spec.email = ['julian@fiander.one']
|
11
12
|
|
@@ -26,8 +27,13 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
28
|
spec.require_paths = ['lib']
|
28
29
|
|
29
|
-
spec.
|
30
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.required_ruby_version = '~> 2.5'
|
31
31
|
|
32
|
-
spec.
|
32
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.8', '>= 3.8.0'
|
35
|
+
spec.add_development_dependency 'rubocop', '~> 0.93', '>= 0.93.1'
|
36
|
+
spec.add_development_dependency 'simplecov', '~> 0.16', '>= 0.16.1'
|
37
|
+
|
38
|
+
spec.add_runtime_dependency 'slack-notifier', '~> 2.3'
|
33
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack-notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,80 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 12.3.3
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '12.3'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 12.3.3
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.8'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.8.0
|
34
57
|
type: :development
|
35
58
|
prerelease: false
|
36
59
|
version_requirements: !ruby/object:Gem::Requirement
|
37
60
|
requirements:
|
38
61
|
- - "~>"
|
39
62
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
63
|
+
version: '3.8'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 3.8.0
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rubocop
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.93'
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 0.93.1
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0.93'
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 0.93.1
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: simplecov
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.16'
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.16.1
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.16'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.16.1
|
41
107
|
- !ruby/object:Gem::Dependency
|
42
108
|
name: slack-notifier
|
43
109
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +126,10 @@ extensions: []
|
|
60
126
|
extra_rdoc_files: []
|
61
127
|
files:
|
62
128
|
- ".gitignore"
|
129
|
+
- ".rubocop.yml"
|
130
|
+
- ".travis.yml"
|
63
131
|
- Gemfile
|
132
|
+
- Gemfile.lock
|
64
133
|
- LICENSE.txt
|
65
134
|
- README.md
|
66
135
|
- Rakefile
|
@@ -80,17 +149,16 @@ require_paths:
|
|
80
149
|
- lib
|
81
150
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
151
|
requirements:
|
83
|
-
- - "
|
152
|
+
- - "~>"
|
84
153
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
154
|
+
version: '2.5'
|
86
155
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
156
|
requirements:
|
88
157
|
- - ">="
|
89
158
|
- !ruby/object:Gem::Version
|
90
159
|
version: '0'
|
91
160
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.7.6
|
161
|
+
rubygems_version: 3.1.2
|
94
162
|
signing_key:
|
95
163
|
specification_version: 4
|
96
164
|
summary: A simplified Slack API.
|