Class: DataChecks::Notifiers::SlackDefaultFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/data_checks/notifiers/slack_default_formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(check_result) ⇒ SlackDefaultFormatter

Returns a new instance of SlackDefaultFormatter.



6
7
8
9
# File 'lib/data_checks/notifiers/slack_default_formatter.rb', line 6

def initialize(check_result)
  @check_run = check_result.check.check_run
  @check_result = check_result
end

Instance Method Details

#colorObject



36
37
38
39
40
41
42
# File 'lib/data_checks/notifiers/slack_default_formatter.rb', line 36

def color
  if @check_run.status == CheckRun.statuses[:passing]
    "good"
  else
    "danger"
  end
end

#textObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/data_checks/notifiers/slack_default_formatter.rb', line 15

def text
  error = @check_run.error_message
  count = @check_result.count
  entries = @check_result.entries&.map { |entry| format_entry(entry) }

  if error
    escape(error)
  else
    text = ["Checker found #{count} element(s)."]
    if entries
      if count > 10
        text << "Showing 10 of #{count} entries"
      end

      text += entries.first(10).map { |entry| "- #{entry}" }
    end

    escape(text.join("\n"))
  end
end

#titleObject



11
12
13
# File 'lib/data_checks/notifiers/slack_default_formatter.rb', line 11

def title
  escape("Check #{@check_run.status.titleize}: #{@check_run.name}")
end