Sha256: d6208b1bcc8ce20c84d680d473f96a099924cc0d697cfbfa992e9446ef01e7a9

Contents?: true

Size: 1.93 KB

Versions: 24

Compression:

Stored size: 1.93 KB

Contents

require 'json'
require 'shellwords'

module DPL
  class Provider
    module Heroku
      class API < Git
        def needs_key?
          false
        end

        def user
          @user ||= api.get_user.body["email"]
        end

        def push_app
          pack_archive
          upload_archive
          trigger_build
        end

        def archive_file
          Shellwords.escape("#{ENV['HOME']}/.dpl.#{option(:app)}.tgz")
        end

        def pack_archive
          log "creating application archive"
          context.shell "tar -zcf #{archive_file} ."
        end

        def upload_archive
          log "uploading application archive"
          context.shell "curl #{Shellwords.escape(put_url)} -X PUT -H 'Content-Type:' --data-binary @#{archive_file}"
        end

        def trigger_build
          log "triggering new deployment"
          response   = post(:builds, source_blob: { url: get_url, version: version })
          stream_url = response.fetch('stream_url')
          context.shell "curl #{Shellwords.escape(stream_url)}"
        end

        def get_url
          source_blob.fetch("get_url")
        end

        def put_url
          source_blob.fetch("put_url")
        end

        def source_blob
          @source_blog ||= post(:sources).fetch("source_blob")
        end

        def version
          @version ||= options[:version] || ENV['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
        end

        def post(subpath, body = nil, options = {})
          options = {
            method: :post,
            path: "/apps/#{option(:app)}/#{subpath}",
            headers: { "Accept" => "application/vnd.heroku+json; version=edge" },
            expects: [200, 201]
          }.merge(options)

          if body
            options[:body]                    = JSON.dump(body)
            options[:headers]['Content-Type'] = 'application/json'
          end

          api.request(options).body
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
dpl-1.7.4.travis.600.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.3 lib/dpl/provider/heroku/api.rb
dpl-1.7.3.travis.597.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.3.travis.594.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.592.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.591.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.590.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.589.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.588.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.586.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.584.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.582.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.581.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.2.travis.579.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.1.travis.578.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.1.travis.577.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.1.travis.575.1 lib/dpl/provider/heroku/api.rb
dpl-1.7.1.travis.570.1 lib/dpl/provider/heroku/api.rb