capistrano-slackify 2.8.0 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/capistrano-slackify.gemspec +1 -1
- data/lib/capistrano/tasks/slackify.cap +1 -0
- data/lib/slackify.rb +38 -25
- data/spec/lib/slackify_spec.rb +16 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c1ce687a6a8d75cb09a1d5f1e1b4011548cb9c7
|
4
|
+
data.tar.gz: 333a05e6aeb30849c73484471ab1e7bc0a35aff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bf327f9e7abea13eecffffb4ce555565ba006825c644c77010075553645117255bb00886a367d67d097b54ff1a845768c126a93435254a3244476819580a50f
|
7
|
+
data.tar.gz: 1af5d9defc5846fad95a6b7590fedef9d46ed665f72f8e4af57bcf2d7dd22ccca9af91d0616df1e792ae230c0246649870c6ba3739de0842ade2ac8c43a8fb60
|
data/README.md
CHANGED
@@ -76,6 +76,32 @@ Any of the defaults can be over-ridden in `config/deploy.rb`:
|
|
76
76
|
set :slack_deploy_failed_color, 'danger'
|
77
77
|
set :slack_notify_events, [:started, :finished, :failed]
|
78
78
|
|
79
|
+
You can setup custom fields by defining a mapping for how to display them in slack:
|
80
|
+
|
81
|
+
set :slack_fields, ['status', 'environment', 'docker_image']
|
82
|
+
# You could also add your custom mappings to the defaults with:
|
83
|
+
# set :slack_fields, fetch(:slack_fields).push('environment', 'docker_image')
|
84
|
+
set :slack_custom_field_mapping, -> {
|
85
|
+
{
|
86
|
+
'environment' => {
|
87
|
+
title: 'Environment',
|
88
|
+
value: -> {
|
89
|
+
if fetch(:stage) == :production
|
90
|
+
'production'
|
91
|
+
else
|
92
|
+
"staging-#{fetch(:staging_name)}"
|
93
|
+
end
|
94
|
+
},
|
95
|
+
short: true,
|
96
|
+
},
|
97
|
+
'docker_image' => {
|
98
|
+
title: 'Docker image',
|
99
|
+
value: fetch(:docker_image),
|
100
|
+
short: false,
|
101
|
+
},
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
79
105
|
To configure the way slack parses your message (see 'Parsing Modes' at https://api.slack.com/docs/formatting) use the `:slack_parse` setting:
|
80
106
|
|
81
107
|
set :slack_parse, 'none' # available options: 'default', 'none', 'full'
|
data/capistrano-slackify.gemspec
CHANGED
@@ -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.
|
7
|
+
spec.version = '2.9.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}
|
@@ -59,6 +59,7 @@ namespace :load do
|
|
59
59
|
set :slack_parse, 'default'
|
60
60
|
set :slack_user, -> { local_user.strip }
|
61
61
|
set :slack_fields, ['status', 'stage', 'branch', 'revision', 'hosts']
|
62
|
+
set :slack_custom_field_mapping, {}
|
62
63
|
set :slack_mrkdwn_in, []
|
63
64
|
set :slack_hosts, -> { release_roles(:all).map(&:hostname).join("\n") }
|
64
65
|
set :slack_url, -> { fail ':slack_url is not set' }
|
data/lib/slackify.rb
CHANGED
@@ -17,7 +17,44 @@ module Slackify
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def payload
|
20
|
-
|
20
|
+
fields = fetch(:slack_fields).each_with_object([]) { |field, fields|
|
21
|
+
if fields_map[field].fetch(:value).respond_to?(:call)
|
22
|
+
field_data = fields_map[field]
|
23
|
+
field_data[:value] = field_data.fetch(:value).call
|
24
|
+
fields.push(field_data)
|
25
|
+
else
|
26
|
+
fields.push(fields_map[field])
|
27
|
+
end
|
28
|
+
}
|
29
|
+
|
30
|
+
MultiJson.dump(
|
31
|
+
{
|
32
|
+
channel: fetch(:slack_channel),
|
33
|
+
username: fetch(:slack_username),
|
34
|
+
icon_emoji: fetch(:slack_emoji),
|
35
|
+
parse: fetch(:slack_parse),
|
36
|
+
attachments: [
|
37
|
+
{
|
38
|
+
fallback: text,
|
39
|
+
color: color,
|
40
|
+
text: text,
|
41
|
+
fields: fields,
|
42
|
+
mrkdwn_in: fetch(:slack_mrkdwn_in),
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def fields_map
|
50
|
+
@fields_map ||= [
|
51
|
+
default_field_map,
|
52
|
+
fetch(:slack_custom_field_mapping),
|
53
|
+
].reduce(&:merge)
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_field_map
|
57
|
+
{
|
21
58
|
'status' => {
|
22
59
|
title: 'Status',
|
23
60
|
value: @status,
|
@@ -44,30 +81,6 @@ module Slackify
|
|
44
81
|
short: true
|
45
82
|
}
|
46
83
|
}
|
47
|
-
|
48
|
-
fields = []
|
49
|
-
|
50
|
-
fetch(:slack_fields).each { |field|
|
51
|
-
fields.push(fields_map[field])
|
52
|
-
}
|
53
|
-
|
54
|
-
MultiJson.dump(
|
55
|
-
{
|
56
|
-
channel: fetch(:slack_channel),
|
57
|
-
username: fetch(:slack_username),
|
58
|
-
icon_emoji: fetch(:slack_emoji),
|
59
|
-
parse: fetch(:slack_parse),
|
60
|
-
attachments: [
|
61
|
-
{
|
62
|
-
fallback: text,
|
63
|
-
color: color,
|
64
|
-
text: text,
|
65
|
-
fields: fields,
|
66
|
-
mrkdwn_in: fetch(:slack_mrkdwn_in),
|
67
|
-
}
|
68
|
-
]
|
69
|
-
}
|
70
|
-
)
|
71
84
|
end
|
72
85
|
|
73
86
|
def fetch(*args, &block)
|
data/spec/lib/slackify_spec.rb
CHANGED
@@ -10,7 +10,21 @@ module Slackify
|
|
10
10
|
slack_emoji: ':ghost:',
|
11
11
|
slack_parse: 'default',
|
12
12
|
slack_user: 'You',
|
13
|
-
slack_fields: ['status', 'stage', 'branch', 'revision', 'hosts'],
|
13
|
+
slack_fields: ['status', 'stage', 'branch', 'revision', 'hosts', 'custom_field', 'custom_field_with_proc'],
|
14
|
+
slack_custom_field_mapping: {
|
15
|
+
'custom_field' => {
|
16
|
+
title: 'custom title',
|
17
|
+
value: 'custom value',
|
18
|
+
short: false
|
19
|
+
},
|
20
|
+
'custom_field_with_proc' => {
|
21
|
+
title: 'custom title proc',
|
22
|
+
value: -> {
|
23
|
+
'custom value proc'
|
24
|
+
},
|
25
|
+
short: false
|
26
|
+
}
|
27
|
+
},
|
14
28
|
slack_mrkdwn_in: ['text'],
|
15
29
|
slack_hosts: "192.168.10.1\r192.168.10.2",
|
16
30
|
slack_text: ':boom:',
|
@@ -22,7 +36,7 @@ module Slackify
|
|
22
36
|
}
|
23
37
|
|
24
38
|
let(:payload) {
|
25
|
-
%{'payload={"channel":"#general","username":"Capistrano","icon_emoji":":ghost:","parse":"default","attachments":[{"fallback":":boom:","color":"good","text":":boom:","fields":[{"title":"Status","value":"success","short":true},{"title":"Stage","value":"sandbox","short":true},{"title":"Branch","value":"master","short":true},{"title":"Revision","value":"SHA","short":true},{"title":"Hosts","value":"192.168.10.1\\r192.168.10.2","short":true}],"mrkdwn_in":["text"]}]}'}
|
39
|
+
%{'payload={"channel":"#general","username":"Capistrano","icon_emoji":":ghost:","parse":"default","attachments":[{"fallback":":boom:","color":"good","text":":boom:","fields":[{"title":"Status","value":"success","short":true},{"title":"Stage","value":"sandbox","short":true},{"title":"Branch","value":"master","short":true},{"title":"Revision","value":"SHA","short":true},{"title":"Hosts","value":"192.168.10.1\\r192.168.10.2","short":true},{"title":"custom title","value":"custom value","short":false},{"title":"custom title proc","value":"custom value proc","short":false}],"mrkdwn_in":["text"]}]}'}
|
26
40
|
}
|
27
41
|
|
28
42
|
let(:text) { context.fetch(:slack_text) }
|
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.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seenmyfate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capistrano
|