Sha256: d9b1dde76ce07cf1d233533624bb1c495c930fb7a21fef6b88c566c77496bc70

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'json'
require 'net/http'

namespace :jianliao do
  namespace :deploy do
    task :updated do
      if fetch(:jianliao_url)
        run_locally do
          elapsed = 1
          announcement = "#{announced_application_name} successfully deployed."

          post_jianliao_message(announcement)
        end
      end
    end

    def short_revision
      deployed_revision = fetch(:deployed_revision)
      deployed_revision[0..7] if deployed_revision
    end

    def announced_application_name
      jianliao_application = fetch(:jianliao_application)
      "".tap do |output|
        output << jianliao_application if jianliao_application
        output << " (#{short_revision})" if short_revision
      end
    end

    def post_jianliao_message(message)
      uri = URI(fetch(:jianliao_url))

      payload = {
        "authorName" => fetch(:jianliao_authorname),
        "text" => message
      }

      res = Net::HTTP.post_form(uri, payload)
    end
  end
end

after  'deploy:finishing',  'jianliao:deploy:updated'

namespace :load do
  task :defaults do
    set :jianliao_url,            -> { ENV['JIANLIAO_URL'] } # Incoming WebHook URL.
    set :jianliao_application,    -> { ENV['JIANLIAO_APPLICATION'] || 'application' }
    set :jianliao_authorname,     -> { ENV['JIANLIAO_AUTHORNAME'] || 'deploybot' }

    set :deployer,          -> { ENV['GIT_AUTHOR_NAME'] || %x[git config user.name].chomp }
    set :deployed_revision, -> { ENV['GIT_COMMIT'] || %x[git rev-parse #{fetch :branch}].strip }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capistrano-jianliao-0.1.0 lib/capistrano/jianliao/tasks/jianliao.rake