capistrano-ikachan 0.0.4 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ff10ed9721ce67c71f6b384fb095b068a533b33
4
- data.tar.gz: fc9de388017a828448904f1f36b3c68505be3244
3
+ metadata.gz: db9f4529272f7182ceda62babd36a3be5b48e7a8
4
+ data.tar.gz: 59c9920b5932cf27929fb235e2a5170cd57edeea
5
5
  SHA512:
6
- metadata.gz: ff42f490814ee20982d054d2029d631ad09fbc689bc623cd060a3bc485c3ab3946a3c6a5d931196b558c2c9193093b7c43754776e9f1ba9bc689dfdb5341d6f1
7
- data.tar.gz: bee1f10f0bb536d88e42f6fc6625a51083b1c49ed603ce2acfe3b99648f56ed06a9652422cb69be9dadc57e816ffba22f702abd1d77e5754f2c5152eec6f6f2a
6
+ metadata.gz: 05301318446a69aec69e83697a90f44e49c2b2d98e00304793775ebd7aa5e1dc14565f335f6d0fc9be9eb224d6f3bb558e4b80734eb7c4a295cf0d765e3e45ef
7
+ data.tar.gz: 94041aa5f0af06bffd96f3b05953430c9b64e5d1a65979e6d89fb10a7d8164b609bac983ea1b4f4d2e339ad7d8a584b20c21495290ae461d1c61b01d0098f344
data/README.md CHANGED
@@ -4,7 +4,7 @@ Capistrano::Ikachan
4
4
  [![Gem Version](https://badge.fury.io/rb/capistrano-ikachan.png)][gem]
5
5
  [gem]: https://rubygems.org/gems/capistrano-ikachan
6
6
 
7
- Irc notification tasks by The Ikachan for Capistrano v3.
7
+ Irc notification tasks with Ikachan for Capistrano v3.
8
8
 
9
9
  Installation
10
10
  ------------
@@ -42,9 +42,9 @@ config.rb:
42
42
  set ikachan_channel, 'ikachan'
43
43
  set ikachan_server, 'http://ikachan.example.com'
44
44
 
45
- after 'deploy:starting', 'ikachan:notify_start'
46
- after 'deploy:finishing', 'ikachan:notify_success'
47
- after 'deploy:finishing_rollback', 'ikachan:notify_failure'
45
+ after 'deploy:started', 'ikachan:notify_start'
46
+ after 'deploy:finishing', 'ikachan:notify_deployment'
47
+ after 'deploy:finishing_rollback', 'ikachan:notify_rollback'
48
48
  ```
49
49
 
50
50
  Contributing
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Ikachan
3
- VERSION = '0.0.4'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -1,65 +1,109 @@
1
1
  require 'string-irc'
2
+ require 'digest/md5'
2
3
 
3
4
  namespace :ikachan do
4
5
  start = Time.now
6
+ elapsed_time = -> { sprintf('%.2f', Time.now - start) }
5
7
 
6
8
  set :ikachan_channel, 'ikachan'
7
9
  set :ikachan_server, 'http://ikachan.example.com'
8
- set :ikachan_message_type, 'notice'
10
+ set :ikachan_message_type, :notice
9
11
 
10
- set :username, -> {
12
+ set :ikachan_username, -> {
11
13
  username = `git config --get user.name`.strip
12
14
  username = `whoami`.strip unless username
13
15
  username
14
16
  }
15
17
 
16
- set :start_icon, -> { StringIrc.new('✔').orange.to_s }
17
- set :failure_icon, -> { StringIrc.new('✘').red.to_s }
18
- set :success_icon, -> { StringIrc.new('✔').light_green.to_s }
18
+ set :ikachan_start_icon, -> { StringIrc.new('✔').yellow }
19
+ set :ikachan_failure_icon, -> { StringIrc.new('✘').red }
20
+ set :ikachan_success_icon, -> { StringIrc.new('✔').light_green }
19
21
 
20
- set :destination, -> {
22
+ set :ikachan_stage, -> {
21
23
  stage = "#{fetch(:stage)}"
22
24
  color = case stage
23
25
  when 'production' then :rainbow
24
- when 'staging' then :light_blue
25
- when 'sandbox' then :yellow
26
+ when 'staging' then :aqua
27
+ when 'sandbox' then :pink
26
28
  when 'development' then :purple
27
- else :grey
29
+ else :light_blue
28
30
  end
29
31
  StringIrc.new(stage).send(color)
30
32
  }
31
33
 
34
+ set :ikachan_appname, -> {
35
+ app = fetch(:application)
36
+
37
+ magic_number = Digest::MD5.hexdigest(app).
38
+ gsub(/[^0-9]/, '').split('').last.to_i
39
+
40
+ colors = StringIrc::COLOR_TABLE.select { |k,v|
41
+ 2 < k && k < 13 && k != 4 && k != 13
42
+ }.map { |k,v| v.last }
43
+ color = colors[magic_number].to_sym
44
+
45
+ StringIrc.new(app).send(color)
46
+ }
47
+
32
48
  set :ikachan_start_message, -> {
33
- "#{fetch(:application)}: #{fetch(:start_icon)} started deploying to #{fetch(:destination)} of #{fetch(:branch)} by #{fetch(:username)}"
49
+ <<-MSG.gsub(/\s+/, ' ')
50
+ #{fetch(:ikachan_appname)}: #{fetch(:ikachan_start_icon)} started deploying
51
+ to #{fetch(:ikachan_stage)} by #{fetch(:ikachan_username)}
52
+ (branch #{fetch(:branch)})
53
+ MSG
34
54
  }
35
55
 
36
56
  set :ikachan_failure_message, -> {
37
- elapse_time = "(#{sprintf('%.2f', Time.now - start)} sec)"
38
- "#{fetch(:application)}: #{fetch(:failure_icon)} failed deploying to #{fetch(:destination)} of #{fetch(:branch)} by #{fetch(:username)} #{elapse_time}"
57
+ <<-MSG.gsub(/\s+/, ' ')
58
+ #{fetch(:ikachan_appname)}: #{fetch(:ikachan_failure_icon)} failed deploying
59
+ to #{fetch(:ikachan_stage)} by #{fetch(:ikachan_username)}
60
+ (branch #{fetch(:branch)} at #{fetch(:current_revision)} / #{elapsed_time.call} sec)
61
+ MSG
39
62
  }
40
63
 
41
64
  set :ikachan_success_message, -> {
42
- elapse_time = "(#{sprintf('%.2f', Time.now - start)} sec)"
43
- "#{fetch(:application)}: #{fetch(:success_icon)} successful deployment to #{fetch(:destination)} of #{fetch(:branch)} by #{fetch(:username)} #{elapse_time}"
65
+ task = fetch(:deploying) ? 'deployment' : 'rollback'
66
+ <<-MSG.gsub(/\s+/, ' ')
67
+ #{fetch(:ikachan_appname)}: #{fetch(:ikachan_success_icon)} successful #{task}
68
+ to #{fetch(:ikachan_stage)} by #{fetch(:ikachan_username)}
69
+ (branch #{fetch(:branch)} at #{fetch(:current_revision)} / #{elapsed_time.call} sec)
70
+ MSG
44
71
  }
45
72
 
46
- def notify_to_ikachan(message)
73
+ def notify_with_ikachan(message)
47
74
  channel = fetch(:ikachan_channel)
48
75
  host = fetch(:ikachan_server)
49
76
  type = fetch(:ikachan_message_type)
50
- `curl -s -F channel=\##{channel} #{host}/join`
51
- `curl -s -F channel=\##{channel} -F message="#{message}" #{host}/#{type}`
77
+
78
+ run_locally do
79
+ execute :curl, '-s',
80
+ "-F channel=\##{channel}",
81
+ "#{host}/join"
82
+ execute :curl, '-s',
83
+ "-F channel=\##{channel}",
84
+ "-F message=\"#{args[:message]}\"",
85
+ "#{host}/#{type}"
86
+ end
87
+ end
88
+
89
+ desc 'Notify message to IRC with Ikachan'
90
+ task :notify, :message do |t, args|
91
+ notify_with_ikachan args[:message]
52
92
  end
53
93
 
94
+ desc 'Notify start to IRC with Ikachan'
54
95
  task :notify_start do
55
- notify_to_ikachan fetch(:ikachan_start_message)
96
+ notify_with_ikachan fetch(:ikachan_start_message)
56
97
  end
57
98
 
58
- task :notify_failure do
59
- notify_to_ikachan fetch(:ikachan_failure_message)
99
+ desc 'Notify rollback to IRC with Ikachan'
100
+ task :notify_rollback do
101
+ message = fetch(:deploying) ? :ikachan_failure_message : :ikachan_success_message
102
+ notify_with_ikachan fetch(message)
60
103
  end
61
104
 
62
- task :notify_success do
63
- notify_to_ikachan fetch(:ikachan_success_message)
105
+ desc 'Notify deployment to IRC with Ikachan'
106
+ task :notify_deployment do
107
+ notify_with_ikachan fetch(:ikachan_success_message)
64
108
  end
65
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-ikachan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linyows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-irc