slack-ruby-bot-server 0.3.1 → 0.4.0

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: 4d16d65efc278c6cc7ae66e43012323a7675f45d
4
- data.tar.gz: 4a4a3392ab0fb18640a23d6f56f848d731b113e9
3
+ metadata.gz: 1bd761a554a479830a8e142d3550c0ee9bf277dc
4
+ data.tar.gz: c0cf2c2735e222f9e5818a02dc8766e0fa7e7e9f
5
5
  SHA512:
6
- metadata.gz: 074ba2f86c6761a2e5c41f4dbca6bd1f8a5b7d226a19370c297b9fc1b6410d1123784f2f7540e6596498a84e502fdb4fabc733055bd5ceb4ef4a270b94f2393a
7
- data.tar.gz: 040856718b74ad9f9fd9ecabd7e3d77c1cdd0257051d3aa126bf82007118696aa63a9152df5b14aa3cc15250c0718f8215934066ffc7360082f445b5e3738ec3
6
+ metadata.gz: d33bd339c7532d61bedc270d34284ccd481780d8c6594d70e9a63802066888e9ae6023eb138ba5d38573ce5ce591ca33c92f28e8c43fe04e6ccf07c2d436952a
7
+ data.tar.gz: 92c8bf07d7b922adc710d90855a381eb5a021c6e60aade96f6798d06be9e2dc97edae3bff1e645034c5989519289fac390834f728bfffb31cd0bc8f5948661cb
@@ -1,9 +1,23 @@
1
- rvm:
2
- - 2.2.4
3
1
  language: ruby
2
+
4
3
  cache: bundler
4
+
5
5
  services:
6
6
  - mongodb
7
+
8
+ matrix:
9
+ include:
10
+ - rvm: 2.3.1
11
+ script:
12
+ - bundle exec danger
13
+ - rvm: 2.3.1
14
+ - rvm: 2.3.0
15
+ - rvm: ruby-head
16
+ - rvm: jruby-head
17
+ allow_failures:
18
+ - rvm: ruby-head
19
+ - rvm: jruby-head
20
+
7
21
  before_install:
8
22
  - "export DISPLAY=:99.0"
9
23
  - "sh -e /etc/init.d/xvfb start"
@@ -1,8 +1,15 @@
1
1
  ### Changelog
2
2
 
