capistrano-slacky 0.1.0 → 0.1.4

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
  SHA256:
3
- metadata.gz: c87234b5cfdadfb8ce089157537abe447d9836f10bb53b457a2e56dbd8a43f39
4
- data.tar.gz: 8c80128b0c46a4b1e7882a8c13cdb68d627054d341605148eeb88964cd43dd63
3
+ metadata.gz: 6e892f62e82295a36d7682081bd49b9325ca4acfb6b7567d35b3d30eee900586
4
+ data.tar.gz: b2fe16318ad7a07fe5152615b3ddaed80e5a50cf8003b3091ca8aa7a1b2d7f2a
5
5
  SHA512:
6
- metadata.gz: a4a123f09d2ea1285546071859f1bd2fa7d2a86b100e435f580b410a9e348f540fd2717769a8b3fff7862ade8c9aa62b8973c1b971b8f867f9793ee5b942c89f
7
- data.tar.gz: 6918fccca963085fc524885ff4adee5cc8fa5b28723417f60a6fcdfa049728c04eb079458268d0f86dd4b7e8067030500ba11ff3be48535bbecc21ce78b34467
6
+ metadata.gz: 5f1fafa918f99df51308081d599b96c22d97800629695ffe5f2073e8eb97df259eec2b367776b0f04f4c575350bef4f35b42212b63e6971649aba93e84377e67
7
+ data.tar.gz: 8a913baa0918ba16b2ff02ecd4db61984a850ca2b3ca41ad5516bc60988dfbe0b70f31d1d8ded6a1f901078366103a30eb744031b94141be7a868491c36d0f95
data/CHANGELOG.md CHANGED
@@ -6,8 +6,47 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.1.4] - 2021-07-27
10
+ ### Fixed
11
+ - Ensure that `:current_revision` exists during rollback. ([@chubchenko][])
12
+
13
+ ## [0.1.3] - 2021-06-14
14
+ ### Changed
15
+ - Update `README.md`. ([@chubchenko][])
16
+
17
+ ### Fixed
18
+ - Change commit message encoding to `UTF-8`. ([@chubchenko][])
19
+
20
+ ## [0.1.2] - 2021-06-03
21
+ ### Changed
22
+ - Use `I18n.t` instead of `t`. ([@chubchenko][])
23
+ - Use `forwardable` instead of `method_missing` + `respond_to_missing?`. ([@chubchenko][])
24
+ - Use the `On` module to interact with the remote server. ([@chubchenko][])
25
+ - Extracted hooks and defaults from `slacky.rake` into separate files. ([@chubchenko][])
26
+ - Renamed `#to_json` to `#as_json`. ([@chubchenko][])
27
+ - Updated hooks from `before` to `after`. ([@chubchenko][])
28
+ - Added 💯 test coverage. ([@chubchenko][])
29
+
30
+ ### Fixed
31
+ - Use `@env` instance variable instead of missing getter `env`. ([@chubchenko][])
32
+ - Update your SSH regex to match the repository with a dash in the name. ([@chubchenko][])
33
+ - Use `SSHKit::Backend.current.capture` instead of `IO.popen` to perform `git log ..` on the remote server. ([@chubchenko][])
34
+
35
+ ### Security
36
+ - Fix possible command injection during the duration retrieval. ([@chubchenko][])
37
+
38
+ ## [0.1.1] - 2021-05-27
39
+ ### Fixed
40
+ - Fix a bug related to using a `Null` messaging. ([@chubchenko][])
41
+
9
42
  ## [0.1.0] - 2021-05-26
10
43
  ### Added
11
44
  - Initial version. ([@chubchenko][])
12
45
 
13
46
  [@chubchenko]: https://github.com/chubchenko
47
+ [Unreleased]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.4...HEAD
48
+ [0.1.4]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.3...v0.1.4
49
+ [0.1.3]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.2...v0.1.3
50
+ [0.1.2]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.1...v0.1.2
51
+ [0.1.1]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.0...v0.1.1
52
+ [0.1.0]: https://github.com/chubchenko/capistrano-slacky/releases/tag/v0.1.0
data/README.md CHANGED
@@ -1,13 +1,123 @@
1
+ <div align="center">
2
+ <img align="center"
3
+ height="100"
4
+ title="capistrano-slacky logo"
5
+ src="./assets/images/logo.svg">
6
+ </div>
7
+
8
+ [![gem version][9]][10]
1
9
  [![build][1]][2]
