capistrano-jabber-notifications 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in capistrano-jabber-notifications.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem "bundler"
8
+ gem "rake"
9
+ end
@@ -18,6 +18,5 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
21
+ spec.add_dependency 'xmpp4r', '=0.5'
23
22
  end
@@ -1,9 +1,88 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require 'xmpp4r'
4
+ require 'xmpp4r/roster/helper/roster'
1
5
  require "capistrano/jabber/notifications/version"
2
6
 
3
7
  module Capistrano
4
8
  module Jabber
5
9
  module Notifications
6
- # Your code goes here...
10
+
11
+ class << self
12
+
13
+ attr_accessor :options
14
+
15
+ def deploy_started(stage)
16
+ send_jabber_message("cap deploy #{stage} by :username started at #{Time.now}")
17
+ end
18
+
19
+ def deploy_completed(stage)
20
+ send_jabber_message("cap deploy #{stage} by :username completed at #{Time.now}")
21
+ end
22
+
23
+ def rollback_started(stage)
24
+ send_jabber_message("cap deploy:rollback #{stage} by :username started at #{Time.now}")
25
+ end
26
+
27
+ def rollback_completed(stage)
28
+ send_jabber_message("cap deploy:rollback #{stage} by :username completed at #{Time.now}")
29
+ end
30
+
31
+ private
32
+
33
+ def send_jabber_message(msg)
34
+ msg.gsub!(':username', username) if msg[':username']
35
+
36
+ client = ::Jabber::Client.new(options[:uid])
37
+ client.connect(options[:server])
38
+ client.auth(options[:password])
39
+ notification_group = options[:group]
40
+
41
+ roster = ::Jabber::Roster::Helper.new(client)
42
+
43
+ mainthread = Thread.current
44
+ roster.add_query_callback { |iq| mainthread.wakeup }
45
+ Thread.stop
46
+
47
+ roster.find_by_group(notification_group).each {|item|
48
+ client.send(item.jid)
49
+ m = ::Jabber::Message.new(item.jid, msg).set_type(:normal).set_id('1').set_subject('hi')
50
+ client.send(m)
51
+ }
52
+
53
+ client.close
54
+ true
55
+ end
56
+
57
+ def username
58
+ @username ||= [`whoami`, `hostname`].map(&:strip).join('@')
59
+ end
60
+ end
7
61
  end
8
62
  end
9
63
  end
64
+
65
+
66
+ Capistrano::Configuration.instance(:must_exist).load do
67
+
68
+ namespace :deploy do
69
+ namespace :jabber do
70
+ %w(deploy_started deploy_completed rollback_started rollback_completed).each do |m|
71
+ task m.to_sym do
72
+ Capistrano::Jabber::Notifications.options = {
73
+ uid: fetch(:jabber_uid),
74
+ server: fetch(:jabber_server),
75
+ password: fetch(:jabber_password),
76
+ group: fetch(:jabber_group)
77
+ }
78
+ Capistrano::Jabber::Notifications.send(m, fetch(:stage))
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ before 'deploy', 'deploy:jabber:deploy_started'
85
+ after 'deploy', 'deploy:jabber:deploy_completed'
86
+ before 'deploy:rollback', 'deploy:jabber:rollback_started'
87
+ after 'deploy:rollback', 'deploy:jabber:rollback_completed'
88
+ end
@@ -1,7 +1,7 @@
1
1
  module Capistrano
2
2
  module Jabber
3
3
  module Notifications
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-jabber-notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,37 +12,16 @@ cert_chain: []
12
12
  date: 2013-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: !ruby/object:Gem::Requirement
15
+ name: xmpp4r
16
+ requirement: &8732140 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - =
20
20
  - !ruby/object:Gem::Version
21
- version: '1.3'
22
- type: :development
21
+ version: '0.5'
22
+ type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '1.3'
30
- - !ruby/object:Gem::Dependency
31
- name: rake
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
24
+ version_requirements: *8732140
46
25
  description: Sending notifications about deploy to jabber
47
26
  email:
48
27
  - lazureykis@gmail.com
@@ -73,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
52
  version: '0'
74
53
  segments:
75
54
  - 0
76
- hash: 4428856003910704509
55
+ hash: 2971062857575580786
77
56
  required_rubygems_version: !ruby/object:Gem::Requirement
78
57
  none: false
79
58
  requirements:
@@ -82,10 +61,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
61
  version: '0'
83
62
  segments:
84
63
  - 0
85
- hash: 4428856003910704509
64
+ hash: 2971062857575580786
86
65
  requirements: []
87
66
  rubyforge_project:
88
- rubygems_version: 1.8.25
67
+ rubygems_version: 1.8.11
89
68
  signing_key:
90
69
  specification_version: 3
91
70
  summary: Sending notifications about deploy to jabber