capistrano-slackify 2.3.0 → 2.4.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: 72c70783267c99964abf6c5b5d46fd4c0a86b53b
4
- data.tar.gz: 01dfb51af25a60985be5d4610a027a8def26da01
3
+ metadata.gz: d4afa1ca7bf3d5e8dabd576e3fc92ca85b93cc44
4
+ data.tar.gz: 9654cfd14e5552aae5beb0b99b027b928c842ab3
5
5
  SHA512:
6
- metadata.gz: dc8c4b670d23ea8c00fc5ce4627b3a72b4c00bd7734fe41714abd86be682f83b7951a9c053a67534cdd9c6abf4e3dc4bd1264ee13306353c38a5e538f37d3a8c
7
- data.tar.gz: dcf88932ef185745b734fde410beeeaa23d5d61443ece1647db293ea8b5d356dfb58faeddf7e859706a5bf2cb0ef0b9e9f6e71c852903b98e41c7c33e64df068
6
+ metadata.gz: 99ea82065754daba9e03291e4f2b3aac001b26709a6ea796ac5ebdd4decaca13bb1d7af896760ffc0193b9251e8d7b55081070e4f3b58c16801c26ea8733fff3
7
+ data.tar.gz: 3a4fbf97272bac1fb2f046471fa7a0abec07b87ae12d8c0549006650407248ca0429bc678c06460e0cd2d7f6f67ec0f99820f755a88794ac05c097f3a342064d
@@ -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.3.0'
7
+ spec.version = '2.4.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}
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_runtime_dependency 'capistrano', '>= 3.1.0'
20
+ spec.add_runtime_dependency 'capistrano', '>= 3.2.0'
21
21
  spec.add_runtime_dependency 'multi_json'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.5'
@@ -6,13 +6,8 @@ namespace :slack do
6
6
  info 'Notifying Slack of deploy starting'
7
7
  set :time_started, Time.now.to_i
8
8
 
9
- payload = Slackify::Payload.build self do |default, context|
10
- default[:text] = fetch(:slack_deploy_starting_text)
11
- default
12
- end
13
-
14
9
  execute :curl, '-X POST', '--data-urlencode',
15
- payload,
10
+ Slackify::Payload.build(self, :starting),
16
11
  fetch(:slack_url)
17
12
  end
18
13
  end
@@ -25,42 +20,8 @@ namespace :slack do
25
20
  info 'Notifying Slack of deploy finished'
26
21
  set :time_finished, Time.now.to_i
27
22
 
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
-
62
23
  execute :curl, '-X POST', '--data-urlencode',
63
- payload,
24
+ Slackify::Payload.build(self, :success),
64
25
  fetch(:slack_url)
65
26
  end
66
27
  end
@@ -73,42 +34,8 @@ namespace :slack do
73
34
  info 'Notifying Slack of deploy failed'
74
35
  set :time_finished, Time.now.to_i
75
36
 
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
-
110
37
  execute :curl, '-X POST', '--data-urlencode',
111
- payload,
38
+ Slackify::Payload.build(self, :failed),
112
39
  fetch(:slack_url)
113
40
  end
114
41
  end
@@ -125,15 +52,18 @@ namespace :load do
125
52
  set :slack_url, -> { fail ':slack_url is not set' }
126
53
  set :slack_text, lambda {
127
54
  time_elapsed = Integer(fetch(:time_finished) - fetch(:time_started))
128
- "#{fetch(:application)} deployed by #{fetch(:slack_user)} " \
129
- "in #{time_elapsed} seconds."
55
+ "#{fetch(:application)} deploy by #{fetch(:slack_user)}: " \
56
+ "successful in #{time_elapsed} seconds."
130
57
  }
131
58
  set :slack_deploy_starting_text, -> {
132
- "#{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}"
59
+ "#{fetch(:application)} deploy by #{fetch(:slack_user)}: " \
60
+ "starting."
133
61
  }
134
62
  set :slack_deploy_failed_text, -> {
135
- "deploy of #{fetch(:application)}"
63
+ "#{fetch(:application)} deploy by #{fetch(:slack_user)}: " \
64
+ "failed."
136
65
  }
66
+ set :slack_deploy_starting_color, 'warning'
137
67
  set :slack_deploy_finished_color, 'good'
138
68
  set :slack_deploy_failed_color, 'danger'
139
69
  end
@@ -3,33 +3,83 @@ require 'multi_json'
3
3
  module Slackify
4
4
  class Payload
5
5
 
6
- def initialize(context)
6
+ def initialize(context, status)
7
7
  @context = context
8
+ @status = status
8
9
  end
9
10
 
10
- def self.build(context, &block)
11
- new(context).build(&block)
11
+ def self.build(context, status)
12
+ new(context, status).build
12
13
  end
13
14
 
14
- def build(&block)
15
- "'payload=#{payload(&block)}'"
15
+ def build
16
+ "'payload=#{payload}'"
16
17
  end
17
18
 
18
- def payload(&block)
19
- default = {
20
- channel: fetch(:slack_channel),
21
- username: fetch(:slack_username),
22
- icon_emoji: fetch(:slack_emoji),
23
- parse: fetch(:slack_parse)
24
- }
25
-
26
- json = yield(default, @context)
27
- MultiJson.dump(json)
19
+ def payload
20
+ MultiJson.dump(
21
+ {
22
+ channel: fetch(:slack_channel),
23
+ username: fetch(:slack_username),
24
+ icon_emoji: fetch(:slack_emoji),
25
+ parse: fetch(:slack_parse),
26
+ attachments: [
27
+ {
28
+ fallback: text,
29
+ color: color,
30
+ text: text,
31
+ fields: [
32
+ {
33
+ title: 'Status',
34
+ value: @status,
35
+ short: true
36
+ },
37
+ {
38
+ title: 'Stage',
39
+ value: fetch(:stage),
40
+ short: true
41
+ },
42
+ {
43
+ title: 'Branch',
44
+ value: fetch(:branch),
45
+ short: true
46
+ },
47
+ {
48
+ title: 'Revision',
49
+ value: fetch(:current_revision),
50
+ short: true
51
+ },
52
+ ]
53
+ }
54
+ ]
55
+ }
56
+ )
28
57
  end
29
58
 
30
59
  def fetch(*args, &block)
31
60
  @context.fetch(*args, &block)
32
61
  end
33
62
 
63
+ def text
64
+ @text ||= case @status
65
+ when :starting
66
+ fetch(:slack_deploy_starting_text)
67
+ when :success
68
+ fetch(:slack_text)
69
+ when :failed
70
+ fetch(:slack_deploy_failed_text)
71
+ end
72
+ end
73
+
74
+ def color
75
+ case @status
76
+ when :starting
77
+ fetch(:slack_deploy_starting_color)
78
+ when :success
79
+ fetch(:slack_deploy_finished_color)
80
+ when :failed
81
+ fetch(:slack_deploy_failed_color)
82
+ end
83
+ end
34
84
  end
35
85
  end
@@ -11,20 +11,21 @@ module Slackify
11
11
  slack_parse: 'default',
12
12
  slack_user: 'You',
13
13
  slack_text: ':boom:',
14
+ slack_deploy_finished_color: 'good',
15
+ stage: 'sandbox',
16
+ branch: 'master',
17
+ current_revision: 'SHA',
14
18
  }
15
19
  }
16
20
 
17
21
  let(:payload) {
18
- %{'payload={"channel":"#general","username":"Capistrano","icon_emoji":":ghost:","parse":"default","text":":boom:"}'}
22
+ %{'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}]}]}'}
19
23
  }
20
24
 
21
25
  let(:text) { context.fetch(:slack_text) }
22
26
 
23
27
  let(:builded_payload) {
24
- Payload.build context do |default, context|
25
- default[:text] = text
26
- default
27
- end
28
+ Payload.build(context, :success)
28
29
  }
29
30
 
30
31
  it 'returns the payload with the specified text' do
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.3.0
4
+ version: 2.4.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-05-28 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.0
19
+ version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.0
26
+ version: 3.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: multi_json
29
29
  requirement: !ruby/object:Gem::Requirement