Skip to content

Commit

Permalink
Skip sending a message to a Slack if the payload is empty (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
chubchenko authored May 27, 2021
1 parent 02c4c96 commit 4395e62
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix a bug related to using a `Null` messaging

## [0.1.0] - 2021-05-26
### Added
- Initial version. ([@chubchenko][])

[@chubchenko]: https://github.com/chubchenko
[Unreleased]: https://github.com/chubchenko/capistrano-slacky/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/chubchenko/capistrano-slacky/releases/tag/v0.1.0
12 changes: 11 additions & 1 deletion lib/capistrano/slacky/payload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ def initialize(env:, action:)
@messaging = ::Capistrano::Slacky::Messaging.for(env: env)
end

def empty?
payload_for_action.nil?
end

def to_json
{
username: ::Capistrano::Slacky.username,
icon_emoji: ::Capistrano::Slacky.icon_emoji,
channel: ::Capistrano::Slacky.channel
}.merge(
@messaging.payload_for(action: @action)
payload_for_action
).to_json
end

private

def payload_for_action
@payload_for_action ||= @messaging.payload_for(action: @action)
end
end
end
end
2 changes: 2 additions & 0 deletions lib/capistrano/slacky/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def self.call(env:, action:)
env: env, action: action
)

return if payload.empty?

::Capistrano::Slacky::Fanout.call(payload: payload)
end
end
Expand Down

0 comments on commit 4395e62

Please sign in to comment.