module Capistrano::Jabber::Notifications

Constants

VERSION

Attributes

options[RW]
variables[RW]

Public Class Methods

deploy_completed() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 19
def deploy_completed
  send_jabber_message "deploy", true
end
deploy_started() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 15
def deploy_started
  send_jabber_message "deploy"
end
rollback_completed() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 27
def rollback_completed
  send_jabber_message "deploy:rollback", true
end
rollback_started() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 23
def rollback_started
  send_jabber_message "deploy:rollback"
end

Private Class Methods

git_log_revisions() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 33
def git_log_revisions
  current, real = variables[:current_revision][0,7], variables[:real_revision][0,7]

  if current == real
    "GIT: No changes ..."
  else
    if (diff = `git log #{current}..#{real} --oneline`) != ""
      diff = "  " << diff.gsub("\n", "\n    ") << "\n"
      "\nGIT Changes:\n" + diff
    else
      "GIT: Git-log problem ..."
    end
  end
end
send_jabber_message(action, completed = false) click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 48
def send_jabber_message(action, completed = false)
  msg = []
  msg << "#{completed ? 'Completed' : 'Started'} #{action} on #{variables[:stage]} by #{username}"
  msg << "Time #{Time.now.to_s}"
  msg << "Application #{variables[:application]}"
  msg << "Branch #{variables[:branch]}"
  msg << "Revision #{options[:real_revision]}"
  msg << "Release name #{options[:release_name]}"
  msg << git_log_revisions if variables[:source].is_a?(Capistrano::Deploy::SCM::Git)
  msg = msg.join("\r\n")

  client = ::Jabber::Client.new(options[:uid].to_s)
  client.connect(options[:server].to_s)
  client.auth(options[:password].to_s)
  notification_group = options[:group].to_s
  notification_list = options[:members]

  roster = ::Jabber::Roster::Helper.new(client)

  mainthread = Thread.current
  roster.add_query_callback { |iq| mainthread.wakeup }
  Thread.stop

  roster.find_by_group(notification_group).each {|item|
    client.send(item.jid)
    m = ::Jabber::Message.new(item.jid, msg).set_type(:normal).set_id('1').set_subject('deploy')
    client.send(m)
  }

  notification_list.each { |member|
    client.send(member)
    m = ::Jabber::Message.new(member, msg).set_type(:normal).set_id('1').set_subject('deploy')
    client.send(m)
  }

  client.close
  true
end
username() click to toggle source
# File lib/capistrano/jabber/notifications.rb, line 87
def username
  @username ||= [`whoami`, `hostname`].map(&:strip).join('@')
end