slack-cap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7777184d7cf2d2a177cbe4334b492c3754d13ac2
4
+ data.tar.gz: 79c59824f9942b76144cc8b8a0a9b4118c16dd40
5
+ SHA512:
6
+ metadata.gz: 2bc2d32b0515a1a6bfc6830f36780d3749d9548ae2e076479062b46ceaf6da009306ff01f695b44ca03682ba0959588889dba4fd546049f4c5a2c820615baec2
7
+ data.tar.gz: 8002f7ae201b11f50c9056fa8b39756da9de46b7c2ca26e1d4696f23fcaa1c1a3c1b05ecbd1aa1f8fa2b0b46057536d71b073629060e013ab0d49e2493f8dc3e
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in slack-cap.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Roman Heinrich
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,42 @@
1
+ # Slack::Cap
2
+ Hooks before / after deploy tasks and notifies Slack about the deployment start and finish.
3
+
4
+ The output looks like this:
5
+
6
+ Jon Doe / MyAwesomeApp's master / production - started - fixing that nasty bug...
7
+ Jon Doe / MyAwesomeApp's master / production - finished - 31 seconds.
8
+
9
+
10
+ ## Installation
11
+
12
+ # In Gemfile:
13
+ gem 'slack-cap'
14
+
15
+ # then run:
16
+ $ bundle
17
+
18
+
19
+ ## Usage
20
+
21
+ # in your Capfile
22
+ require 'slack-cap'
23
+
24
+ # in your config/deploy.rb
25
+ set :slack_app, 'MyAwesomeApp'
26
+ set :slack_team, 'my-subdomain-on-slack.com'
27
+ set :slack_token, 'XXXXXXXXXXXX'
28
+ set :slack_channel, '#deployments'
29
+ set :slack_username, 'capistrano'
30
+
31
+
32
+ # deployment
33
+ $ MSG='fixing that nasty bug...' cap production deploy
34
+
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/[my-github-username]/slack-cap/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,71 @@
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
+ namespace :slack do
32
+ def wrapper
33
+ @wrapper ||= SlackNotifierWrapper.new(
34
+ app: fetch(:slack_app),
35
+ team: fetch(:slack_team),
36
+ token: fetch(:slack_token),
37
+ channel: fetch(:slack_channe),
38
+ username: fetch(:slack_username),
39
+ )
40
+ end
41
+
42
+ def msg_prefix
43
+ deployer = wrapper.deployer
44
+ app = wrapper.app
45
+ branch = fetch(:branch, nil)
46
+ stage = fetch(:stage, 'production')
47
+ app_string = branch ? "#{app}'s #{branch}" : app
48
+
49
+
50
+ "#{deployer} / #{app_string} / #{stage}"
51
+ end
52
+
53
+ task :starting do
54
+ msg = "#{msg_prefix} - started - #{wrapper.reason}"
55
+
56
+ wrapper.notify(msg)
57
+ set(:start_time, Time.now)
58
+ end
59
+
60
+ 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
67
+ end
68
+
69
+ before 'deploy', 'slack:starting'
70
+ after 'deploy', 'slack:finished'
71
+ end
@@ -0,0 +1,5 @@
1
+ module Slack
2
+ module Cap
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/lib/slack-cap.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'slack-notifier'
2
+ require "slack-cap/version"
3
+ load File.expand_path("capistrano/tasks/slack.rake", File.dirname(__FILE__))
data/slack-cap.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slack-cap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "slack-cap"
8
+ spec.version = Slack::Cap::VERSION
9
+ spec.authors = ["Roman Heinrich"]
10
+ spec.email = ["roman.heinrich@gmail.com"]
11
+ spec.summary = %q{Capistrano plugin to enable notifications to Slack}
12
+ spec.description = spec.summary
13
+ spec.homepage = "https://github.com/mindreframer/slack-cap"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency "slack-notifier", "~> 0.6"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: slack-cap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman Heinrich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slack-notifier
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Capistrano plugin to enable notifications to Slack
56
+ email:
57
+ - roman.heinrich@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/capistrano/tasks/slack.rake
68
+ - lib/slack-cap.rb
69
+ - lib/slack-cap/version.rb
70
+ - slack-cap.gemspec
71
+ homepage: https://github.com/mindreframer/slack-cap
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Capistrano plugin to enable notifications to Slack
95
+ test_files: []