10
+ [![downloads][11]][12]
2
11
 
3
12
  # capistrano-slacky
4
13
 
5
- Send `Capistrano` deployment status to `Slack`.
14
+ Send `Capistrano` deployment status to `Slack` via the Incoming Webhooks integration.
15
+
16
+ - Messages are built on the basis of the [Block Kit][13]. See [Demo](#demo) section.
17
+ - Fires after every successful/failed deployment or rollback.
18
+ - Use _Incoming Webhook URL_ from the remote server.
19
+ - Send commit log between 2 deployments.
20
+
21
+ ## Table of Contents
22
+
23
+ - [Requirements](#requirements)
24
+ - [Installation](#installation)
25
+ - [Configuration](#configuration)
26
+ - [Usage](#usage)
27
+ - [Demo](#demo)
28
+
29
+ ## Requirements
30
+
31
+ - Ruby >= 2.5
32
+ - Capistrano ~> 3.0
33
+ - Slack
34
+
35
+ ## Installation
36
+
37
+ Add the following line to your `Gemfile`:
38
+
39
+ ```ruby
40
+ gem "capistrano-slacky", "~> 0.1", require: false
41
+ ```
42
+
43
+ And then execute:
44
+
45
+ ```bash
46
+ bundle install
47
+ ```
48
+
49
+ ## Configuration
50
+
51
+ Out of the box, the gem has a default configuration:
52
+
53
+ ```ruby
54
+ set :slacky, username: "ChatOps", # Set your bot's user name.
55
+ icon_emoji: ":robot_face:", # Emoji to use as the icon for this message.
56
+ channel: "#deployment", # The name of the channel to send a message to.
57
+ klass: Capistrano::Slacky::Messaging::Default # The class that responsible for creating a message.
58
+ ```
59
+
60
+ So you can easily tweak your deployment messages and all other configuration to what you want.
61
+
62
+ ## Usage
63
+
64
+ Require the library in your application's Capfile
65
+
66
+ ```ruby
67
+ require "capistrano/slacky"
68
+ ```
69
+
70
+ - Add an [Incoming Webhooks][4] to your Slack.
71
+ - The received _Incoming Webhook URL_ must be uploaded to the remote server. It should be stored in a `shared` directory under the following path `config/slacky.yml`.
72
+ - Run `cap production slacky:ping` command to test your integration.
73
+
74
+ That's all, deploy your application as usual and you will see a deployment notification in your Slack channel.
75
+
76
+ In case if you want to disable deployment notifications for a specific stage just set `slacky` to `false`.
77
+
78
+ ```ruby
79
+ set :slacky, false
80
+ ```
81
+
82
+ ## Demo
83
+
84
+ ![Deployed successfully][5]
85
+
86
+ ![Reverted successfully][6]
87
+
88
+ ## Supported Ruby Versions
89
+
90
+ This library aims to support and is [tested against][2] the following Ruby implementations:
91
+
92
+ - Ruby 2.5
93
+ - Ruby 2.6
94
+ - Ruby 2.7
95
+ - Ruby 3.0
96
+
97
+ If something doesn't work on one of these Ruby versions, it's a bug.
98
+
99
+ ## Versioning
100
+
101
+ This library aims to adhere to [Semantic Versioning 2.0.0][4]. Violations of this scheme should be reported as bugs. Specifically, if a minor or patch version is released that breaks backward compatibility, that version should be immediately yanked, and/or a new version should be immediately released that restores compatibility. Breaking changes to the public API will only be introduced with new major versions. As a result of this policy, you can (and should) specify a dependency on this gem using the [Pessimistic Version Constraint][5] with two digits of precision. For example:
102
+
103
+ ```ruby
104
+ gem "capistrano-slacky", "~> 0.1"
105
+ ```
6
106
 
7
107
  ## License
8
108
 
9
109
  [MIT][3]
10
110
 
11
- [1]: https://github.com/chubchenko/capistrano-slacky/workflows/build/badge.svg
12
- [2]: https://github.com/chubchenko/capistrano-slacky/actions
111
+ [1]: https://github.com/chubchenko/capistrano-slacky/actions/workflows/build.yml/badge.svg
112
+ [2]: https://github.com/chubchenko/capistrano-slacky/actions/workflows/build.yml
13
113
  [3]: https://choosealicense.com/licenses/mit
114
+ [4]: https://api.slack.com/messaging/webhooks
115
+ [5]: ./assets/images/deployed_successfully.jpg
116
+ [6]: ./assets/images/deployment_failed.jpg
117
+ [7]: ./assets/images/reverted_successfully.jpg
118
+ [8]: ./assets/images/rollback_failed.jpg
119
+ [9]: https://badge.fury.io/rb/capistrano-slacky.svg
120
+ [10]: https://badge.fury.io/rb/capistrano-slacky
121
+ [11]: https://img.shields.io/gem/dt/capistrano-slacky
122
+ [12]: https://rubygems.org/gems/capistrano-slacky
123
+ [13]: https://api.slack.com/block-kit
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  load File.expand_path("../../tasks/slacky.rake", __FILE__)
4
+ load File.expand_path("../../tasks/hooks.rake", __FILE__)
5
+ load File.expand_path("../../tasks/defaults.rake", __FILE__)
4
6
 
5
7
  require_relative "slacky/version"
6
8
  require_relative "slacky/configuration"
@@ -9,24 +11,19 @@ require_relative "slacky/runner"
9
11
  require_relative "slacky/block"
10
12
  require_relative "slacky/facade"
11
13
  require_relative "slacky/command"
14
+ require_relative "slacky/on"
12
15
 
13
16
  module Capistrano
14
17
  module Slacky
15
- module_function
18
+ require "forwardable"
16
19
 
17
- # Delegate any missing method call to the configuration
18
- def method_missing(method_name, *arguments, &block)
19
- return super unless configuration.respond_to?(method_name)
20
+ module_function
20
21
 
21
- configuration.public_send(method_name, *arguments, &block)
22
- end
22
+ extend ::SingleForwardable
23
23
 
24
- # Replace the Object.respond_to?() method
25
- def respond_to_missing?(method_name, include_private = false)
26
- configuration.respond_to?(method_name) || super
27
- end
24
+ def_delegators :configuration, :username, :icon_emoji, :channel, :klass, :slacky?, :repo
25
+ def_delegator :"Capistrano::Slacky::On", :on
28
26
 
29
- # @return [Capistrano::Slacky::Configuration]
30
27
  def configuration
31
28
  @configuration ||= ::Capistrano::Slacky::Configuration.new
32
29
  end
@@ -10,10 +10,10 @@ module Capistrano
10
10
  end
11
11
  end
12
12
 
13
- def to_json
13
+ def as_json
14
14
  {
15
15
  type: :context,
16
- elements: @elements.map(&:to_json)
16
+ elements: @elements.map(&:as_json)
17
17
  }
18
18
  end
19
19
 
@@ -22,7 +22,7 @@ module Capistrano
22
22
  @text = text
23
23
  end
24
24
 
25
- def to_json
25
+ def as_json
26
26
  {
27
27
  type: :mrkdwn,
28
28
  text: @text
@@ -8,7 +8,7 @@ module Capistrano
8
8
  @text = text
9
9
  end
10
10
 
11
- def to_json
11
+ def as_json
12
12
  {
13
13
  type: :header,
14
14
  text: {
@@ -8,9 +8,9 @@ module Capistrano
8
8
  @blocks = blocks.flatten
9
9
  end
10
10
 
11
- def to_json
11
+ def as_json
12
12
  {
13
- blocks: @blocks.map(&:to_json)
13
+ blocks: @blocks.map(&:as_json)
14
14
  }
15
15
  end
16
16
  end
@@ -10,10 +10,10 @@ module Capistrano
10
10
  end
11
11
  end
12
12
 
13
- def to_json
13
+ def as_json
14
14
  {
15
15
  type: :section,
16
- fields: @fields.map(&:to_json)
16
+ fields: @fields.map(&:as_json)
17
17
  }
18
18
  end
19
19
 
@@ -22,7 +22,7 @@ module Capistrano
22
22
  @text = text
23
23
  end
24
24
 
25
- def to_json
25
+ def as_json
26
26
  {
27
27
  type: :mrkdwn, text: @text
28
28
  }
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "command/current_revision"
3
4
  require_relative "command/duration"
4
5
  require_relative "command/diff"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module Slacky
5
+ module Command
6
+ class CurrentRevision
7
+ REVISION_FILE = "REVISION"
8
+
9
+ private_constant :REVISION_FILE
10
+
11
+ def self.call
12
+ output = nil
13
+
14
+ ::Capistrano::Slacky.on(within: :release) do
15
+ output = ::SSHKit::Backend.current.capture(:cat, REVISION_FILE)
16
+ end
17
+
18
+ output
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -5,7 +5,13 @@ module Capistrano
5
5
  module Command
6
6
  class Diff
7
7
  def self.call(previous:, current:)
8
- new(previous: previous, current: current).call
8
+ output = nil
9
+
10
+ ::Capistrano::Slacky.on(within: :repository) do
11
+ output = new(previous: previous, current: current).call
12
+ end
13
+
14
+ output
9
15
  end
10
16
 
11
17
  def initialize(previous:, current:)
@@ -14,15 +20,15 @@ module Capistrano
14
20
  end
15
21
 
16
22
  def call
17
- diff = ::IO.popen(
18
- ["git", "log", "--oneline", "--first-parent", "#{previous}..#{current}"]
19
- ).readlines
23
+ log = ::SSHKit::Backend.current.capture(
24
+ :git, :log, "--oneline", "--first-parent", "#{previous}..#{current}"
25
+ ).split("\n")
20
26
 
21
- diff.map.with_index(1) do |line, index|
27
+ log.map.with_index(1) do |line, index|
22
28
  sha, commit = line.match(/^(\w+) (.*+?)/).captures
23
29
 
24
30
  if /^Merge pull request/.match?(commit)
25
- commit = ::IO.popen(["git", "log", "-1", sha, '--pretty=format:"%b"']).readline
31
+ commit = ::SSHKit::Backend.current.capture(:git, :log, "-1", sha, '--pretty=format:"%b"')
26
32
  end
27
33
 
28
34
  Message.new(index: index, sha: sha, commit: commit)
@@ -48,6 +54,9 @@ module Capistrano
48
54
  "0" => ":zero:"
49
55
  }.freeze
50
56
 
57
+ DEFAULT_ENCODING = "UTF-8"
58
+ private_constant :DEFAULT_ENCODING
59
+
51
60
  def initialize(index:, sha:, commit:)
52
61
  @index = index
53
62
  @sha = sha
@@ -65,7 +74,7 @@ module Capistrano
65
74
  end
66
75
 
67
76
  def commit
68
- @commit.delete('"').strip
77
+ @commit.delete('"').strip.force_encoding(DEFAULT_ENCODING)
69
78
  end
70
79
 
71
80
  def to_a
@@ -5,7 +5,7 @@ module Capistrano
5
5
  module Command
6
6
  class Duration
7
7
  def self.call(pid: $PID)
8
- `ps -p #{pid} -o etime=`.strip
8
+ ::IO.popen(["ps", "-p", pid.to_s, "-o", "etime="]).readline.strip
9
9
  end
10
10
  end
11
11
  end
@@ -37,14 +37,14 @@ module Capistrano
37
37
 
38
38
  def repo
39
39
  @repo ||= Repo.new(
40
- remote: env.fetch(:repo_url)
40
+ remote: @env.fetch(:repo_url)
41
41
  )
42
42
  end
43
43
 
44
44
  private
45
45
 
46
46
  def data
47
- @data ||= env.fetch(:slacky, {})
47
+ @data ||= @env.fetch(:slacky, {})
48
48
  end
49
49
 
50
50
  class Repo
@@ -64,7 +64,7 @@ module Capistrano
64
64
  end
65
65
 
66
66
  def ssh?
67
- @remote.match?(/((git|ssh|http(s)?)|(git@[\w.]+))(:(\/)?)([\w.@:\/-~]+)(\.git)(\/)?/)
67
+ @remote.match?(/((git|ssh|http(s)?)|(git@[\w.]+))(:(\/)?)([\w.@:\/~-]+)(\.git)(\/)?/)
68
68
  end
69
69
  end
70
70
 
@@ -8,9 +8,9 @@ module Capistrano
8
8
  @env = env
9
9
 
10
10
  super(
11
- t("slacky.stage"), "`#{stage}`",
12
- t("slacky.branch"), "`#{branch}`",
13
- t("slacky.duration"), "`#{duration}`",
11
+ ::I18n.t("slacky.stage", scope: "capistrano"), "`#{stage}`",
12
+ ::I18n.t("slacky.branch", scope: "capistrano"), "`#{branch}`",
13
+ ::I18n.t("slacky.duration", scope: "capistrano"), "`#{duration}`",
14
14
  )
15
15
  end
16
16
 
@@ -11,25 +11,17 @@ module Capistrano
11
11
  ).call
12
12
  end
13
13
 
14
- attr_accessor :difference
15
-
16
14
  def initialize(previous:, current:)
17
- ref = self
18
-
19
- on(::Capistrano::Configuration.env.primary(:app)) do
20
- within repo_path do
21
- ref.difference = ::Capistrano::Slacky::Command::Diff.call(
22
- previous: previous,
23
- current: current
24
- )
25
- end
26
- end
15
+ @difference = ::Capistrano::Slacky::Command::Diff.call(
16
+ previous: previous,
17
+ current: current
18
+ )
27
19
  end
28
20
 
29
21
  def call
30
22
  if difference.empty?
31
23
  return ::Capistrano::Slacky::Block::Context.new(
32
- t("slacky.nothing_has_changed_since_the_previous_release")
24
+ ::I18n.t("slacky.nothing_has_changed_since_the_previous_release", scope: "capistrano")
33
25
  )
34
26
  end
35
27
 
@@ -39,6 +31,10 @@ module Capistrano
39
31
  )
40
32
  end
41
33
  end
34
+
35
+ private
36
+
37
+ attr_reader :difference
42
38
  end
43
39
  end
44
40
  end
@@ -6,7 +6,7 @@ module Capistrano
6
6
  class DeployedBy < ::Capistrano::Slacky::Block::Context
7
7
  def initialize(env:)
8
8
  super(
9
- t("slacky.deployed_by", deployer: env.fetch(:local_user))
9
+ ::I18n.t("slacky.deployed_by", scope: "capistrano", deployer: env.fetch(:local_user))
10
10
  )
11
11
  end
12
12
  end
@@ -6,7 +6,7 @@ module Capistrano
6
6
  class Exception < ::Capistrano::Slacky::Block::Context
7
7
  DefaultException = ::Class.new(::StandardError) do
8
8
  def initialize
9
- super(t("slacky.something_went_wrong"))
9
+ super(::I18n.t("slacky.something_went_wrong", scope: "capistrano"))
10
10
  end
11
11
  end
12
12
 
@@ -39,7 +39,7 @@ module Capistrano
39
39
  }.freeze
40
40
 
41
41
  def initialize(text)
42
- super(t("slacky.#{text}", emoji: EMOJI_MAP.fetch(text).sample))
42
+ super(::I18n.t("slacky.#{text}", scope: "capistrano", emoji: EMOJI_MAP.fetch(text).sample))
43
43
  end
44
44
  end
45
45
  end
@@ -8,9 +8,10 @@ module Capistrano
8
8
  @env = env
9
9
 
10
10
  super(
11
- t("slacky.revision", repository_url: ::Capistrano::Slacky.repo.url,
12
- current: current,
13
- previous: previous)
11
+ I18n.t("slacky.revision", scope: "capistrano",
12
+ repository_url: ::Capistrano::Slacky.repo.url,
13
+ current: current,
14
+ previous: previous)
14
15
  )
15
16
  end
16
17
 
@@ -9,19 +9,15 @@ module Capistrano
9
9
 
10
10
  module_function
11
11
 
12
- def uri(role: Hook.role)
12
+ def uri
13
13
  output = nil
14
14
 
15
- on(role) do
16
- output = capture(:cat, File.join(shared_path, DEFAULT_HOOK_FILE))
15
+ ::Capistrano::Slacky.on(within: :shared) do
16
+ output = ::SSHKit::Backend.current.capture(:cat, DEFAULT_HOOK_FILE)
17
17
  end
18
18
 
19
19
  URI(output)
20
20
  end
21
-
22
- def role
23
- ::Capistrano::Configuration.env.primary(:app)
24
- end
25
21
  end
26
22
 
27
23
  private_constant :Hook
@@ -10,7 +10,7 @@ module Capistrano
10
10
  def self.for(env:)
11
11
  klass =
12
12
  if ::Capistrano::Slacky.slacky?
13
- (::Capistrano::Slacky.klass || Default)
13
+ (::Capistrano::Slacky.klass || ::Capistrano::Slacky::Messaging::Default)
14
14
  else
15
15
  Null
16
16
  end
@@ -11,7 +11,7 @@ module Capistrano
11
11
  ::Capistrano::Slacky::Facade::Revision.new(env: env),
12
12
  ::Capistrano::Slacky::Facade::Changelog.for(env: env),
13
13
  ::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
14
- ).to_json
14
+ ).as_json
15
15
  end
16
16
 
17
17
  def payload_for_reverted
@@ -20,7 +20,7 @@ module Capistrano
20
20
  ::Capistrano::Slacky::Facade::Body.new(env: env),
21
21
  ::Capistrano::Slacky::Facade::Revision.new(env: env),
22
22
  ::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
23
- ).to_json
23
+ ).as_json
24
24
  end
25
25
 
26
26
  def payload_for_failed
@@ -29,7 +29,13 @@ module Capistrano
29
29
  ::Capistrano::Slacky::Facade::Body.new(env: env),
30
30
  ::Capistrano::Slacky::Facade::Exception.new,
31
31
  ::Capistrano::Slacky::Facade::DeployedBy.new(env: env)
32
- ).to_json
32
+ ).as_json
33
+ end
34
+
35
+ private
36
+
37
+ def deploying?
38
+ env.fetch(:deploying, false)
33
39
  end