3
+ #### 0.4.0 (8/29/2016)
4
+
5
+ * [#25](https://github.com/slack-ruby/slack-ruby-bot-server/pull/25): Added [danger](http://danger.systems), PR linting - [@dblock](https://github.com/dblock).
6
+ * The `reset` and `resetting` callbacks have been removed - [@dblock](https://github.com/dblock).
7
+ * Callbacks receive `team` and `error`, but no longer `server` - [@dblock](https://github.com/dblock).
8
+ * [#23](https://github.com/slack-ruby/slack-ruby-bot-server/issues/23): Fix: server-side removal of bot doesn't deactivate it - [@dblock](https://github.com/dblock).
9
+
3
10
  #### 0.3.1 (7/10/2016)
4
11
 
5
- * [#22](https://github.com/dblock/slack-ruby-bot-server/issues/22): Subclassing `SlackRubyBotServer::App` creates an `.instance` of child class - [@dblock](https://github.com/dblock).
12
+ * [#22](https://github.com/slack-ruby/slack-ruby-bot-server/issues/22): Subclassing `SlackRubyBotServer::App` creates an `.instance` of child class - [@dblock](https://github.com/dblock).
6
13
 
7
14
  #### 0.3.0 (7/4/2016)
8
15
 
@@ -12,23 +19,23 @@
12
19
  #### 0.2.0 (6/21/2016)
13
20
 
14
21
  * Relaxed dependency versions, notably enabling grape 0.16.2 and Swagger 0.21.0 that uses Swagger 2.0 spec - [@dblock](https://github.com/dblock).
15
- * [#21](https://github.com/dblock/slack-ruby-bot-server/issues/21): Fix: pass additional options through into `SlackRubyBot::Server` - [@dblock](https://github.com/dblock).
22
+ * [#21](https://github.com/slack-ruby/slack-ruby-bot-server/issues/21): Fix: pass additional options through into `SlackRubyBot::Server` - [@dblock](https://github.com/dblock).
16
23
 
17
24
  #### 0.1.1 (6/4/2016)
18
25
 
19
- * [#14](https://github.com/dblock/slack-ruby-bot-server/pull/14): Moved config/initializers into the library - [@tmsrjs](https://github.com/tmsrjs).
26
+ * [#14](https://github.com/slack-ruby/slack-ruby-bot-server/pull/14): Moved config/initializers into the library - [@tmsrjs](https://github.com/tmsrjs).
20
27
 
21
28
  #### 0.1.0 (6/1/2016)
22
29
 
23
30
  * Initial public release - [@dblock](https://github.com/dblock).
24
- * 2016/6/1: Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
25
- * 2016/5/30: [#11](https://github.com/dblock/slack-ruby-bot-server/pull/11) Turn project into gem - [@tmsrjs](https://github.com/tmsrjs).
26
- * 2016/5/5: Use `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
27
- * 2016/4/18: Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
28
- * 2016/4/18: Use Grape 0.15.x - [@dblock](https://github.com/dblock).
29
- * 2016/4/18: Removed OOB GC - [@dblock](https://github.com/dblock).
30
- * 2016/2/11: Use Unicorn instead of Puma - [@dblock](https://github.com/dblock).
31
- * 2016/2/11: Fix: wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
32
- * 2016/2/11: Use an OOB GC - [@dblock](https://github.com/dblock).
33
- * 2016/2/9: Defer start, much faster - [@dblock](https://github.com/dblock).
34
- * 2016/1/10: Backported changes from slack-metabot and slack-shellbot - [@dblock](https://github.com/dblock).
31
+ * Renamed slack-bot-server to slack-ruby-bot-server - [@dblock](https://github.com/dblock).
32
+ * [#11](https://github.com/slack-ruby/slack-ruby-bot-server/pull/11): Turn project into gem - [@tmsrjs](https://github.com/tmsrjs).
33
+ * Use `celluloid-io` instead of `faye-websocket`, upgrade to slack-ruby-bot 0.8.0 - [@dblock](https://github.com/dblock).
34
+ * Fixed `SlackRubyBotServer#reset` - [@dblock](https://github.com/dblock).
35
+ * Use Grape 0.15.x - [@dblock](https://github.com/dblock).
36
+ * Removed OOB GC - [@dblock](https://github.com/dblock).
37
+ * Use Unicorn instead of Puma - [@dblock](https://github.com/dblock).
38
+ * Fix: wait for EventMachine reactor to start - [@dblock](https://github.com/dblock).
39
+ * Use an OOB GC - [@dblock](https://github.com/dblock).
40
+ * Defer start, much faster - [@dblock](https://github.com/dblock).
41
+ * Backported changes from slack-metabot and slack-shellbot - [@dblock](https://github.com/dblock).
@@ -0,0 +1 @@
1
+ # inherits from https://github.com/slack-ruby/danger
data/Gemfile CHANGED
@@ -19,4 +19,5 @@ group :development, :test do
19
19
  gem 'hyperclient'
20
20
  gem 'capybara'
21
21
  gem 'selenium-webdriver'
22
+ gem 'danger', '~> 2.0'
22
23
  end
data/README.md CHANGED
@@ -13,7 +13,7 @@ A library that contains a [Grape](http://github.com/ruby-grape/grape) API servin
13
13
 
14
14
  ### Stable Release
15
15
 
16
- You're reading the documentation for the **stable** release of slack-ruby-bot-server 0.3.1. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
16
+ You're reading the documentation for the **stable** release of slack-ruby-bot-server 0.4.0. See [UPGRADING](UPGRADING.md) when upgrading from an older version.
17
17
 
18
18
  ### Try Me
19
19
 
@@ -76,15 +76,15 @@ You can introduce custom behavior into the service lifecycle via callbacks. This
76
76
  ```ruby
77
77
  instance = SlackRubyBotServer::Service.instance
78
78
 
79
- instance.on :created do |team, server, error|
79
+ instance.on :created do |team, error|
80
80
  # a new team has been registered
81
81
  end
82
82
 
83
- instance.on :deactivated do |team, server, error|
83
+ instance.on :deactivated do |team, error|
84
84
  # an existing team has been deactivated in Slack
85
85
  end
86
86
 
87
- instance.on :error do |team, server, error|
87
+ instance.on :error do |team, error|
88
88
  # an error has occurred
89
89
  end
90
90
  ```
@@ -104,8 +104,6 @@ The following callbacks are supported. All callbacks receive a `team`, except `e
104
104
  | started | the service has (re)connected a team to Slack |
105
105
  | deactivating | a team is being deactivated |
106
106
  | deactivated | a team has been deactivated |
107
- | resetting | the service is resetting, all teams being stopped |
108
- | reset | the service has been reset, all teams have been stopped |
109
107
 
110
108
  #### Server Class
111
109
 
@@ -1,6 +1,29 @@
1
1
  Upgrading Slack-Ruby-Bot-Server
2
2
  ===============================
3
3
 
4
+ ### Upgrading to >= 0.4.0
5
+
6
+ #### Add giphy to your Gemfile for GIF support
7
+
8
+ The dependency on the `giphy` gem was dropped in slack-ruby-bot 0.9.0 and GIFs don't appear by default. If you want GIF support, add `gem 'giphy'` to your **Gemfile**.
9
+
10
+ See [slack-ruby-bot#89](https://github.com/slack-ruby/slack-ruby-bot/pull/89) for more information.
11
+
12
+ #### Changes in Callbacks
13
+
14
+ The `SlackRubyBotServer::Service` class used to track services in a `Hash`. This is no longer the case. Callbacks no longer receive a server object for the team, but the latter is assigned as `team.server`.
15
+
16
+ ```ruby
17
+ instance = SlackRubyBotServer::Service.instance
18
+
19
+ instance.on :started do |team, error|
20
+ # a new team has been registered
21
+ # team.server is available
22
+ end
23
+ ```
24
+
25
+ The `reset` and `resetting` callbacks have also been removed.
26
+
4
27
  ### Upgrading to >= 0.3.1
5
28
 
6
29
  #### Remove Monkey-Patching of SlackRubyBotServer::App
@@ -10,6 +10,8 @@ class Team
10
10
  field :token, type: String
11
11
  field :active, type: Boolean, default: true
12
12
 
13
+ attr_accessor :server # server at runtime
14
+
13
15
  scope :active, -> { where(active: true) }
14
16
 
15
17
  validates_uniqueness_of :token, message: 'has already been used'
@@ -14,8 +14,6 @@ module SlackRubyBotServer
14
14
  end
15
15
 
16
16
  def initialize
17
- @lock = Mutex.new
18
- @services = {}
19
17
  @callbacks = Hash.new { |h, k| h[k] = [] }
20
18
  end
21
19
 
@@ -25,91 +23,73 @@ module SlackRubyBotServer
25
23
 
26
24
  def create!(team)
27
25
  run_callbacks :creating, team
28
- server = start!(team)
29
- run_callbacks :created, team, server
26
+ start!(team)
27
+ run_callbacks :created, team
30
28
  end
31
29
 
32
30
  def start!(team)
33
- raise 'Token already known.' if @services.key?(team.token)
34
31
  run_callbacks :starting, team
35
32
  logger.info "Starting team #{team}."
36
33
  server = SlackRubyBotServer::Config.server_class.new(team: team)
37
- @lock.synchronize do
38
- @services[team.token] = server
39
- end
40
34
  start_server! team, server
41
- run_callbacks :started, team, server
35
+ run_callbacks :started, team
42
36
  server
43
37
  rescue StandardError => e
44
- run_callbacks :error, team, nil, e
38
+ run_callbacks :error, team, e
45
39
  logger.error e
46
40
  end
47
41
 
48
42
  def restart!(team, server, wait = 1)
49
- run_callbacks :restarting, team, server
43
+ run_callbacks :restarting, team
50
44
  start_server! team, server, wait
51
- run_callbacks :restarted, team, server
45
+ run_callbacks :restarted, team
52
46
  end
53
47
 
54
48
  def stop!(team)
55
49
  logger.info "Stopping team #{team}."
56
- @lock.synchronize do
57
- raise 'Token unknown.' unless @services.key?(team.token)
58
- server = @services[team.token]
59
- run_callbacks :stopping, team, server
60
- server.stop!
61
- @services.delete(team.token)
62
- run_callbacks :stopped, team, server
63
- end
50
+ run_callbacks :stopping, team
51
+ team.server.stop! if team.server
52
+ run_callbacks :stopped, team
64
53
  rescue StandardError => e
65
- run_callbacks :error, team, @services[team.token], e
54
+ run_callbacks :error, team, e
66
55
  logger.error e
56
+ ensure
57
+ team.server = nil
67
58
  end
68
59
 
69
60
  def start_from_database!
70
61
  Team.active.each do |team|
71
62
  run_callbacks :booting, team
72
- server = start!(team)
73
- run_callbacks :booted, team, server
63
+ start!(team)
64
+ run_callbacks :booted, team
74
65
  end
75
66
  end
76
67
 
77
68
  def deactivate!(team)
78
- @lock.synchronize do
79
- raise 'Token unknown.' unless @services.key?(team.token)
80
- server = @services[team.token]
81
- run_callbacks :deactivating, team, server
82
- team.deactivate!
83
- @services.delete(team.token)
84
- run_callbacks :deactivated, team, server
85
- end
69
+ run_callbacks :deactivating, team
70
+ team.deactivate!
71
+ run_callbacks :deactivated, team
86
72
  rescue Mongoid::Errors::Validations => e
87
- run_callbacks :error, team, @services[team.token], e
73
+ run_callbacks :error, team, e
88
74
  logger.error "#{team.name}: #{e.message}, error - #{e.document.class}, #{e.document.errors.to_hash}, ignored."
89
75
  rescue StandardError => e
90
- run_callbacks :error, team, @services[team.token], e
76
+ run_callbacks :error, team, e
91
77
  logger.error "#{team.name}: #{e.class}, #{e.message}, ignored."
92
- end
93
-
94
- def reset!
95
- run_callbacks :resetting
96
- @services.values.to_a.each do |server|
97
- stop!(server.team)
98
- end
99
- run_callbacks :reset
78
+ ensure
79
+ team.server = nil
100
80
  end
101
81
 
102
82
  def self.reset!
103
- @instance.reset! if @instance
104
83
  @instance = nil
105
84
  end
106
85
 
107
86
  private
108
87
 
109
88
  def start_server!(team, server, wait = 1)
89
+ team.server = server
110
90
  server.start_async
111
91
  rescue StandardError => e
112
- run_callbacks :error, team, server, e
92
+ run_callbacks :error, team, e
113
93
  case e.message
114
94
  when 'account_inactive', 'invalid_auth' then
115
95
  logger.error "#{team.name}: #{e.message}, team will be deactivated."
@@ -121,11 +101,11 @@ module SlackRubyBotServer
121
101
  end
122
102
  end
123
103
 
124
- def run_callbacks(type, team = nil, server = nil, error = nil)
104
+ def run_callbacks(type, team = nil, error = nil)
125
105
  callbacks = @callbacks[type.to_s]
126
106
  return false unless callbacks
127
107
  callbacks.each do |c|
128
- c.call team, server, error
108
+ c.call team, error
129
109
  end
130
110
  true
131
111
  rescue StandardError => e
@@ -1,3 +1,3 @@
1
1
  module SlackRubyBotServer
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -0,0 +1 @@
1
+ This app is deployed from [github.com/slack-ruby/slack-ruby-bot-server-sample](https://github.com/slack-ruby/slack-ruby-bot-server-sample).
@@ -1,6 +1,6 @@
1
1
  ENV['RACK_ENV'] ||= 'development'
2
2
 
3
- require 'slack-ruby-bot-server'
3
+ Bundler.require :default
4
4
 
5
5
  require_relative 'commands'
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-bot-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Doubrovkine
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-10 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slack-ruby-bot
@@ -207,6 +207,7 @@ files:
207
207
  - CHANGELOG.md
208
208
  - CONTRIBUTING.md
209
209
  - DEBUGGING.md
210
+ - Dangerfile
210
211
  - Gemfile
211
212
  - Guardfile
212
213
  - LICENSE
@@ -264,6 +265,7 @@ files:
264
265
  - sample_app/.rspec
265
266
  - sample_app/Gemfile
266
267
  - sample_app/Procfile
268
+ - sample_app/README.md
267
269
  - sample_app/Rakefile
268
270
  - sample_app/commands.rb
269
271
  - sample_app/commands/help.rb
@@ -296,7 +298,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
296
298
  version: '0'
297
299
  requirements: []
298
300
  rubyforge_project:
299
- rubygems_version: 2.4.8
301
+ rubygems_version: 2.5.1
300
302
  signing_key:
301
303
  specification_version: 4
302
304
  summary: A Grape API serving a Slack bot to multiple teams.