self.fire_hook

in lib/release_tools/slack/webhook.rb [14:42]


      def self.fire_hook(text: nil, channel: nil, attachments: [], blocks: [])
        
        
        return unless webhook_url.present?

        body = {}

        body[:text] = text if text.present?
        body[:channel] = channel if channel.present?
        body[:attachments] = attachments if attachments.any?
        body[:blocks] = blocks if blocks.any?

        logger.trace(__method__, body)

        if Feature.enabled?(:slack_down)
          logger.warn("Not attempting to call Slack webhook API because FF 'slack_down' is enabled", body: body)
          return
        end

        response = HTTP.post(webhook_url, json: body)

        return if response.status.success?

        logger.info("#{__method__} request", body)
        logger.info("#{__method__} response", code: response.code, body: response.body.to_s, response: response.inspect)

        raise CouldNotPostError.new("#{response.code} #{response.reason} #{response.body}")
      end