34
40
  end
35
41
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module Slacky
5
+ module On
6
+ class Path
7
+ extend ::Capistrano::DSL
8
+ end
9
+
10
+ PATH_MAP = {
11
+ repository: -> { Path.repo_path },
12
+ shared: -> { Path.shared_path },
13
+ release: -> { Path.release_path }
14
+ }.freeze
15
+
16
+ private_constant :PATH_MAP
17
+
18
+ module_function
19
+
20
+ def on(within:, &block)
21
+ ::Capistrano::DSL.on(::Capistrano::Configuration.env.primary(:app)) do
22
+ ::SSHKit::Backend.current.within(PATH_MAP.fetch(within).call, &block)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -11,15 +11,25 @@ module Capistrano
11
11
  @messaging = ::Capistrano::Slacky::Messaging.for(env: env)
12
12
  end
13
13
 
14
+ def empty?
15
+ payload_for_action.nil?
16
+ end
17
+
14
18
  def to_json
15
19
  {
16
20
  username: ::Capistrano::Slacky.username,
17
21
  icon_emoji: ::Capistrano::Slacky.icon_emoji,
18
22
  channel: ::Capistrano::Slacky.channel
19
23
  }.merge(
20
- @messaging.payload_for(action: @action)
24
+ payload_for_action
21
25
  ).to_json
