slackistrano 3.8.1 → 3.8.2

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: 3a8353756db234daceeaa82ee93d7e09cdb1e696
4
- data.tar.gz: e2270ff236ef7cb99a8a5ca9866685e72b948e5c
3
+ metadata.gz: 4fac68f58cb93ece5bc58a404e97e1e21189d841
4
+ data.tar.gz: b58e73827ae619e20a4e2a61081872177c810ac4
5
5
  SHA512:
6
- metadata.gz: fb861d03629d874e95bfaa99021a77615a734ec369b2fd3d74cd9f26d71753a4ec4ef36b73e3ef6acab45b938db70c87348a655599ad5577110c093609b616f7
7
- data.tar.gz: ddc5219bf447125f28518037dfbe9cb2fc4d66f08a295657bcc921d1c195c4c71cccf45ea2eefabf38bfb5d7c7afff56ffa292292c192c22813d9820a9e6bf19
6
+ metadata.gz: 34024139c2b12d28ddcf69428009078d931621ed75018d2c5c448464da14b6291aff0ec6193cc803bbac701c0a34b49ef977100e925d0298a26909f6b7260714
7
+ data.tar.gz: 5259c193fe28f066d04972abbe22345295b9ccd8f3a305a9426c26e539c911d5ebc7723ed28221e430f136fe45e767fe6408426391d20ddbbeba1d9b1ceea605
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Slackistrano Change Log
2
2
 
3
+ 3.8.2
4
+ -----
5
+
6
+ - Allow overriding icon_url, icon_emoji, and usename without needing custom
7
+ messaging class [#78, #68]
8
+
3
9
  3.8.1
4
10
  -----
5
11
 
data/README.md CHANGED
@@ -66,6 +66,26 @@ You have two options to notify a channel in Slack when you deploy:
66
66
  }
67
67
  ```
68
68
 
69
+ ### Optional Configuration & Overrides
70
+
71
+ By default Slackistrano will use a default icon and username. These, can be
72
+ overriden if you are using the default messaging class (ie. have not specified
73
+ your own).
74
+
75
+ 1. Configure per instructions above.
76
+ 2. Add the following to `config/deploy.rb`:
77
+
78
+ ```ruby
79
+ set :slackistrano, {
80
+ ...
81
+ username: 'Foobar the Deployer',
82
+ icon_emoji: ':thumbsup:', # takes precedence over icon_url
83
+ icon_url: 'https://avatars2.githubusercontent.com/u/16705?v=4&s=40',
84
+ ...
85
+ }
86
+ ```
87
+
88
+
69
89
  ### Test your Configuration
70
90
 
71
91
  Test your setup by running the following command. This will post each stage's
@@ -86,78 +106,83 @@ You can customize the messaging posted to Slack by providing your own messaging
86
106
  class and overriding several methods. Here is one example:
87
107
 
88
108
  ```ruby
89
- module Slackistrano
90
- class CustomMessaging < Messaging::Base
91
-
92
- # Send failed message to #ops. Send all other messages to default channels.
93
- # The #ops channel must exist prior.
94
- def channels_for(action)
95
- if action == :failed
96
- "#ops"
97
- else
98
- super
99
- end
100
- end
101
-
102
- # Suppress updating message.
103
- def payload_for_updating
104
- nil
105
- end
106
-
107
- # Suppress reverting message.
108
- def payload_for_reverting
109
- nil
110
- end
111
-
112
- # Fancy updated message.
113
- # See https://api.slack.com/docs/message-attachments
114
- def payload_for_updated
115
- {
116
- attachments: [{
117
- color: 'good',
118
- title: 'Integrations Application Deployed :boom::bangbang:',
119
- fields: [{
120
- title: 'Environment',
121
- value: stage,
122
- short: true
123
- }, {
124
- title: 'Branch',
125
- value: branch,
126
- short: true
127
- }, {
128
- title: 'Deployer',
129
- value: deployer,
130
- short: true
131
- }, {
132
- title: 'Time',
133
- value: elapsed_time,
134
- short: true
135
- }],
136
- fallback: super[:text]
137
- }]
138
- }
139
- end
140
-
141
- # Default reverted message. Alternatively simply do not redefine this
142
- # method.
143
- def payload_for_reverted
144
- super
145
- end
146
-
147
- # Slightly tweaked failed message.
148
- # See https://api.slack.com/docs/message-formatting
149
- def payload_for_failed
150
- payload = super
151
- payload[:text] = "OMG :fire: #{payload[:text]}"
152
- payload
153
- end
154
-
155
- # Override the deployer helper to pull the full name from the password file.
156
- # See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb
157
- def deployer
158
- Etc.getpwnam(ENV['USER']).gecos
159
- end
160
- end
109
+ if defined?(Slackistrano::Messaging)
110
+ module Slackistrano
111
+ class CustomMessaging < Messaging::Base
112
+
113
+ # Send failed message to #ops. Send all other messages to default channels.
114
+ # The #ops channel must exist prior.
115
+ def channels_for(action)
116
+ if action == :failed
117
+ "#ops"
118
+ else
119
+ super
120
+ end
121
+ end
122
+
123
+ # Suppress updating message.
124
+ def payload_for_updating
125
+ nil
126
+ end
127
+
128
+ # Suppress reverting message.
129
+ def payload_for_reverting
130
+ nil
131
+ end
132
+
133
+ # Fancy updated message.
134
+ # See https://api.slack.com/docs/message-attachments
135
+ def payload_for_updated
136
+ {
137
+ attachments: [{
138
+ color: 'good',
139
+ title: 'Integrations Application Deployed :boom::bangbang:',
140
+ fields: [{
141
+ title: 'Environment',
142
+ value: stage,
143
+ short: true
144
+ }, {
145
+ title: 'Branch',
146
+ value: branch,
147
+ short: true
148
+ }, {
149
+ title: 'Deployer',
150
+ value: deployer,
151
+ short: true
152
+ }, {
153
+ title: 'Time',
154
+ value: elapsed_time,
155
+ short: true
156
+ }],
157
+ fallback: super[:text]
158
+ }]
159
+ }
160
+ end
161
+
162
+ # Default reverted message. Alternatively simply do not redefine this
163
+ # method.
164
+ def payload_for_reverted
165
+ super
166
+ end
167
+
168
+ # Slightly tweaked failed message.
169
+ # See https://api.slack.com/docs/message-formatting
170
+ def payload_for_failed
171
+ payload = super
172
+ payload[:text] = "OMG :fire: #{payload[:text]}"
173
+ payload
174
+ end
175
+
176
+ # Override the deployer helper to pull the best name available (git, password file, env vars).
177
+ # See https://github.com/phallstrom/slackistrano/blob/master/lib/slackistrano/messaging/helpers.rb
178
+ def deployer
179
+ name = `git config user.name`.strip
180
+ name = nil if name.empty?
181
+ name ||= Etc.getpwnam(ENV['USER']).gecos || ENV['USER'] || ENV['USERNAME']
182
+ name
183
+ end
184
+ end
185
+ end
161
186
  end
162
187
  ```
163
188
 
@@ -10,14 +10,16 @@ module Slackistrano
10
10
  extend Forwardable
11
11
  def_delegators :env, :fetch
12
12
 
13
- attr_reader :team, :token, :webhook
14
-
15
- def initialize(env: nil, team: nil, channel: nil, token: nil, webhook: nil)
16
- @env = env
17
- @team = team
18
- @channel = channel
19
- @token = token
20
- @webhook = webhook
13
+ attr_reader :team, :token, :webhook, :options
14
+
15
+ def initialize(options = {})
16
+ @options = options.dup
17
+
18
+ @env = options.delete(:env)
19
+ @team = options.delete(:team)
20
+ @channel = options.delete(:channel)
21
+ @token = options.delete(:token)
22
+ @webhook = options.delete(:webhook)
21
23
  end
22
24
 
23
25
  def payload_for_updating
@@ -3,15 +3,15 @@ module Slackistrano
3
3
  module Helpers
4
4
 
5
5
  def icon_url
6
- 'https://raw.githubusercontent.com/phallstrom/slackistrano/master/images/slackistrano.png'
6
+ options.fetch(:icon_url, 'https://raw.githubusercontent.com/phallstrom/slackistrano/master/images/slackistrano.png')
7
7
  end
8
8
 
9
9
  def icon_emoji
10
- nil
10
+ options.fetch(:icon_emoji, nil)
11
11
  end
12
12
 
13
13
  def username
14
- 'Slackistrano'
14
+ options.fetch(:username, 'Slackistrano')
15
15
  end
16
16
 
17
17
  def deployer
@@ -1,3 +1,3 @@
1
1
  module Slackistrano
2
- VERSION = '3.8.1'
2
+ VERSION = '3.8.2'
3
3
  end
@@ -2,6 +2,39 @@ require 'spec_helper'
2
2
 
3
3
  describe Slackistrano::Messaging::Default do
4
4
 
5
+ describe "#icon_url" do
6
+ it "returns a default" do
7
+ expect(subject.icon_url).to match(/phallstrom.*slackistrano.png/)
8
+ end
9
+
10
+ it "returns a custom option" do
11
+ allow(subject).to receive(:options).and_return(icon_url: 'http://example.com/foo.png')
12
+ expect(subject.icon_url).to eq 'http://example.com/foo.png'
13
+ end
14
+ end
15
+
16
+ describe "#icon_emoji" do
17
+ it "returns a default of nil" do
18
+ expect(subject.icon_emoji).to eq nil
19
+ end
20
+
21
+ it "returns a custom option" do
22
+ allow(subject).to receive(:options).and_return(icon_emoji: ':thumbsup:')
23
+ expect(subject.icon_emoji).to eq ':thumbsup:'
24
+ end
25
+ end
26
+
27
+ describe "#username" do
28
+ it "returns a default" do
29
+ expect(subject.username).to eq 'Slackistrano'
30
+ end
31
+
32
+ it "returns a custom option" do
33
+ allow(subject).to receive(:options).and_return(username: 'Codan the Deployer')
34
+ expect(subject.username).to eq 'Codan the Deployer'
35
+ end
36
+ end
37
+
5
38
  describe '#branch' do
6
39
  it "delegates to fetch" do
7
40
  expect(subject).to receive(:fetch).with(:branch)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slackistrano
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: 3.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Hallstrom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-26 00:00:00.000000000 Z
11
+ date: 2017-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano