Sha256: cf10e97f3d26768f642e10b978909491683f25a9b68f060af62807af48792f43

Contents?: true

Size: 1.5 KB

Versions: 7

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

require "kapost_deploy/heroku/app_releases"

module KapostDeploy
  module Plugins
    # After-promotion plugin to notify honeybadger after a promotion is complete.
    # Honeybadger.io can be configured to clear all honeybadgers upon this deploy notification.
    class NotifyHoneyBadgerAfterPromote
      def initialize(config,
                     ahead_releases: KapostDeploy::Heroku::AppReleases.new(config.app, token: config.heroku_api_token),
                     kernel: Kernel)

        self.config = config
        self.git_config = config.options.fetch(:git_config, {})
        self.ahead_releases = ahead_releases
        self.kernel = kernel
      end

      def after
        return unless configured?

        notify_honeybadger
      end

      private

      attr_accessor :config, :git_config, :ahead_releases, :kernel

      def notify_honeybadger
        kernel.system("bundle exec honeybadger deploy -e #{env} -s #{commit_sha} -r #{repository_url}")
      end

      def env
        config.to.split("-").last
      end

      def commit_sha
        ci_sha || pipeline_sha
      end

      def ci_sha
        ENV["CIRCLE_SHA1"]
      end

      def pipeline_sha
        ahead_releases.latest_deploy_version
      end

      def github_repo
        git_config[:github_repo] unless git_config.nil?
      end

      def repository_url
        "https://github.com/#{github_repo}"
      end

      def configured?
        !github_repo.nil? && !github_repo.empty?
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kapost_deploy-0.7.1 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.7.0 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.6.2 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.6.1 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.5.0 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.4.0 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb
kapost_deploy-0.3.0 lib/kapost_deploy/plugins/notify_honeybadger_after_promote.rb