Sha256: 5c30c19ac75041087a9b1c4b1856e53f38f2ca65468f0311fe3003aaff9f4d65

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

require "json"
require "net/http"
require "uri"

module Tomo::Plugin::Rollbar
  class Tasks < ::Tomo::TaskLibrary
    def notify_deploy
      require_settings :rollbar_env, :rollbar_token

      http_post(
        "https://api.rollbar.com/api/1/deploy/",
        local_username: remote.release[:deploy_user],
        access_token:   settings.fetch(:rollbar_token),
        environment:    settings.fetch(:rollbar_env),
        revision:       remote.release[:revision]
      )

      logger.info("Rollbar notification complete.")
    end

    private

    def http_post(url, params)
      uri = URI(url)
      request = Net::HTTP::Post.new(uri.request_uri)
      request.body = ::JSON.dump(params)
      request["Content-Type"] = "application/json"

      logger.debug("Building Rollbar POST to #{uri} with #{params.inspect}")
      return if dry_run?

      response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
        http.request(request)
      end
      handle_error(response)
    end

    def handle_error(response)
      return if response.is_a?(Net::HTTPSuccess)

      die("#{response.code} #{response.message}")
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
tomo-plugin-rollbar-1.3.1 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.3.0 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.2.2 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.2.1 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.2.0 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.5 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.4 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.3 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.2 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.1 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.1.0 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.0.3 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.0.2 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.0.1 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-1.0.0 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-0.1.1 lib/tomo/plugin/rollbar/tasks.rb
tomo-plugin-rollbar-0.1.0 lib/tomo/plugin/rollbar/tasks.rb