Sha256: 869ebad48571617e50dc1d131857ed44012e2ea0e89e749dab5133b1f99e3949
Contents?: true
Size: 1.93 KB
Versions: 2
Compression:
Stored size: 1.93 KB
Contents
require 'multi_json' module Slackify class Payload def initialize(context, status) @context = context @status = status end def self.build(context, status) new(context, status).build end def build "'payload=#{payload}'" end def payload fields_map = { 'status' => { title: 'Status', value: @status, short: true }, 'stage' => { title: 'Stage', value: fetch(:stage), short: true }, 'branch' => { title: 'Branch', value: fetch(:branch), short: true }, 'revision' => { title: 'Revision', value: fetch(:current_revision), short: true }, 'hosts' => { title: 'Hosts', value: fetch(:slack_hosts), short: true } } fields = [] fetch(:slack_fields).each { |field| fields.push(fields_map[field]) } MultiJson.dump( { channel: fetch(:slack_channel), username: fetch(:slack_username), icon_emoji: fetch(:slack_emoji), parse: fetch(:slack_parse), attachments: [ { fallback: text, color: color, text: text, fields: fields, } ] } ) end def fetch(*args, &block) @context.fetch(*args, &block) end def text @text ||= case @status when :starting fetch(:slack_deploy_starting_text) when :success fetch(:slack_text) when :failed fetch(:slack_deploy_failed_text) end end def color case @status when :starting fetch(:slack_deploy_starting_color) when :success fetch(:slack_deploy_finished_color) when :failed fetch(:slack_deploy_failed_color) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
capistrano-slackify-2.7.1 | lib/slackify.rb |
capistrano-slackify-2.7.0 | lib/slackify.rb |