class CodeBuildNotifier::SlackMessage

Attributes

build[R]
config[R]

Public Class Methods

new(build, config) click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 25
def initialize(build, config)
  @build = build
  @config = config
end

Public Instance Methods

additional_channel() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 43
def additional_channel
  !build.for_pr? && config.additional_channel
end
payload() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 30
def payload
  {
    color: slack_color,
    fallback: [title, body].join("\n"),
    title: title,
    text: body
  }
end
recipients() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 39
def recipients
  [author_email, committer_email].uniq
end

Private Instance Methods

body() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 72
        def body
  "commit #{commit_link} (#{commit_message_subject}) in " \
  "#{source_ref_link}"
end
details_url() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 67
        def details_url
  'https://console.aws.amazon.com/codesuite/codebuild/projects/' \
  "#{build.project_code}/build/#{build.build_id}/log?region=#{config.region}"
end
slack_color() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 47
        def slack_color
  {
    'FAILED' => 'danger',
    'SUCCEEDED' => 'good'
  }[build.status]
end
slack_icon() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 60
        def slack_icon
  {
    'FAILED' => ':broken_heart:',
    'SUCCEEDED' => ':green_heart:'
  }[build.status]
end
title() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 54
        def title
  "#{slack_icon} #{author_name}'s " \
  "<#{details_url}|#{build.project_code} build> - " \
  "#{build.status.downcase}"
end
url_path() click to toggle source
# File lib/codebuild-notifier/slack_message.rb, line 85
        def url_path
  if %r{\Apr/}.match?(source_ref)
    "pull/#{source_ref[3..-1]}"
  else
    "tree/#{source_ref.gsub(%r{\Abranch/}, '')}"
  end
end