22
26
  end
27
+
28
+ private
29
+
30
+ def payload_for_action
31
+ @payload_for_action ||= @messaging.payload_for(action: @action)
32
+ end
23
33
  end
24
34
  end
25
35
  end
@@ -6,11 +6,13 @@ require_relative "fanout"
6
6
  module Capistrano
7
7
  module Slacky
8
8
  class Runner
9
- def self.call(env:, action:)
9
+ def self.call(action:, env: ::Capistrano::Configuration.env)
10
10
  payload = ::Capistrano::Slacky::Payload.new(
11
11
  env: env, action: action
12
12
  )
13
13
 
14
+ return if payload.empty?
15
+
14
16
  ::Capistrano::Slacky::Fanout.call(payload: payload)
15
17
  end
16
18
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capistrano
4
4
  module Slacky
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :load do
4
+ task :defaults do
5
+ append :linked_files, "config/slacky.yml"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ after :'deploy:finishing', :'slacky:updated'
4
+ after :'deploy:finishing_rollback', :'slacky:reverted'
5
+ after :'deploy:failed', :'slacky:failed'
@@ -3,40 +3,31 @@
3
3
  namespace :slacky do
4
4
  desc "Slacky after a successful deployment"
5
5
  task :updated do
6
- Capistrano::Slacky::Runner.call(
7
- env: self, action: :updated
8
- )
6
+ Capistrano::Slacky::Runner.call(action: :updated)
9
7
  end
