Sha256: 347300224b1cb02371e008a3700b1c27db235b8d7fc856771181c3da55645632

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

class CC::Service::HipChat < CC::Service
  class Config < CC::Service::Config
    attribute :auth_token, Axiom::Types::Token,
      description: "Your HipChat API auth token"

    attribute :room_id, Axiom::Types::String,
      description: "The ID or name of the HipChat chat room to send notifications to"

    attribute :notify, Axiom::Types::Boolean, default: false,
      description: "Should we trigger a notification for people in the room?"

    validates :auth_token, presence: true
    validates :room_id, presence: true
  end

  BASE_URL = "https://api.hipchat.com/v1".freeze

  self.description = "Send messages to a HipChat chat room"

  def receive_test
    speak(formatter.format_test, "green").merge(
      message: "Test message sent",
    )
  end

  def receive_coverage
    speak(formatter.format_coverage, color)
  end

  def receive_quality
    speak(formatter.format_quality, color)
  end

  def receive_vulnerability
    speak(formatter.format_vulnerability, "red")
  end

  private

  def formatter
    CC::Formatters::LinkedFormatter.new(self, prefix: nil, link_style: :html)
  end

  def speak(message, color)
    url = "#{BASE_URL}/rooms/message"
    params = {
      from:       "Code Climate",
      message:    message,
      auth_token: config.auth_token,
      room_id:    config.room_id,
      notify:     !!config.notify,
      color:      color,
    }
    service_post(url, params)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
codeclimate-services-1.11.4 lib/cc/services/hipchat.rb
codeclimate-services-1.11.3 lib/cc/services/hipchat.rb
codeclimate-services-1.11.2 lib/cc/services/hipchat.rb
codeclimate-services-1.11.1 lib/cc/services/hipchat.rb
codeclimate-services-1.11.0 lib/cc/services/hipchat.rb
codeclimate-services-1.10.1 lib/cc/services/hipchat.rb
codeclimate-services-1.10.0 lib/cc/services/hipchat.rb
codeclimate-services-1.9.8 lib/cc/services/hipchat.rb