slack-cap 0.1.0 → 0.2.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: 7777184d7cf2d2a177cbe4334b492c3754d13ac2
4
- data.tar.gz: 79c59824f9942b76144cc8b8a0a9b4118c16dd40
3
+ metadata.gz: 1d8ef0d69f4b99b092272c6855fde1a0cd08a4ff
4
+ data.tar.gz: fd935700bbdc03ef6ac2814161cda0d79f68f07d
5
5
  SHA512:
6
- metadata.gz: 2bc2d32b0515a1a6bfc6830f36780d3749d9548ae2e076479062b46ceaf6da009306ff01f695b44ca03682ba0959588889dba4fd546049f4c5a2c820615baec2
7
- data.tar.gz: 8002f7ae201b11f50c9056fa8b39756da9de46b7c2ca26e1d4696f23fcaa1c1a3c1b05ecbd1aa1f8fa2b0b46057536d71b073629060e013ab0d49e2493f8dc3e
6
+ metadata.gz: 474288e22d633701cbb27280d7298938527c4ca202b4367da324bd9fdbd63f7d555e90de59fb2b414d57c3004eac2e093ada444e46b384fca0871cb8a28c511f
7
+ data.tar.gz: 21e313e2b002de71dec90402bff2fe8465039382c0109faa440f049ffbe8600a08470e8b05f4bfcfaf4441f4e06b896f9e33b2a1afcb18ab4c93f5a0a465dbda
data/README.md CHANGED
@@ -26,6 +26,8 @@
26
26
  set :slack_team, 'my-subdomain-on-slack.com'
27
27
  set :slack_token, 'XXXXXXXXXXXX'
28
28
  set :slack_channel, '#deployments'
29
+
30
+ # optional param, defaults to 'capistrano'
29
31
  set :slack_username, 'capistrano'
30
32
 
31
33
 
@@ -1,36 +1,6 @@
1
- class SlackNotifierWrapper
2
- attr_accessor :team, :token, :channel, :app, :username
3
-
4
- def initialize(opts)
5
- @app = opts.fetch(:app)
6
- @team = opts.fetch(:team)
7
- @token = opts.fetch(:token)
8
- @channel = opts.fetch(:channel)
9
- @username = opts[:username] ||'capistrano'
10
- end
11
-
12
- def deployer
13
- ENV['GIT_AUTHOR_NAME'] || `git config user.name`.chomp
14
- end
15
-
16
- def reason
17
- raise "provice a reason with MSG=... !" unless ENV['MSG']
18
- ENV['MSG']
19
- end
20
-
21
- def notify(msg, icon_emoji: ':rocket:')
22
- notifier.ping(msg, icon_emoji: icon_emoji)
23
- end
24
-
25
- def notifier
26
- @notifier ||= ::Slack::Notifier.new(team, token, channel: channel, username: username)
27
- end
28
- end
29
-
30
-
31
1
  namespace :slack do
32
2
  def wrapper
33
- @wrapper ||= SlackNotifierWrapper.new(
3
+ @wrapper ||= Slack::Cap::SlackNotifierWrapper.new(
34
4
  app: fetch(:slack_app),
35
5
  team: fetch(:slack_team),
36
6
  token: fetch(:slack_token),
@@ -58,12 +28,10 @@ namespace :slack do
58
28
  end
59
29
 
60
30
  task :finished do
61
- begin
62
- start_time = fetch(:start_time)
63
- elapsed = Time.now.to_i - start_time.to_i
64
- msg = "#{msg_prefix} - finished - #{elapsed} seconds."
65
- wrapper.notify(msg)
66
- end
31
+ start_time = fetch(:start_time)
32
+ elapsed = Time.now.to_i - start_time.to_i
33
+ msg = "#{msg_prefix} - finished - #{elapsed} seconds."
34
+ wrapper.notify(msg)
67
35
  end
68
36
 
69
37
  before 'deploy', 'slack:starting'
data/lib/slack-cap.rb CHANGED
@@ -1,3 +1,7 @@
1
1
  require 'slack-notifier'
2
+
2
3
  require "slack-cap/version"
4
+ require "slack-cap/colorize"
5
+ require "slack-cap/slack_notifier_wrapper"
6
+
3
7
  load File.expand_path("capistrano/tasks/slack.rake", File.dirname(__FILE__))
@@ -0,0 +1,27 @@
1
+ module Slack
2
+ module Cap
3
+
4
+ # simple colorization
5
+ class Colorize
6
+ def self.colorize(text, color_code)
7
+ "\e[#{color_code}m#{text}\e[0m"
8
+ end
9
+
10
+ def self.red(text)
11
+ colorize(text, 31)
12
+ end
13
+
14
+ def self.green(text)
15
+ colorize(text, 32)
16
+ end
17
+
18
+ def self.yellow(text)
19
+ colorize(text, 33)
20
+ end
21
+
22
+ def pink(text)
23
+ colorize(text, 35)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module Slack
2
+ module Cap
3
+ class SlackNotifierWrapper
4
+ attr_accessor :team, :token, :channel, :app, :username
5
+
6
+ def initialize(opts)
7
+ @app = opts.fetch(:app)
8
+ @team = opts.fetch(:team)
9
+ @token = opts.fetch(:token)
10
+ @channel = opts.fetch(:channel)
11
+ @username = opts[:username] ||'capistrano'
12
+ end
13
+
14
+ def deployer
15
+ ENV['GIT_AUTHOR_NAME'] || `git config user.name`.chomp
16
+ end
17
+
18
+ def reason
19
+ raise "provice a reason with MSG=... !" unless ENV['MSG']
20
+ ENV['MSG']
21
+ end
22
+
23
+ def notify(msg, icon_emoji: ':rocket:')
24
+ begin
25
+ notifier.ping(msg, icon_emoji: icon_emoji)
26
+ rescue Net::OpenTimeout, Net::ReadTimeout
27
+ puts Colorize.red("SLACK TIMEOUT")
28
+ end
29
+ end
30
+
31
+ def notifier
32
+ @notifier ||= ::Slack::Notifier.new(team, token, channel: channel, username: username)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  module Cap
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-cap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Heinrich
@@ -66,6 +66,8 @@ files:
66
66
  - Rakefile
67
67
  - lib/capistrano/tasks/slack.rake
68
68
  - lib/slack-cap.rb
69
+ - lib/slack-cap/colorize.rb
70
+ - lib/slack-cap/slack_notifier_wrapper.rb
69
71
  - lib/slack-cap/version.rb
70
72
  - slack-cap.gemspec
71
73
  homepage: https://github.com/mindreframer/slack-cap