10
8
 
11
9
  desc "Slacky after successful rollback"
12
- task :reverted do
13
- Capistrano::Slacky::Runner.call(
14
- env: self, action: :reverted
15
- )
10
+ task reverted: [:ensure_current_revision] do
11
+ Capistrano::Slacky::Runner.call(action: :reverted)
16
12
  end
17
13
 
18
14
  desc "Slacky after failure deployment or rollback"
19
15
  task :failed do
20
- Capistrano::Slacky::Runner.call(
21
- env: self, action: :failed
22
- )
16
+ Capistrano::Slacky::Runner.call(action: :failed)
23
17
  end
24
18
 
25
- # task :ping do
26
- # [:updated, :reverted, :failed].each do |action|
27
- # Capistrano::Slacky::Runner.call(
28
- # env: self, action: action
29
- # )
30
- # end
31
- # end
32
- end
19
+ desc "Slacky all slackable task (updated, reverted, failed)"
20
+ task :ping do
21
+ ask(:previous_revision) unless env.any?(:previous_revision)
22
+ ask(:current_revision) unless env.any?(:current_revision)
33
23
 
34
- before :'deploy:finishing', :'slacky:updated'
35
- before :'deploy:finishing_rollback', :'slacky:reverted'
36
- before :'deploy:failed', :'slacky:failed'
24
+ [:updated, :reverted, :failed].each do |action|
25
+ Capistrano::Slacky::Runner.call(action: action)
26
+ end
27
+ end
37
28
 
