talking-capistrano 0.0.4 → 0.1.2

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.
data/Gemfile CHANGED
@@ -4,3 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "capistrano"
7
+ gem "skypemac"
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Talking::Capistrano
2
2
 
3
3
  Capisrano task to notify start|end|erros of a capistrano deploy execution
4
+ Current Notification methods supported:
5
+ *. Skype Group - via some topic
6
+ *. speaker voice - via OSX's `say` command
4
7
 
5
- * Current code is based on thr `say` command in OSX, espeak can also be used, however, I didn't bother yet. PR always welcome
8
+ * Current code is based on the `say` command in OSX and the 'skypemac' gem, espeak can also be used, however, I didn't bother yet. PR always welcome
6
9
 
7
10
  ## Installation
8
11
 
@@ -24,7 +27,14 @@ Simply add:
24
27
 
25
28
  require 'talking-capistrano'
26
29
 
27
- In your deploy.rb, enjoy
30
+ In your Capfile, enjoy
31
+
32
+ To get the Skype Notification to kick in, simply add, in the deploy.rb file (or the specific environment, eg. production.rb):
33
+
34
+ set :skype_topic, "Production Team"
35
+
36
+ This will kick a search on the Skype chats with this as the topic, and will send a mesage to that group.
37
+ If topic not found, it will simply be ignored.
28
38
 
29
39
  ## Contributing
30
40
 
@@ -0,0 +1,41 @@
1
+ class SkypeScriptInvoker
2
+
3
+ attr_accessor :target_chat_id
4
+
5
+ @@SCRIPT_PATH = File.join(File.dirname(__FILE__), "../scripts/")
6
+
7
+ def initialize(topic)
8
+ ## Initilize the chat_id
9
+ @target_chat_id = get_chat_id_for_topic topic
10
+ end
11
+
12
+ def get_chats
13
+ `osascript #{@@SCRIPT_PATH}skype_get_chats.APPLESCRIPT`
14
+ end
15
+
16
+ def get_topic_for_chat(chat_id)
17
+ `osascript #{@@SCRIPT_PATH}skype_get_topic_for_chat.APPLESCRIPT '#{chat_id}'`
18
+ end
19
+
20
+ def get_chat_id_for_topic(target_topic ="dummy_stuff")
21
+
22
+ found_chat_id = nil
23
+ chats = get_chats
24
+ chats.gsub! "CHATS ", ""
25
+
26
+ chats.split(",").each do |chat_id|
27
+ details = (get_topic_for_chat chat_id).chomp.split("TOPIC ")
28
+ topic = details[1].chomp if details.size > 1
29
+ found_chat_id = chat_id if topic == target_topic
30
+ end
31
+
32
+ found_chat_id
33
+ end
34
+
35
+ def send_message(message)
36
+ `osascript #{@@SCRIPT_PATH}skype_send_message.APPLESCRIPT '#{@target_chat_id}' '#{message}'` unless @target_chat_id.nil?
37
+ #puts "Sending '#{@@target_chat_id}' '#{message}' " unless @target_chat_id.nil?
38
+ end
39
+
40
+
41
+ end
@@ -2,8 +2,7 @@
2
2
  "Agnes",
3
3
  "Albert",
4
4
  "Alex",
5
- "Bad",
6
- "News",
5
+ "Bad News",
7
6
  "Bahh",
8
7
  "Bells",
9
8
  "Boing",
@@ -24,7 +23,11 @@
24
23
  "Victoria",
25
24
  "Whisper",
26
25
  "Zarvox"],
27
- "say_deploy_completed": ["Deploying to - ENV - Completed!"],
28
- "say_deploy_failed": ["Oops, Deploying to - ENV - went kaakehn!"],
29
- "say_deploy_started": ["Deploying to - ENV - Yahllah!"]
26
+ "say_deploy_completed": ["Deploying to - [ENV] - Completed!"],
27
+ "say_deploy_failed": ["Oops, Deploying to - [ENV] - went kaakehn!",
28
+ "Oops, Deploying to - [ENV] - failed!",
29
+ "Deploy to [ENV] Fail - Fail - Fail !!"],
30
+ "say_deploy_started": ["Deploying to - [ENV]- Yalaa!",
31
+ "Deploying to - [ENV]!",
32
+ "[ENV] deploy is starting - Now!"]
30
33
  }
@@ -1,19 +1,51 @@
1
- require 'capistrano'
2
-
3
1
  require "talking-capistrano/version"
4
-
5
2
  require 'JSON'
6
3
 
7
4
  module TalkingCapistrano
5
+ module SkypeNotification
6
+
7
+ require 'skype_script_invoker'
8
+
9
+ class << self;
10
+ attr_accessor :topic;
11
+ end
12
+
13
+ def self.set_notify(topic_exist)
14
+ @notify = topic_exist
15
+ @topic = topic_exist if topic_exist
16
+ end
17
+ def self.notify?
18
+ @notify
19
+ end
20
+
21
+ def self.notify(text)
22
+ skyper = SkypeScriptInvoker.new(@topic)
23
+ skyper.send_message(pad_text text) unless @topic.nil?
24
+ end
25
+
26
+ def self.pad_text(text)
27
+ "TalkingCapistrano: #{text}"
28
+ end
29
+ end
30
+ end
31
+
32
+ module TalkingCapistrano
33
+
8
34
  @DATA_SET = JSON.load( File.read(File.join(File.dirname(__FILE__), '/talking-capistrano.json' )) )
9
- def self.say_deploy_started(rails_env ="unknown env")
10
- get_item(:say_deploy_started).sub! "ENV", rails_env
35
+
36
+ class << self;
37
+ attr_accessor :local_rails_env;
11
38
  end
12
- def self.say_deploy_completed(rails_env ="unknown env")
13
- get_item(:say_deploy_completed).sub! "ENV", rails_env
39
+
40
+ def self.say_deploy_started
41
+
42
+ get_item(:say_deploy_started).sub! "ENV", @local_rails_env
43
+ end
44
+ def self.say_deploy_completed
45
+ get_item(:say_deploy_completed).sub! "ENV", @local_rails_env
14
46
  end
15
- def self.say_deploy_failed(rails_env ="unknown env")
16
- get_item(:say_deploy_failed).sub! "ENV", rails_env
47
+ def self.say_deploy_failed
48
+ get_item(:say_deploy_failed).sub! "ENV", @local_rails_env
17
49
  end
18
50
  def self.say_speaker_name
19
51
  get_item(:voices)
@@ -23,16 +55,11 @@ module TalkingCapistrano
23
55
 
24
56
  def self.get_item(arr)
25
57
  @DATA_SET[arr.to_s].shuffle(random: Time.now.to_i).first
26
- end
58
+ end
27
59
  end
28
60
 
29
61
  ## In a capistrano scope
30
62
  Capistrano::Configuration.instance.load do
31
-
32
- set :speaker, TalkingCapistrano::say_speaker_name
33
- set :say_deploy_started, TalkingCapistrano::say_deploy_started(rails_env)
34
- set :say_deploy_completed, TalkingCapistrano::say_deploy_completed(rails_env)
35
- set :say_deploy_failed, TalkingCapistrano::say_deploy_failed(rails_env)
36
63
 
37
64
  set :say_command, "say"
38
65
 
@@ -40,17 +67,22 @@ Capistrano::Configuration.instance.load do
40
67
  namespace :deploy do
41
68
  namespace :say do
42
69
  task :about_to_deploy do
43
- `#{say_command} #{say_deploy_started} -v '#{speaker}' &`
70
+ `#{say_command} #{TalkingCapistrano::say_deploy_started} -v '#{TalkingCapistrano::say_speaker_name}' &`
44
71
  end
72
+ task :setup do
73
+ TalkingCapistrano.local_rails_env = rails_env
74
+ end
45
75
  end
46
76
  end
47
77
 
48
-
49
78
  #Overide capistrano code deploy, to add the on error hook, seems to not be called otherwise
50
79
  namespace :deploy do
51
80
  task :update_code, :except => { :no_release => true } do
52
81
  on_rollback do
53
- `#{say_command} #{say_deploy_failed} -v #{speaker} &`;
82
+ `#{say_command} #{TalkingCapistrano::say_deploy_failed} -v #{TalkingCapistrano::say_speaker_name} &`;
83
+ if TalkingCapistrano::SkypeNotification.notify?
84
+ TalkingCapistrano::SkypeNotification.notify(TalkingCapistrano::say_deploy_failed)
85
+ end
54
86
  run "rm -rf #{release_path}; true"
55
87
  end
56
88
  strategy.deploy!
@@ -58,11 +90,34 @@ Capistrano::Configuration.instance.load do
58
90
  end
59
91
  end
60
92
 
93
+ namespace :deploy do
94
+ namespace :skype_notifications do
95
+ task :setup do
96
+ TalkingCapistrano::SkypeNotification.set_notify(fetch(:skype_topic, false))
97
+ end
98
+ task :send_about_to_deploy do
99
+ if TalkingCapistrano::SkypeNotification.notify?
100
+ TalkingCapistrano::SkypeNotification.notify(TalkingCapistrano::say_deploy_started)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ #setup tasks for say and skype
107
+ before "deploy", "deploy:skype_notifications:setup"
108
+ before "deploy", "deploy:say:setup"
109
+
110
+ # Skype notifications on deploy stages
111
+ before "deploy", "deploy:skype_notifications:send_about_to_deploy"
61
112
 
62
113
  # Say notifications on deploy stages
63
114
  before "deploy", "deploy:say:about_to_deploy"
115
+ # Say + Skype notifications on deploy stages - hack to avoid stack too deep exception
64
116
  after "deploy" do
65
- `#{say_command} #{say_deploy_completed} -v '#{speaker}' &`
117
+ `#{say_command} #{TalkingCapistrano::say_deploy_completed} -v '#{TalkingCapistrano::say_speaker_name}' &`
118
+ if TalkingCapistrano::SkypeNotification.notify?
119
+ TalkingCapistrano::SkypeNotification.notify(TalkingCapistrano::say_deploy_completed)
120
+ end
66
121
  end
67
122
 
68
123
  end
@@ -1,5 +1,5 @@
1
1
  module Talking
2
2
  module Capistrano
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -0,0 +1,4 @@
1
+ tell application "Skype"
2
+ send command "SEARCH RECENTCHATS" script name "TalkingCapistrano"
3
+ --send command "CHATMESSAGE #bigimot60/$shai_ei;ecefc87ba7f22432 nana" script name "TalkingCapistrano"
4
+ end tell
@@ -0,0 +1,5 @@
1
+ on run argv
2
+ tell application "Skype"
3
+ send command "GET CHAT " & item 1 of argv & " TOPIC" script name "TalkingCapistrano"
4
+ end tell
5
+ end run
@@ -0,0 +1,5 @@
1
+ on run argv
2
+ tell application "Skype"
3
+ send command "CHATMESSAGE " & item 1 of argv & " " & item 2 of argv script name "TalkingCapistrano"
4
+ end tell
5
+ end run
@@ -14,6 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.files << "lib/talking-capistrano.json"
17
+ gem.files << "lib/skype_script_invoker.rb"
17
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
20
  gem.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talking-capistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-14 00:00:00.000000000 Z
12
+ date: 2013-01-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Capisrano task to notify start|end|erros of a capistrano deploy execution
15
15
  email:
@@ -23,9 +23,13 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - lib/skype_script_invoker.rb
26
27
  - lib/talking-capistrano.json
27
28
  - lib/talking-capistrano.rb
28
29
  - lib/talking-capistrano/version.rb
30
+ - scripts/skype_get_chats.APPLESCRIPT
31
+ - scripts/skype_get_topic_for_chat.APPLESCRIPT
32
+ - scripts/skype_send_message.APPLESCRIPT
29
33
  - talking-capistrano.gemspec
30
34
  homepage: https://github.com/fiverr/talking-capistrano.git
31
35
  licenses: []