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 +4 -4
- data/README.md +2 -0
- data/lib/capistrano/tasks/slack.rake +5 -37
- data/lib/slack-cap.rb +4 -0
- data/lib/slack-cap/colorize.rb +27 -0
- data/lib/slack-cap/slack_notifier_wrapper.rb +37 -0
- data/lib/slack-cap/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d8ef0d69f4b99b092272c6855fde1a0cd08a4ff
|
4
|
+
data.tar.gz: fd935700bbdc03ef6ac2814161cda0d79f68f07d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 474288e22d633701cbb27280d7298938527c4ca202b4367da324bd9fdbd63f7d555e90de59fb2b414d57c3004eac2e093ada444e46b384fca0871cb8a28c511f
|
7
|
+
data.tar.gz: 21e313e2b002de71dec90402bff2fe8465039382c0109faa440f049ffbe8600a08470e8b05f4bfcfaf4441f4e06b896f9e33b2a1afcb18ab4c93f5a0a465dbda
|
data/README.md
CHANGED
@@ -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
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
@@ -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
|
data/lib/slack-cap/version.rb
CHANGED
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.
|
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
|