# The MIT License # Copyright © 2009 Magnus Bergmark # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. class GitRemoteMonitor::Notifiers::Meow < GitRemoteMonitor::Notifiers::Base class << self def available? # Try to load the meow gem require 'meow' return true rescue LoadError return false end end def initialize @meow = ::Meow.new('git-remote-monitor') end def send_notification!(status) message = get_message(status) if message @meow.notify(notification_title(status), message, :icon => notification_icon(status), :note_type => notification_type(status)) end end protected def notification_title(status) "#{status.name} (#{status.branch_name})" end def notification_icon(status) # TODO: Different icons for each status type "#{GitRemoteMonitor.root}/images/git-logo.png" end def notification_type(status) status.type.to_s.capitalize end def get_message(status) case status.type when :local # Don't bother notify on local changes only nil when :diverged "Diverged! Remote has #{status.remote_commits} new commit(s), and you have #{status.local_commits} commit(s) to push." when :remote "Remote got updated! Now #{status.remote_commits} commit(s) in front of you." else raise "Unknown case. This is a bug! Please report it with the stack trace. Thank you." end end end