slackbot-rails 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/images/slack-preview.png +0 -0
- data/lib/slackbot/rails.rb +89 -0
- data/lib/slackbot/rails/engine.rb +6 -0
- data/lib/slackbot/rails/version.rb +5 -0
- data/lib/slackbot/railtie.rb +7 -0
- data/slackbot-rails.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3fba1ecbb7c38a3b512bf42959614ecdeb97410
|
4
|
+
data.tar.gz: d1b11fd26d339fb62660af866ead49d48475db49
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48ee3548c593fb39d23a71935612e4e212d5782d9efda6316a4e39690705d0b96310748d266edfe30e00a10b08fb1f03d6f8ad09ea904d749fdbd83d274c8230
|
7
|
+
data.tar.gz: 95b05efcd7d22f9fa1b776b2b19d293c38005d73da3e092375ba518e6d85a202eebe6ce45c62f9b65b1093bbe46508f1918c4556ced2f4e920dfe1c4da9a6724
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Björn Wolf
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Slackbot::Rails
|
2
|
+
|
3
|
+
An activerecord hook to send notifications to slack on updations and creation of resources.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'slackbot-rails', :git => 'git://github.com/bitsapien/slackbot-rails.git'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Just put the `notify_bot` method in your model
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
class Model < ActiveRecord::Base
|
21
|
+
notify_bot bot: {
|
22
|
+
webhook: '<WEBHOOK URL>',
|
23
|
+
name: '<BOT NAME>',
|
24
|
+
channel: '#channel-name'
|
25
|
+
},
|
26
|
+
message: {
|
27
|
+
create: 'A new resource in *{class.model_name.human}* was created. '}
|
28
|
+
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
This would send a notification on Slack:
|
33
|
+
|
34
|
+
![Slack Preview](https://raw.githubusercontent.com/bitsapien/slackbot-rails/master/images/slack-preview.png)
|
35
|
+
|
36
|
+
Attributes inside '{}' will be evaluated on the present object of the model, for example :
|
37
|
+
`It is {valid?} that the present object passed validations` would output ->
|
38
|
+
`It is true that the present object passed validations`
|
39
|
+
|
40
|
+
|
41
|
+
#### Setting Defaults
|
42
|
+
|
43
|
+
You may enable/disable notifications using a flag, for example in `application.rb`
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
config.slackbot_rails_enable = Rails.env.production?
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
## TODO
|
51
|
+
|
52
|
+
1. Specs!
|
53
|
+
2. Background job option.
|
54
|
+
3. Add I18n support.
|
55
|
+
4. Add fallbacks for configurations.
|
56
|
+
5. Add more support for emojis.
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
Binary file
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'slackbot/rails/engine'
|
2
|
+
require 'slackbot/rails/version'
|
3
|
+
require 'slackbot/railtie' if defined? ::Rails::Railtie
|
4
|
+
require 'slack-notifier'
|
5
|
+
|
6
|
+
module Slackbot
|
7
|
+
module Rails
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def bot
|
12
|
+
@bot ||= Slack::Notifier.new slackbot_rails_options[:bot][:webhook],
|
13
|
+
http_options: { open_timeout: 5 } do
|
14
|
+
defaults channel: '#general',
|
15
|
+
username: 'Untitled'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def push_to_bot(message)
|
21
|
+
begin
|
22
|
+
bot.ping(text: message, channel: slackbot_rails_options[:bot][:channel], username: slackbot_rails_options[:bot][:name], icon_emoji: slackbot_rails_options[:bot][:icon])
|
23
|
+
rescue Exception => e
|
24
|
+
logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
|
25
|
+
logger.fatal "[Slackbot::Rails] #{e}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def notify_bot(options = {})
|
30
|
+
begin
|
31
|
+
cattr_accessor :slackbot_rails_options
|
32
|
+
self.slackbot_rails_options = options
|
33
|
+
if Slackbot::Railtie.enable_notifications && slackbot_rails_options[:message][:create].present?
|
34
|
+
after_commit :push_create_notification_to_bot, on: :create
|
35
|
+
end
|
36
|
+
if Slackbot::Railtie.enable_notifications && slackbot_rails_options[:message][:update].present?
|
37
|
+
after_commit :push_update_notification_to_bot, on: :update
|
38
|
+
end
|
39
|
+
rescue Exception => e
|
40
|
+
logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
|
41
|
+
logger.fatal "[Slackbot::Rails] #{e}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def push_create_notification_to_bot
|
49
|
+
begin
|
50
|
+
Thread.new do
|
51
|
+
self.class.push_to_bot build_message('create')
|
52
|
+
end
|
53
|
+
rescue Exception => e
|
54
|
+
logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
|
55
|
+
logger.fatal "[Slackbot::Rails] #{e}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def push_update_notification_to_bot
|
60
|
+
begin
|
61
|
+
Thread.new do
|
62
|
+
self.class.push_to_bot build_message('update')
|
63
|
+
end
|
64
|
+
rescue Exception => e
|
65
|
+
logger.fatal "[Slackbot::Rails] Something went wrong with pushing to the bot:"
|
66
|
+
logger.fatal "[Slackbot::Rails] #{e}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def build_message(action)
|
71
|
+
begin
|
72
|
+
message = slackbot_rails_options[:message][action.to_sym]
|
73
|
+
|
74
|
+
evaluate = message.scan(/{(.*?)}/).flatten
|
75
|
+
values = evaluate.inject({}) {|h,e| h.merge!(e => e.to_s.split('.').inject(self) {|o, a| o.try(a)})}
|
76
|
+
ready = message
|
77
|
+
values.each do |k,v|
|
78
|
+
ready = ready.gsub!("{#{k}}", v.to_s)
|
79
|
+
end
|
80
|
+
|
81
|
+
rescue Exception => e
|
82
|
+
logger.fatal e.message
|
83
|
+
end
|
84
|
+
ready
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
ActiveRecord::Base.send :include, Slackbot::Rails
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'slackbot/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slackbot-rails"
|
8
|
+
spec.version = Slackbot::Rails::VERSION
|
9
|
+
spec.authors = ["bitsapien"]
|
10
|
+
spec.email = ["bitsapien@gmail.com"]
|
11
|
+
spec.description = "Gem for notifying slack about the creation and updation of ActiveRecord models."
|
12
|
+
spec.summary = "Notify slack of model creates and updates"
|
13
|
+
spec.homepage = "http://github.com/bitsapien/slackbot-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_dependency "slack-notifier"
|
25
|
+
spec.add_dependency "activerecord", "> 3.0"
|
26
|
+
spec.add_dependency "activesupport", "> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slackbot-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bitsapien
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: slack-notifier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Gem for notifying slack about the creation and updation of ActiveRecord
|
84
|
+
models.
|
85
|
+
email:
|
86
|
+
- bitsapien@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- images/slack-preview.png
|
97
|
+
- lib/slackbot/rails.rb
|
98
|
+
- lib/slackbot/rails/engine.rb
|
99
|
+
- lib/slackbot/rails/version.rb
|
100
|
+
- lib/slackbot/railtie.rb
|
101
|
+
- slackbot-rails.gemspec
|
102
|
+
homepage: http://github.com/bitsapien/slackbot-rails
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.5.1
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Notify slack of model creates and updates
|
126
|
+
test_files: []
|