capistrano-notifications 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: 7206bacffdeab09b3d57eeb83820a09923c2aa90
4
+ data.tar.gz: 46e25ffe6c17e06b479dc6756ce552460725a723
5
+ SHA512:
6
+ metadata.gz: c135f5e6cde1151e1b4096aa77540d126afeb11351a57252a5482af6912c2ebfe1ab03c5f78899d38f81dfeb5ca6de4dcd35e6795324a5b7fc6a42cab991c360
7
+ data.tar.gz: c53393e19861dd3390d3d0c4c14cc0712c2597a8fb017dfb6d0639a213cb9574d184ce59cb41a72a95de07c9a6bef36ec0d90734792ba0cd055ab8d35dcb0115
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
15
+
16
+ .ruby-version
17
+ .ruby-gemset
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano_notifications.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 scorix
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,45 @@
1
+ # Capistrano::Notifications
2
+
3
+ Send notifications around deploy to teammates(subscribers).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'capistrano-notifications', github: 'scorix/capistrano-notifications'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ ### Slack
20
+
21
+ in deploy.rb
22
+
23
+ ```ruby
24
+ # deploy.rb
25
+ set :notify_default_options, team: 'my-team', token: 'token'
26
+ set :notify_adapter, :Slack
27
+ set :subscribers, %w(@scorix #deploy)
28
+ ```
29
+
30
+ in Capfile
31
+
32
+ ```ruby
33
+ # Capfile
34
+
35
+ require 'capistrano/notifications'
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/scorix/capistrano-notifications/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
45
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/notifications/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'capistrano-notifications'
8
+ spec.version = Capistrano::Notifications::VERSION
9
+ spec.authors = ['scorix']
10
+ spec.email = ['scorix@gmail.com']
11
+ spec.summary = %q{Capistrano notifications.}
12
+ spec.description = %q{Send deploy notifications to subscribers.}
13
+ spec.homepage = ''
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_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'capistrano', '~> 3.3.5'
24
+
25
+ spec.add_dependency 'faraday'
26
+ end
@@ -0,0 +1,27 @@
1
+ module Capistrano
2
+ module Notifications
3
+ module Adapter
4
+ class Base
5
+
6
+ def self.setup(*args)
7
+ options = args.last.is_a?(Hash) ? args.last : {}
8
+
9
+ instance = self.new
10
+ options.each { |k, v| instance.instance_variable_set("@#{k}", v) }
11
+ instance
12
+ end
13
+
14
+ def notify(members = [], message = '')
15
+ members.each { |member| send_notification(member, message) }
16
+ end
17
+
18
+ protected
19
+
20
+ def send_notification(_member, _message)
21
+ raise NoMethodError, 'send_notification is not defined.'
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,33 @@
1
+ module Capistrano
2
+ module Notifications
3
+ module Adapter
4
+ class Slack < Base
5
+
6
+ attr_reader :team, :token
7
+
8
+ protected
9
+ def send_notification(_member, _message)
10
+ connection = Faraday.new(url: "https://#{team}.slack.com") do |faraday|
11
+ faraday.request :url_encoded
12
+ faraday.adapter Faraday.default_adapter
13
+ end
14
+ connection.post do |req|
15
+ req.url '/services/hooks/incoming-webhook'
16
+ req.headers['User-Agent'] = "Capistrano Notification #{Capistrano::Notifications::VERSION}"
17
+ req.body = {
18
+ token: token,
19
+ payload: {
20
+ channel: "#{_member}",
21
+ username: "#{fetch(:application)} #{fetch(:env)}",
22
+ text: _message,
23
+ icon_emoji: ':grin:',
24
+ mrkdwn: true
25
+ }.to_json
26
+ }
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ module Capistrano
2
+ module Notifications
3
+ module Adapter
4
+ autoload :Base, 'capistrano/notifications/adapter/base'
5
+ autoload :Slack, 'capistrano/notifications/adapter/slack'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Notifications
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Capistrano
5
+ module Notifications
6
+ autoload :Adapter, 'capistrano/notifications/adapter'
7
+ end
8
+ end
9
+
10
+ load File.expand_path('../tasks/notifications.rake', __FILE__)
@@ -0,0 +1,92 @@
1
+ #
2
+ # adapters:
3
+ #
4
+ # * Slack
5
+ #
6
+ # example:
7
+ #
8
+ # set :notify_adapter, :Slack
9
+ #
10
+ set :notify_adapter, -> { nil }
11
+
12
+ #
13
+ # default options:
14
+ #
15
+ # * Slack:
16
+ #
17
+ # team **required**
18
+ #
19
+ # token **required**
20
+ #
21
+ # example:
22
+ #
23
+ # set :notify_default_options, team: 'my-team', token: 'token'
24
+ #
25
+ set :notify_default_options, -> { {} }
26
+
27
+ #
28
+ # subscribers
29
+ #
30
+ # * Slack:
31
+ #
32
+ # subscribers could be a user, or a channel
33
+ #
34
+ # example:
35
+ #
36
+ # set :subscribers, -> { ['@scorix', '#deploy'] }
37
+ #
38
+ set :subscribers, -> { [] }
39
+
40
+ namespace :notify do
41
+
42
+ def find_adapter
43
+ adapter = fetch(:notify_adapter, nil)
44
+
45
+ if adapter
46
+ adapter = Capistrano::Notifications::Adapter.const_get(adapter.to_sym).setup(fetch(:notify_default_options))
47
+
48
+ begin
49
+ yield adapter
50
+ rescue => e
51
+ warn e.message
52
+ end
53
+ end
54
+ end
55
+
56
+ task :starting do
57
+ find_adapter do |adapter|
58
+ adapter.notify(fetch(:subscribers), "@#{local_user} is deploying branch #{fetch(:branch)}")
59
+ end
60
+ end
61
+
62
+ task :finishing do
63
+ find_adapter do |adapter|
64
+ adapter.notify(fetch(:subscribers), t(:revision_log_message,
65
+ branch: fetch(:branch),
66
+ user: "@#{local_user}",
67
+ sha: fetch(:current_revision),
68
+ release: fetch(:release_timestamp)))
69
+ end
70
+ end
71
+
72
+ task :log_revision do
73
+ on primary(:app) do
74
+ previous_revision = nil
75
+
76
+ within releases_path do
77
+ previous_revision = capture(:grep, "deployed #{revision_log} | tail -n 1 | cut -f1 -d')' | cut -f4 -d' '")
78
+ end
79
+
80
+ within repo_path do
81
+ git_log = capture(:git, "log --oneline --no-color #{fetch(:branch)} #{previous_revision}..#{fetch(:current_revision)} | sed 's/^M$//'")
82
+ set(:git_log, git_log)
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+
89
+ before 'deploy:log_revision', 'notify:log_revision'
90
+ before 'deploy:starting', 'notify:starting'
91
+
92
+ after 'deploy:finishing', 'notify:finishing'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-notifications
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - scorix
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.3.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.3.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Send deploy notifications to subscribers.
70
+ email:
71
+ - scorix@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-notifications.gemspec
82
+ - lib/capistrano/notifications.rb
83
+ - lib/capistrano/notifications/adapter.rb
84
+ - lib/capistrano/notifications/adapter/base.rb
85
+ - lib/capistrano/notifications/adapter/slack.rb
86
+ - lib/capistrano/notifications/version.rb
87
+ - lib/capistrano/tasks/notifications.rake
88
+ homepage: ''
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.5
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Capistrano notifications.
112
+ test_files: []