Sha256: 219b916ed587f2e684bd4109f80b8ef6c399781d790d9c9296bd90730dd0b0ce

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

class CC::Service::HipChat < CC::Service
  class Config < CC::Service::Config
    attribute :auth_token, Axiom::Types::String,
      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

10 entries across 10 versions & 1 rubygems

Version Path
codeclimate-services-1.9.7 lib/cc/services/hipchat.rb
codeclimate-services-1.9.6 lib/cc/services/hipchat.rb
codeclimate-services-1.9.5 lib/cc/services/hipchat.rb
codeclimate-services-1.9.4 lib/cc/services/hipchat.rb
codeclimate-services-1.9.3 lib/cc/services/hipchat.rb
codeclimate-services-1.9.2 lib/cc/services/hipchat.rb
codeclimate-services-1.9.1 lib/cc/services/hipchat.rb
codeclimate-services-1.9.0 lib/cc/services/hipchat.rb
codeclimate-services-1.8.0 lib/cc/services/hipchat.rb
codeclimate-services-1.7.0 lib/cc/services/hipchat.rb