class Changelog::Notifier::Formatters::Slack
Format the given release note hash for Slack
Public Class Methods
new(release_note_hash)
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 13 def initialize(release_note_hash) @release_note_hash = release_note_hash end
Public Instance Methods
format()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 17 def format { attachments: build_attachments, text: description_text } end
Private Instance Methods
build_attachments()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 26 def build_attachments Array(@release_note_hash[:changes]).map do |change, logs| { mrkdwn_in: ['text'], color: color_for(change), title: change.to_s.capitalize, fields: logs.map { |log| { title: log } } } end end
color_for(change)
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 37 def color_for(change) case change when :added then green when :changed then yellow when :deprecated then yellow when :fixed then green when :removed then red when :security then red end end
description_text()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 48 def description_text "*#{formatted_application_name}* version " \ "*#{@release_note_hash[:version]}* has just been released by " \ "*#{@release_note_hash[:author]}* on the " \ "*#{formatted_release_date}*.\n\nPlease find bellow the release note:" end
formatted_application_name()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 55 def formatted_application_name @release_note_hash[:application].gsub(/_/, ' ').titleize end
formatted_release_date()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 59 def formatted_release_date Date.parse(@release_note_hash[:date]).strftime('%b %d') end
green()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 63 def green '#36a64f' end
red()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 67 def red '#fc464a' end
yellow()
click to toggle source
# File lib/changelog/notifier/formatters/slack.rb, line 71 def yellow '#fd9134' end