capistrano-slack_notification 0.0.1

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: 2a456e196bc170b8aa2023432c78699747aaeac8
4
+ data.tar.gz: 27ca39f0e60279647fc546970a3acb9199c9fbd2
5
+ SHA512:
6
+ metadata.gz: c44e5b46efd1365df569adb1f563e229aac416f9bfe802a74d6b531f496bae10e5c7146fcc39625752803ffeb3fec8c585209f0c73af3e9a2ba03ec0b90d05bb
7
+ data.tar.gz: e9484ef9e324620fa573397c6e8b3fb8c8a226239797b2650e41857233ab5751c893a5ba66c36bd86424557c11ec10c0d8c14bc1f81d1dc25d0c78e710cf150f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-slack_notification.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'awesome_print'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 linyows
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,70 @@
1
+ Capistrano - Slack Notification
2
+ ===============================
3
+
4
+ Notify Capistrano ver3 deployment to Slack.
5
+
6
+ [![Gem version](https://img.shields.io/gem/v/capistrano-slack_notification.svg?style=flat-square)][gem]
7
+ [gem]: https://rubygems.org/gems/capistrano-slack_notification
8
+
9
+ Installation
10
+ ------------
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'capistrano-slack_notification'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```sh
21
+ $ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```sh
27
+ $ gem install capistrano-slack_notification
28
+ ```
29
+
30
+ Usage
31
+ -----
32
+
33
+ Capfile:
34
+
35
+ ```ruby
36
+ require 'capistrano/slack_notification'
37
+ ```
38
+
39
+ config.rb:
40
+
41
+ ```ruby
42
+ set :slack_channel, '#general'
43
+ set :slack_endpoint, 'https://hooks.slack.com'
44
+ set :slack_path, '/services/T00000000/B00000000/XXXXXXXXXXXXXXXXX'
45
+
46
+ after 'deploy:started', 'slack:notify_start'
47
+ after 'deploy:finishing', 'slack:notify_finish'
48
+ after 'deploy:finishing_rollback', 'slack:notify_rollback'
49
+ ```
50
+
51
+ Contributing
52
+ ------------
53
+
54
+ 1. Fork it ( https://github.com/linyows/capistrano-slack_notification/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create a new Pull Request
59
+
60
+ Author
61
+ ------
62
+
63
+ - [linyows][linyows]
64
+
65
+ [linyows]: https://github.com/linyows
66
+
67
+ License
68
+ -------
69
+
70
+ The MIT License (MIT)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/slack_notification/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-slack_notification"
8
+ spec.version = Capistrano::SlackNotification::VERSION
9
+ spec.authors = ["linyows"]
10
+ spec.email = ["linyows@gmail.com"]
11
+ spec.summary = %q{Notify Capistrano deployment to Slack.}
12
+ spec.description = %q{Notify Capistrano deployment to Slack.}
13
+ spec.homepage = "https://github.com/linyows/capistrano-slack_notification"
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 "faraday", "~> 0.9"
22
+ spec.add_dependency "capistrano", "> 3.1"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,7 @@
1
+ require "capistrano/slack_notification/version"
2
+
3
+ module Capistrano
4
+ module SlackNotification
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module SlackNotification
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,116 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ namespace :slack do
5
+ start = Time.now
6
+ elapsed_time = -> { sprintf('%.2f', Time.now - start) }
7
+
8
+ set :slack_token, nil
9
+ set :slack_channel, '#general'
10
+
11
+ set :slack_endpoint, 'https://slack.com'
12
+ set :slack_username, 'capistrano'
13
+ set :slack_icon_url, 'https://github.com/linyows/capistrano-slack_notification/misc/capistrano-icon.png'
14
+
15
+ set :slack_deployer, -> {
16
+ username = `git config --get user.name`.strip
17
+ username = `whoami`.strip unless username
18
+ username
19
+ }
20
+
21
+ set :slack_path, -> {
22
+ token = fetch(:slack_token)
23
+ "/api/chat.postMessage#{"?token=#{token}" if token}"
24
+ }
25
+
26
+ set :slack_stage, -> {
27
+ stage = fetch(:stage)
28
+ stage.to_s == 'production' ? ":warning: #{stage}" : stage
29
+ }
30
+
31
+ set :slack_default_body, -> {
32
+ {
33
+ username: fetch(:slack_username),
34
+ channel: fetch(:slack_channel),
35
+ icon_url: fetch(:slack_icon_url),
36
+ text: ''
37
+ }
38
+ }
39
+
40
+ set :slack_start_body, -> {
41
+ fetch(:slack_default_body).merge(
42
+ attachments: JSON.dump([{
43
+ color: "warning",
44
+ title: fetch(:application),
45
+ text: "Started deploying to #{fetch(:slack_stage)} by @#{fetch(:slack_deployer)}" +
46
+ " (branch #{fetch(:branch)})",
47
+ mrkdwn_in: ['text']
48
+ }])
49
+ )
50
+ }
51
+
52
+ set :slack_failure_body, -> {
53
+ fetch(:slack_default_body).merge(
54
+ attachments: JSON.dump([{
55
+ color: 'danger',
56
+ title: fetch(:application),
57
+ text: "Failed deploying to #{fetch(:slack_stage)} by @#{fetch(:slack_deployer)}" +
58
+ " (branch #{fetch(:branch)} at #{fetch(:current_revision)} / #{elapsed_time.call} sec)",
59
+ mrkdwn_in: ['text']
60
+ }])
61
+ )
62
+ }
63
+
64
+ set :slack_success_body, -> {
65
+ task = fetch(:deploying) ? 'deployment' : '*rollback*'
66
+ fetch(:slack_default_body).merge(
67
+ attachments: JSON.dump([{
68
+ color: 'good',
69
+ title: fetch(:application),
70
+ text: "Successful #{task} to #{fetch(:slack_stage)} by @#{fetch(:slack_deployer)}" +
71
+ " (branch #{fetch(:branch)} at #{fetch(:current_revision)} / #{elapsed_time.call} sec)",
72
+ mrkdwn_in: ['text']
73
+ }])
74
+ )
75
+ }
76
+
77
+ def post_to_slack(message = '')
78
+ notify_to_slack_with(title: message)
79
+ end
80
+
81
+ def post_to_slack_with(body)
82
+ conn = Faraday.new(fetch :slack_endpoint) do |c|
83
+ c.request :url_encoded
84
+ c.adapter Faraday.default_adapter
85
+ c.options.timeout = 5
86
+ c.options.open_timeout = 5
87
+ c.response :logger
88
+ end
89
+
90
+ require 'awesome_print'
91
+ res = conn.post fetch(:slack_path), body
92
+ ap body
93
+ ap res
94
+ end
95
+
96
+ desc 'Post message to Slack (ex. cap production "slack:notify[yo!])"'
97
+ task :post, :message do |t, args|
98
+ post_to_slack args[:message]
99
+ end
100
+
101
+ desc 'Notify a deploy starting to Slack'
102
+ task :notify_start do
103
+ post_to_slack_with fetch(:slack_start_body)
104
+ end
105
+
106
+ desc 'Notify a deploy rollback to Slack'
107
+ task :notify_rollback do
108
+ post_to_slack_with fetch(
109
+ :"slack_#{fetch(:deploying) ? :failure : :success}_body")
110
+ end
111
+
112
+ desc 'Notify a deploy finish to Slack'
113
+ task :notify_finish do
114
+ post_to_slack_with fetch(:slack_success_body)
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-slack_notification
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Notify Capistrano deployment to Slack.
70
+ email:
71
+ - linyows@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - capistrano-slack_notification.gemspec
82
+ - lib/capistrano/slack_notification.rb
83
+ - lib/capistrano/slack_notification/version.rb
84
+ - lib/capistrano/tasks/slack_notification.rake
85
+ homepage: https://github.com/linyows/capistrano-slack_notification
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.5
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: Notify Capistrano deployment to Slack.
109
+ test_files: []