Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 66 lines (55 sloc) 1.555 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
class ProwlNotifier
  begin
    require "prowler"
  rescue LoadError
    puts "Prowler gem missing.\nsudo gem install pixeltrix-prowler --source=http://gems.github.com"
    raise
  end

  attr_accessor :keys
  attr_accessor :from
  
  def initialize(project = nil)
    @keys = []
  end

  def from
    @from || "CruiseControl.rb"
  end

  def build_broken(build, previous_build)
    return if keys.empty?
    notify("Build failed",
           enhance_description("#{build.project.name} build #{build.label} broken", build),
           Prowler::Priority::HIGH)
  end

  def build_fixed(build, previous_build)
    return if keys.empty?
    notify("Build fixed",
           enhance_description("#{build.project.name} build #{build.label} fixed", build),
          Prowler::Priority::NORMAL)
  end
  
  private
  
  def notify(event, description, priority = Prowler::Priority::NORMAL)
    keys.each do |key|
      Prowler.new(key, from).notify(event, description, priority)
    end
    CruiseControl::Log.event("Sent Prowl notification to #{keys.size == 1 ? "1 person" : "#{keys.size} people"}", :debug)
  rescue => e
    CruiseControl::Log.event("Error sending prowl notification", :error)
    raise
  end

  def enhance_description(desc, build)
    if Configuration.dashboard_url
      desc += " See #{short_url(build.url)} for details."
    end
    desc
  end

  begin
    require "shorturl"

    def short_url(url)
      ShortURL.shorten(url)
    end
  rescue LoadError
    def short_url(url)
      url
    end
  end
end

Project.plugin :prowl_notifier
Something went wrong with that request. Please try again.