Sha256: 7ab6805a48bea90029bd6ce600682408aa22acf8bd5ef16800f4611cf20786d1

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require "platform-api"

module KapostDeploy
  module Heroku
    # Promotes a heroku app via Heroku Plaform API
    class AppPromoter
      def initialize(pipeline, token:)
        self.pipeline = pipeline
        self.token = token
      end

      def promote(from:, to:)
        pipeline_id = discover_pipeline(pipeline)["id"]
        from_id = discover_app(from)["id"]
        to_id   = discover_app(to)["id"]

        promotion_data = {
          pipeline: { id: pipeline_id },
          source: { app: { id: from_id } },
          targets: [{ app: { id: to_id } }]
        }

        wait_for_promotion(heroku.pipeline_promotion.create(promotion_data))
      end

      private

      attr_accessor :pipeline
      attr_accessor :token

      def wait_for_promotion(promotion)
        while promotion["status"] == "pending"
          print "."
          sleep 1
          promotion = heroku.pipeline_promotion.info(promotion["id"])
        end
      end

      def discover_pipeline(pipeline)
        heroku.pipeline.info(pipeline)
      end

      def discover_app(app_name)
        heroku.app.info(app_name)
      end

      def heroku
        @heroku ||= PlatformAPI.connect(token)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
kapost_deploy-0.7.1 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.7.0 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.6.2 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.6.1 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.5.0 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.4.0 lib/kapost_deploy/heroku/app_promoter.rb
kapost_deploy-0.3.0 lib/kapost_deploy/heroku/app_promoter.rb