chattycrow_capistrano_notifications 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bd5455675612bbe1bf9e1396eca165752dc89612
4
+ data.tar.gz: 4587f91b752e44d4e009901dcb878859a3f91a56
5
+ SHA512:
6
+ metadata.gz: 481e49798ca321b9fdde9e6a137bda629b8d20b64da66ab3165e9a5b94abd789091e3aed7b639d20c9c9edb215842b5a5cae96b7c7fde490103a41aae5e962ab
7
+ data.tar.gz: 03eb989dc880fc31c27b380404f774646637be8a1f4822f8c777b3977bacaa7d7416d3419bd8ccf86769a7e4fed35ef4a5c2167a00126e82d8f02c0837e6d1fc
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-jabber-notifications.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ chattycrow_capistrano_notifications (0.0.1)
5
+ capistrano (~> 3.1)
6
+ chatty_crow
7
+
8
+ PATH
9
+ remote: /Users/strnadj/Projects/chattycrow_ruby
10
+ specs:
11
+ chatty_crow (1.2.2)
12
+ mime-types (>= 1)
13
+ multi_json (~> 1.0)
14
+ rest_client (~> 1.7)
15
+
16
+ GEM
17
+ remote: https://rubygems.org/
18
+ specs:
19
+ capistrano (3.2.1)
20
+ i18n
21
+ rake (>= 10.0.0)
22
+ sshkit (~> 1.3)
23
+ colorize (0.7.3)
24
+ i18n (0.6.11)
25
+ mime-types (2.4.3)
26
+ multi_json (1.10.1)
27
+ net-scp (1.2.1)
28
+ net-ssh (>= 2.6.5)
29
+ net-ssh (2.9.1)
30
+ netrc (0.7.7)
31
+ rake (10.3.2)
32
+ rest_client (1.7.3)
33
+ netrc (~> 0.7.7)
34
+ sshkit (1.5.1)
35
+ colorize
36
+ net-scp (>= 1.1.2)
37
+ net-ssh (>= 2.8.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bundler
44
+ chatty_crow!
45
+ chattycrow_capistrano_notifications!
46
+ rake
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 ChattyCrow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.textile ADDED
@@ -0,0 +1,37 @@
1
+ !https://avatars1.githubusercontent.com/u/9012750?v=3&s=200!
2
+
3
+ h1. ChattyCrow - Capistrano deploy notifications library
4
+
5
+ h2. Installation
6
+
7
+ <pre>
8
+ # Add to your gemfile
9
+ gem 'chattycrow_capistrano_notifications', '~> 1.0.0'
10
+ bundle install
11
+ </pre>
12
+
13
+ h2. Using
14
+
15
+ <pre>
16
+ # Capfile
17
+ require 'capistrano/chatty_crow/notifications'
18
+ </pre>
19
+
20
+ <pre>
21
+ # config/deploy.rb
22
+ set :chattycrow_host, 'https://chattycrow.com/api/v1' # This is default, it's not required
23
+ set :chattycrow_token, 'token'
24
+ set :chattycrow_services, {
25
+ jabber: { channel: 'channel#token', contacts: %w(abc def ghi) },
26
+ hipchat: { channel: 'channel#hipchat', color: :auto, notify: true }
27
+ }
28
+ </pre>
29
+
30
+ **If you put color :auto or you don't fill color settings on hipchat and slack, it will be formatted automatically.**
31
+
32
+ h2. Contribution
33
+
34
+ * Fork
35
+ * Create new branch
36
+ * Add your hacks or features
37
+ * Create pull request
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
+ # Pavel Lazureykis<lazureykis@gmail.com> is original author of Capistrano-Jabber notification gem
5
+ # This gem was something like fork, maybe bootstrap for notifications
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chattycrow_capistrano_notifications"
8
+ spec.version = '0.0.1'
9
+ spec.authors = ["NetBrick"]
10
+ spec.email = ["info@netbrick.eu", "jan.strnadek@gmail.com"]
11
+ spec.description = %q{Sending notifications about deploy via chattycrow service}
12
+ spec.summary = %q{Sending notifications about deploy via chattycrow service}
13
+ spec.homepage = "https://chattycrow.com/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'capistrano', '~> 3.1'
21
+ spec.add_dependency 'chatty_crow', '>= 1.3.1'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rake'
25
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path("../../tasks/chatty_crow/notifications.rake", __FILE__)
@@ -0,0 +1 @@
1
+ require 'capistrano/chatty_crow/notifications'
@@ -0,0 +1,172 @@
1
+ require 'chattycrow'
2
+
3
+ module Capistrano
4
+ module ChattyCrow
5
+ module Notifications
6
+ class << self
7
+ attr_accessor :options
8
+
9
+ def deploy_started
10
+ send_cc "deploy"
11
+ end
12
+
13
+ def deploy_completed
14
+ send_cc "deploy", true
15
+ end
16
+
17
+ def rollback_started
18
+ send_cc "deploy:rollback"
19
+ end
20
+
21
+ def rollback_completed
22
+ send_cc "deploy:rollback", true
23
+ end
24
+
25
+ private
26
+
27
+ def git_log_revisions
28
+ current, real = options[:current_revision][0,7], options[:previous_revision]
29
+
30
+ if current == real
31
+ "GIT: No changes ..."
32
+ else
33
+ if (diff = `git log #{real}..#{current} --pretty=format:"%h%x09%an%x09%ad%x09%s"`) != ""
34
+ diff = " " << diff.gsub("\n", "\n ") << "\n"
35
+ else
36
+ "GIT: Git-log problem ..."
37
+ end
38
+ end
39
+ end
40
+
41
+ def normal_log(action, completed)
42
+ msg = []
43
+ msg << "#{completed ? 'Completed' : 'Started'} #{action} on #{options[:stage]} by #{username}"
44
+ msg << "Time: #{Time.now.to_s}"
45
+ msg << "Application: #{options[:application]}"
46
+ msg << "Branch: #{options[:branch]}"
47
+ msg << "\nGit changes:\n" + git_log_revisions if options[:source].to_sym == :git
48
+ msg.join("\r\n")
49
+ end
50
+
51
+ def create_message(action, completed, type, settings)
52
+ case type
53
+ when :slack
54
+ if action.to_sym == :deploy
55
+ color = completed ? :good : :warning
56
+ else
57
+ color = :danger
58
+ end
59
+
60
+ # Return
61
+ payload = {
62
+ icon: ':floppy_disk:',
63
+ body: "#{completed ? 'Completed' : 'Started'} #{action} #{options[:application]} on #{options[:stage]}:",
64
+ attachments: [
65
+ color: color,
66
+ fallback: "Author: #{username}, Branch: #{options[:branch]}, Time: #{Time.now.to_s}",
67
+ fields: [
68
+ { title: 'Author', value: username, short: true },
69
+ { title: 'Branch', value: options[:branch], short: true },
70
+ { title: 'Time', value: Time.now.to_s, short: true },
71
+ { title: 'Stage', value: options[:stage], short: true },
72
+ { title: 'Changes', value: git_log_revisions }
73
+ ]
74
+ ]
75
+ }
76
+ settings.dup.merge(payload)
77
+ when :hipchat
78
+ if action.to_sym == :deploy
79
+ color = completed ? :green : :yellow
80
+ else
81
+ color = :red
82
+ end
83
+
84
+ payload = {
85
+ body: normal_log(action, completed),
86
+ notify: true,
87
+ color: color
88
+ }
89
+ settings.dup.merge(payload)
90
+ else
91
+ normal_log(action, completed)
92
+ end
93
+ end
94
+
95
+ def send_cc(action, completed = false)
96
+ # Prepare batches
97
+ ::ChattyCrow.configure do |config|
98
+ config.host = options[:host]
99
+ config.token = options[:token]
100
+ end
101
+
102
+ # Create batch
103
+ batch = ::ChattyCrow.create_batch(options[:token])
104
+
105
+ # Iterate over services
106
+ options[:services].each do |type, settings|
107
+ message = create_message(action, completed, type, settings)
108
+
109
+ if message.is_a?(String)
110
+ batch.send("add_#{type}", message, settings.dup)
111
+ else
112
+ batch.send("add_#{type}", message)
113
+ end
114
+ end
115
+
116
+ # Execute!
117
+ response = batch.execute!
118
+
119
+ puts "REsponse: #{response.channels}"
120
+ true
121
+ end
122
+
123
+ def username
124
+ @username ||= [`whoami`, `hostname`].map(&:strip).join('@')
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ set :current_revision, lambda { `git rev-parse #{fetch :branch}`.chomp }
132
+
133
+ namespace :deploy do
134
+ namespace :chatty_crow do
135
+ %w(deploy_started deploy_completed rollback_started rollback_completed).each do |m|
136
+
137
+
138
+ task m.to_sym do
139
+ # Run only once!
140
+ unless fetch(:revision)
141
+ on roles(:app, :web) do |host|
142
+ within current_path do
143
+ set :revision, capture(:cat, "REVISION")
144
+ end
145
+ end
146
+ end
147
+
148
+ Capistrano::ChattyCrow::Notifications.options = {
149
+ host: fetch(:chattycrow_host),
150
+ token: fetch(:chattycrow_token),
151
+ services: fetch(:chattycrow_services),
152
+ action: m.to_sym,
153
+ branch: fetch(:branch),
154
+ application: fetch(:application),
155
+ stage: fetch(:stage),
156
+ source: fetch(:scm),
157
+ current_revision: fetch(:current_revision),
158
+ previous_revision: fetch(:revision)
159
+ }
160
+
161
+ Capistrano::ChattyCrow::Notifications.send m
162
+ end
163
+ end
164
+ end
165
+
166
+ # Deploy tasks
167
+ before 'deploy', 'deploy:chatty_crow:deploy_started'
168
+ after 'deploy', 'deploy:chatty_crow:deploy_completed'
169
+ before 'deploy:rollback', 'deploy:chatty_crow:rollback_started'
170
+ after 'deploy:rollback', 'deploy:chatty_crow:rollback_completed'
171
+ end
172
+
@@ -0,0 +1 @@
1
+ # Empty file for bundle require
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chattycrow_capistrano_notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - NetBrick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chatty_crow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.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: 1.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: '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
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Sending notifications about deploy via chattycrow service
70
+ email:
71
+ - info@netbrick.eu
72
+ - jan.strnadek@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE
81
+ - README.textile
82
+ - Rakefile
83
+ - chattycrow_capistrano_notifications.gemspec
84
+ - lib/capistrano/chatty_crow/notifications.rb
85
+ - lib/capistrano/chattycrow_notifications.rb
86
+ - lib/capistrano/tasks/chatty_crow/notifications.rake
87
+ - lib/chattycrow_capistrano_notifications.rb
88
+ homepage: https://chattycrow.com/
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.3
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Sending notifications about deploy via chattycrow service
112
+ test_files: []
113
+ has_rdoc: