capistrano-slackify 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Capistrano Slackify
1
+ # Capistrano Slackify [![Build Status](https://travis-ci.org/onthebeach/capistrano-slackify.svg)](https://travis-ci.org/onthebeach/capistrano-slackify)
2
2
 
3
3
  Publish deploy notifications to [Slack](https://slack.com) - for [Capistrano v3](https://github.com/capistrano/capistrano).
4
4
 
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  Require the gem in your `Capfile`:
22
22
 
23
- require 'capistrano/slackfiy'
23
+ require 'capistrano/slackify'
24
24
 
25
25
  And then set the required variables in `config/deploy.rb`:
26
26
 
@@ -35,7 +35,7 @@ The task will run automatically on deploy, or can be run manually using:
35
35
 
36
36
  By default, this will publish something along the lines of:
37
37
 
38
- Revision 64a3c1de of my_app deployed to production by seenmyfate
38
+ Revision 64a3c1de of my_app deployed to production by seenmyfate in 333 seconds.
39
39
 
40
40
  ### Customisation
41
41
 
@@ -43,8 +43,16 @@ Any of the defaults can be over-ridden in `config/deploy.rb`:
43
43
 
44
44
  set :slack_channel, '#devops'
45
45
  set :slack_username, 'Deploybot'
46
- set :slack_text, -> { "Uh-oh, #{local_user} just deployed" }
47
46
  set :slack_emoji, ':trollface:'
47
+ set :slack_user, ENV['GIT_AUTHOR_NAME']
48
+ set :slack_text, -> {
49
+ "Revision #{fetch(:current_revision, fetch(:branch))} of " \
50
+ "#{fetch(:application)} deployed to #{fetch(:stage)} by #{local_user} " \
51
+ "in #{elapsed} seconds."
52
+ }
53
+ set :slack_deploy_starting_text, -> {
54
+ "Notifying Slack of #{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}"
55
+ }
48
56
 
49
57
  ### Copyright
50
58
 
@@ -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 = '1.0.0'
7
+ spec.version = '1.1.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}
@@ -1,25 +1,46 @@
1
1
  namespace :slack do
2
2
  desc 'Notify Slack of a deployment via the incoming webhooks integration - ' \
3
3
  ':slack_subdomain and :slack_token must be set'
4
- task :notify do
4
+ task :notify_started do
5
5
  run_locally do
6
- info 'Notifying Slack of deploy'
6
+ info 'Notifying Slack of deploy starting'
7
+ set :time_started, Time.now.to_i
7
8
  execute :curl, '-X POST',
8
- '--data-urlencode', fetch(:slack_payload),
9
+ '--data-urlencode', Slackify::Payload.build(:start),
9
10
  fetch(:slack_url)
10
11
  end
11
12
  end
13
+ before 'deploy', 'slack:notify_started'
12
14
 
13
- after 'deploy:finished', 'slack:notify'
15
+ desc 'Notify Slack of a deployment via the incoming webhooks integration - ' \
16
+ ':slack_subdomain and :slack_token must be set'
17
+ task :notify_finished do
18
+ run_locally do
19
+ info 'Notifying Slack of deploy finished'
20
+ set :time_finished, Time.now.to_i
21
+ execute :curl, '-X POST',
22
+ '--data-urlencode', Slackify::Payload.build(:finish),
23
+ fetch(:slack_url)
24
+ end
25
+ end
26
+ after 'deploy:finished', 'slack:notify_finished'
14
27
  end
15
28
 
16
29
  namespace :load do
17
30
  task :defaults do
18
31
  set :slack_channel, '#general'
19
32
  set :slack_username, 'Capistrano'
20
- set :slack_text, -> { slack_text }
21
33
  set :slack_emoji, ':ghost:'
22
- set :slack_payload, -> { "'payload=#{slack_payload}'" }
23
- set :slack_url, -> { slack_url }
34
+ set :slack_user, -> { local_user.strip }
35
+ set :slack_url, -> { Slackify::Configuration.instance.url }
36
+ set :slack_text, lambda {
37
+ time_elapsed = Integer(fetch(:time_finished) - fetch(:time_started))
38
+ "Revision #{fetch(:current_revision, fetch(:branch))} of " \
39
+ "#{fetch(:application)} deployed to #{fetch(:stage)} by #{fetch(:slack_user)} " \
40
+ "in #{time_elapsed} seconds."
41
+ }
42
+ set :slack_deploy_starting_text, -> {
43
+ "#{fetch(:stage)} deploy starting with revision/branch #{fetch(:current_revision, fetch(:branch))} for #{fetch(:application)}"
44
+ }
24
45
  end
25
46
  end
@@ -1,9 +1,9 @@
1
1
  require 'uri'
2
2
  require 'yajl/json_gem'
3
- module Slackify
3
+ require 'singleton'
4
4
 
5
+ module Slackify
5
6
  class URL
6
-
7
7
  def initialize(subdomain, token)
8
8
  @subdomain, @token = subdomain, token
9
9
  end
@@ -21,34 +21,57 @@ module Slackify
21
21
  end
22
22
  end
23
23
 
24
- module Payload
24
+ class Payload
25
+
26
+ attr_reader :status
27
+ protected :status
28
+
29
+ def self.build(status)
30
+ new(status).build
31
+ end
32
+
33
+ def initialize(status)
34
+ @status = status
35
+ end
36
+
37
+ def build
38
+ "'payload=#{payload}'"
39
+ end
25
40
 
26
- def slack_payload
41
+ def payload
27
42
  {
28
43
  channel: fetch(:slack_channel),
29
44
  username: fetch(:slack_username),
30
- text: fetch(:slack_text),
45
+ text: slack_text,
31
46
  icon_emoji: fetch(:slack_emoji)
32
47
  }.to_json
33
48
  end
34
49
 
35
50
  def slack_text
36
- "Revision #{fetch(:current_revision, fetch(:branch))} of " \
37
- "#{fetch(:application)} deployed to #{fetch(:stage)} by #{local_user}"
51
+ if @status == :start
52
+ fetch(:slack_deploy_starting_text)
53
+ else
54
+ fetch(:slack_text)
55
+ end
38
56
  end
39
57
 
40
- def slack_url
41
- URL.new(slack_subdomain, slack_token).to_s
58
+ end
59
+
60
+ class Configuration
61
+ include Singleton
62
+
63
+ def url
64
+ URL.new(subdomain, token).to_s
42
65
  end
43
66
 
44
- def slack_subdomain
67
+ private
68
+
69
+ def subdomain
45
70
  fetch(:slack_subdomain) { fail ':slack_subdomain is not set' }
46
71
  end
47
72
 
48
- def slack_token
73
+ def token
49
74
  fetch(:slack_token) { fail ':slack_token is not set' }
50
75
  end
51
-
52
76
  end
53
77
  end
54
- self.extend(Slackify::Payload)
metadata CHANGED
@@ -1,83 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-slackify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - seenmyfate
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-22 00:00:00.000000000 Z
12
+ date: 2014-08-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: capistrano
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 3.1.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 3.1.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: yajl-ruby
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: bundler
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - "~>"
51
+ - - ~>
46
52
  - !ruby/object:Gem::Version
47
53
  version: '1.5'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - "~>"
59
+ - - ~>
53
60
  - !ruby/object:Gem::Version
54
61
  version: '1.5'
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: rake
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - ">="
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - ">="
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rspec
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
- - - ">="
83
+ - - ! '>='
74
84
  - !ruby/object:Gem::Version
75
85
  version: '0'
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
- - - ">="
91
+ - - ! '>='
81
92
  - !ruby/object:Gem::Version
82
93
  version: '0'
83
94
  description: Publish deployment notifications to Slack via the incoming webhooks integration
@@ -87,8 +98,8 @@ executables: []
87
98
  extensions: []
88
99
  extra_rdoc_files: []
89
100
  files:
90
- - ".gitignore"
91
- - ".travis.yml"
101
+ - .gitignore
102
+ - .travis.yml
92
103
  - CONTRIBUTING.md
93
104
  - Gemfile
94
105
  - LICENSE.txt
@@ -103,28 +114,34 @@ files:
103
114
  homepage: https://github.com/onthebeach/capistrano-slackify
104
115
  licenses:
105
116
  - MIT
106
- metadata: {}
107
117
  post_install_message:
108
118
  rdoc_options: []
109
119
  require_paths:
110
120
  - lib
111
121
  required_ruby_version: !ruby/object:Gem::Requirement
122
+ none: false
112
123
  requirements:
113
- - - ">="
124
+ - - ! '>='
114
125
  - !ruby/object:Gem::Version
115
126
  version: '0'
127
+ segments:
128
+ - 0
129
+ hash: 3771920176072130592
116
130
  required_rubygems_version: !ruby/object:Gem::Requirement
131
+ none: false
117
132
  requirements:
118
- - - ">="
133
+ - - ! '>='
119
134
  - !ruby/object:Gem::Version
120
135
  version: '0'
136
+ segments:
137
+ - 0
138
+ hash: 3771920176072130592
121
139
  requirements: []
122
140
  rubyforge_project:
123
- rubygems_version: 2.2.2
141
+ rubygems_version: 1.8.25
124
142
  signing_key:
125
- specification_version: 4
143
+ specification_version: 3
126
144
  summary: Publish deployment notifications to Slack via the incoming webhooks integration
127
145
  test_files:
128
146
  - spec/lib/slackify_spec.rb
129
147
  - spec/spec_helper.rb
130
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 7f43d21b28dc2237a8c389c9925bde9e9f96947e
4
- data.tar.gz: 8ca460ea89937d3b18074e6faea7a7d7280adda2
5
- SHA512:
6
- metadata.gz: 95447efe53eb4ad20865629e3d800e93cea36c20242b849c4e62f54d2a994c7bdf5f22a61c23f211508dcdc6a49cf339d95f354bfa9ad6b99695322daa20fbeb
7
- data.tar.gz: 46a2a7625fbee81dd9f677f97d4830d9eb96b528a72b11ca8fda0e11ccccaf9f55fc19f3539c1c46a89e0b93305364e36cb534b6fe8bbf2f1272039dc5dabf06