Sha256: c7129c20e4e6f1f9bddc1e2a7d1714ac768c71b95ae61c5c4c62e6272927cfad

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

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

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

    attribute :notify, 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"

  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

9 entries across 9 versions & 1 rubygems

Version Path
codeclimate-services-0.6.1 lib/cc/services/hipchat.rb
codeclimate-services-0.6.0 lib/cc/services/hipchat.rb
codeclimate-services-0.5.3 lib/cc/services/hipchat.rb
codeclimate-services-0.5.2 lib/cc/services/hipchat.rb
codeclimate-services-0.5.1 lib/cc/services/hipchat.rb
codeclimate-services-0.5.0 lib/cc/services/hipchat.rb
codeclimate-services-0.4.1 lib/cc/services/hipchat.rb
codeclimate-services-0.4.0 lib/cc/services/hipchat.rb
codeclimate-services-0.3.0 lib/cc/services/hipchat.rb