38
- namespace :load do
39
- task :defaults do
40
- append :linked_files, "config/slacky.yml"
29
+ desc "Ensure that the current revision is set"
30
+ task :ensure_current_revision do
31
+ set_if_empty(:current_revision) { Capistrano::Slacky::Command::CurrentRevision.call }
41
32
  end
42
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-slacky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Chubchenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
11
+ date: 2021-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -72,21 +72,7 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0.21'
75
- - !ruby/object:Gem::Dependency
76
- name: webmock
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '3.12'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '3.12'
89
- description: Send Capistrano deployment status to Slack via the incoming webhooks
75
+ description: Send Capistrano deployment status to Slack via the Incoming Webhooks
90
76
  integration
91
77
  email: artem.chubchenko@gmail.com
92
78
  executables: []
@@ -104,6 +90,7 @@ files:
104
90
  - lib/capistrano/slacky/block/root.rb
105
91
  - lib/capistrano/slacky/block/section.rb
106
92
  - lib/capistrano/slacky/command.rb
93
+ - lib/capistrano/slacky/command/current_revision.rb
107
94
  - lib/capistrano/slacky/command/diff.rb
108
95
  - lib/capistrano/slacky/command/duration.rb
109
96
  - lib/capistrano/slacky/configuration.rb
@@ -121,9 +108,12 @@ files:
121
108
  - lib/capistrano/slacky/messaging/base.rb
122
109
  - lib/capistrano/slacky/messaging/default.rb
123
110
  - lib/capistrano/slacky/messaging/null.rb
111
+ - lib/capistrano/slacky/on.rb
124
112
  - lib/capistrano/slacky/payload.rb
125
113
  - lib/capistrano/slacky/runner.rb
126
114
  - lib/capistrano/slacky/version.rb
115
+ - lib/tasks/defaults.rake
116
+ - lib/tasks/hooks.rake
127
117
  - lib/tasks/slacky.rake
128
118
  homepage: https://github.com/chubchenko/capistrano-slacky
129
119
  licenses: