capistrano-slackify 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6efe9edb2bfae9ed432763cc512c2dd71d87779f
4
- data.tar.gz: 76eced927e78e318647d365931fb86dd891a0268
3
+ metadata.gz: 72c70783267c99964abf6c5b5d46fd4c0a86b53b
4
+ data.tar.gz: 01dfb51af25a60985be5d4610a027a8def26da01
5
5
  SHA512:
6
- metadata.gz: aa01862a635434cdaf6edd3174c33d08ef29a6294938430d569b90f7e3745a266f04983a3ccce4d71902567ca3e80f1b1d5e2a2d84e452e3e37bd2611a15813e
7
- data.tar.gz: 9715200f4b82f656b7e5023171d8a0ef98577e4e433f0a26597cc641ff313d15701f214960044ce935c02646479323dadf28a33135a180363e373a39e4895700
6
+ metadata.gz: dc8c4b670d23ea8c00fc5ce4627b3a72b4c00bd7734fe41714abd86be682f83b7951a9c053a67534cdd9c6abf4e3dc4bd1264ee13306353c38a5e538f37d3a8c
7
+ data.tar.gz: dcf88932ef185745b734fde410beeeaa23d5d61443ece1647db293ea8b5d356dfb58faeddf7e859706a5bf2cb0ef0b9e9f6e71c852903b98e41c7c33e64df068
data/README.md CHANGED
@@ -69,6 +69,8 @@ Any of the defaults can be over-ridden in `config/deploy.rb`:
69
69
  set :slack_deploy_failed_text, -> {
70
70
  "#{fetch(:stage)} deploy of #{fetch(:application)} with revision/branch #{fetch(:current_revision, fetch(:branch))} failed"
71
71
  }
72
+ set :slack_deploy_finished_color, 'good'
73
+ set :slack_deploy_failed_color, 'danger'
72
74
 
73
75
  To configure the way slack parses your message (see 'Parsing Modes' at https://api.slack.com/docs/formatting) use the `:slack_parse` setting:
74
76
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano-slackify'
7
- spec.version = '2.2.0'
7
+ spec.version = '2.3.0'
8
8
  spec.authors = ['seenmyfate']
9
9
  spec.email = ['seenmyfate@gmail.com']
10
10
  spec.summary = %q{Publish deployment notifications to Slack via the incoming webhooks integration}
@@ -5,8 +5,14 @@ namespace :slack do
5
5
  run_locally do
6
6
  info 'Notifying Slack of deploy starting'
7
7
  set :time_started, Time.now.to_i
8
+
9
+ payload = Slackify::Payload.build self do |default, context|
10
+ default[:text] = fetch(:slack_deploy_starting_text)
11
+ default
12
+ end
13
+
8
14
  execute :curl, '-X POST', '--data-urlencode',
9
- Slackify::Payload.build(self, fetch(:slack_deploy_starting_text)),
15
+ payload,
10
16
  fetch(:slack_url)
11
17
  end
12
18
  end
@@ -18,8 +24,43 @@ namespace :slack do
18
24
  run_locally do
19
25
  info 'Notifying Slack of deploy finished'
20
26
  set :time_finished, Time.now.to_i
27
+
28
+ payload = Slackify::Payload.build self do |default, context|
29
+ text = fetch(:slack_text)
30
+ default[:attachments] = [
31
+ {
32
+ fallback: text,
33
+ color: fetch(:slack_deploy_finished_color),
34
+ text: text,
35
+ fields: [
36
+ {
37
+ title: 'Status',
38
+ value: 'success',
39
+ short: true
40
+ },
41
+ {
42
+ title: 'Stage',
43
+ value: fetch(:stage),
44
+ short: true
45
+ },
46
+ {
47
+ title: 'Branch',
48
+ value: fetch(:branch),
49
+ short: true
50
+ },
51
+ {
52
+ title: 'Revision',
53
+ value: fetch(:current_revision),
54
+ short: true
55
+ },
56
+ ]
57
+ }
58
+ ]
59
+ default
60
+ end
61
+
21
62
  execute :curl, '-X POST', '--data-urlencode',
22
- Slackify::Payload.build(self, fetch(:slack_text)),
63
+ payload,
23
64
  fetch(:slack_url)
24
65
  end
25
66
  end
@@ -31,8 +72,43 @@ namespace :slack do
31
72
  run_locally do
32
73
  info 'Notifying Slack of deploy failed'
33
74
  set :time_finished, Time.now.to_i
75
+
76
+ payload = Slackify::Payload.build self do |default, context|
77
+ text = fetch :slack_deploy_failed_text
78
+ default[:attachments] = [
79
+ {
80
+ fallback: text,
81
+ color: fetch(:slack_deploy_failed_color),
82
+ text: text,
83
+ fields: [
84
+ {
85
+ title: 'Status',
86
+ value: 'failed',
87
+ short: true
88
+ },
89
+ {
90
+ title: 'Stage',
91
+ value: fetch(:stage),
92
+ short: true
93
+ },
94
+ {
95
+ title: 'Branch',
96
+ value: fetch(:branch),
97
+ short: true
98
+ },
99
+ {
100
+ title: 'Revision',
101
+ value: fetch(:current_revision),
102
+ short: true
103
+ },
104
+ ]
105
+ }
106
+ ]
107
+ default
108
+ end
109
+
34
110
  execute :curl, '-X POST', '--data-urlencode',
35
- Slackify::Payload.build(self, fetch(:slack_deploy_failed_text)),
111
+ payload,
36
112
  fetch(:slack_url)
37
113
  end
38
114
  end
@@ -49,15 +125,16 @@ namespace :load do
49
125
  set :slack_url, -> { fail ':slack_url is not set' }
50
126
  set :slack_text, lambda {
51
127
  time_elapsed = Integer(fetch(:time_finished) - fetch(:time_started))
52
- "Revision #{fetch(:current_revision, fetch(:branch))} of " \
53
- "#{fetch(:application)} deployed to #{fetch(:stage)} by #{fetch(:slack_user)} " \
128
+ "#{fetch(:application)} deployed by #{fetch(:slack_user)} " \
54
129
  "in #{time_elapsed} seconds."
55
130
  }
56
131
  set :slack_deploy_starting_text, -> {
57
132
  "#{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}"
58
133
  }
59
134
  set :slack_deploy_failed_text, -> {
60
- "#{fetch(:stage)} deploy of #{fetch(:application)} with revision/branch #{fetch(:current_revision, fetch(:branch))} failed"
135
+ "deploy of #{fetch(:application)}"
61
136
  }
137
+ set :slack_deploy_finished_color, 'good'
138
+ set :slack_deploy_failed_color, 'danger'
62
139
  end
63
140
  end
@@ -3,29 +3,28 @@ require 'multi_json'
3
3
  module Slackify
4
4
  class Payload
5
5
 
6
- attr_reader :text
7
- protected :text
8
-
9
- def initialize(context, text)
10
- @context, @text = context, text
6
+ def initialize(context)
7
+ @context = context
11
8
  end
12
9
 
13
- def self.build(context, text)
14
- new(context, text).build
10
+ def self.build(context, &block)
11
+ new(context).build(&block)
15
12
  end
16
13
 
17
- def build
18
- "'payload=#{payload}'"
14
+ def build(&block)
15
+ "'payload=#{payload(&block)}'"
19
16
  end
20
17
 
21
- def payload
22
- MultiJson.dump({
18
+ def payload(&block)
19
+ default = {
23
20
  channel: fetch(:slack_channel),
24
21
  username: fetch(:slack_username),
25
- text: text,
26
22
  icon_emoji: fetch(:slack_emoji),
27
23
  parse: fetch(:slack_parse)
28
- })
24
+ }
25
+
26
+ json = yield(default, @context)
27
+ MultiJson.dump(json)
29
28
  end
30
29
 
31
30
  def fetch(*args, &block)
@@ -15,13 +15,20 @@ module Slackify
15
15
  }
16
16
 
17
17
  let(:payload) {
18
- %{'payload={"channel":"#general","username":"Capistrano","text":":boom:","icon_emoji":":ghost:","parse":"default"}'}
18
+ %{'payload={"channel":"#general","username":"Capistrano","icon_emoji":":ghost:","parse":"default","text":":boom:"}'}
19
19
  }
20
20
 
21
21
  let(:text) { context.fetch(:slack_text) }
22
22
 
23
+ let(:builded_payload) {
24
+ Payload.build context do |default, context|
25
+ default[:text] = text
26
+ default
27
+ end
28
+ }
29
+
23
30
  it 'returns the payload with the specified text' do
24
- expect(Payload.build(context, text)).to eq payload
31
+ expect(builded_payload).to eq payload
25
32
  end
26
33
 
27
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-slackify
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - seenmyfate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-05 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.4.2
124
+ rubygems_version: 2.4.5
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Publish deployment notifications to Slack via the incoming webhooks integration