Class: Semvergen::SlackNotifier
- Inherits:
-
Object
- Object
- Semvergen::SlackNotifier
- Defined in:
- lib/semvergen/slack_notifier.rb
Instance Method Summary collapse
- #attachment(gem_name, new_version, change_log_message) ⇒ Object
- #gem_published(gem_name, new_version, change_log_message) ⇒ Object
-
#initialize(opts) ⇒ SlackNotifier
constructor
A new instance of SlackNotifier.
- #notifier ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(opts) ⇒ SlackNotifier
7 8 9 10 11 |
# File 'lib/semvergen/slack_notifier.rb', line 7 def initialize(opts) @webhook_url = opts["webhook_url"] @username = opts["username"] @icons = opts["icons"] end |
Instance Method Details
#attachment(gem_name, new_version, change_log_message) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/semvergen/slack_notifier.rb', line 34 def (gem_name, new_version, ) { title: "#{user} has published a new version of '#{gem_name}'", fallback: , fields: [ {title: "Version", value: new_version}, {title: "Change Log", value: } ], color: "good", mrkdwn_in: ["text", "title", "fallback", "fields"] } end |
#gem_published(gem_name, new_version, change_log_message) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/semvergen/slack_notifier.rb', line 13 def gem_published(gem_name, new_version, ) = {} [:icon_url] = @icons.sample if @icons [:attachments] = [(gem_name, new_version, )] notifier.ping "Semvergen: release #{gem_name}", end |
#notifier ⇒ Object
20 21 22 23 24 25 |
# File 'lib/semvergen/slack_notifier.rb', line 20 def notifier @notifier ||= Slack::Notifier.new( @webhook_url, username: @username ) end |
#user ⇒ Object
27 28 29 30 31 32 |
# File 'lib/semvergen/slack_notifier.rb', line 27 def user [ ENV["USER"], `whoami` ].compact.detect { |u| !u.nil? } end |