Class: HipchatNotification::Message

Inherits:
Object
  • Object
show all
Defined in:
app/models/hipchat_notification.rb

Instance Method Summary collapse

Constructor Details

#initialize(deploy, is_multi_message) ⇒ Message



40
41
42
43
44
45
46
47
# File 'app/models/hipchat_notification.rb', line 40

def initialize(deploy, is_multi_message)
  @deploy = deploy
  @stage = deploy.stage
  @project = @stage.project
  @user = @deploy.user
  @changeset = @deploy.changeset
  @is_multi_message = is_multi_message
end

Instance Method Details

#contentObject



77
78
79
80
81
82
83
84
# File 'app/models/hipchat_notification.rb', line 77

def content
  if @is_multi_message
    return subject if @deploy.job.succeeded? || @deploy.job.failed? || @deploy.job.errored?
    @content ||= HipchatNotificationRenderer.render(@deploy, subject, {is_multi_message: true})
  else
    @content ||= HipchatNotificationRenderer.render(@deploy, subject)
  end
end

#fromObject



53
54
55
# File 'app/models/hipchat_notification.rb', line 53

def from
  "Deploy"
end

#styleObject



49
50
51
# File 'app/models/hipchat_notification.rb', line 49

def style
  {:color => color, :notify => @is_multi_message}
end

#subjectObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/hipchat_notification.rb', line 57

def subject
  if @is_multi_message
    subject = "#{@user.name} is <a href='#{deploy_url}'>deploying</a> <strong>#{@project.name}</strong> to <strong>#{@stage.name}</strong><br>"

    subject = "#{@user.name} successfully deployed <strong>#{@project.name}</strong> @<a href='#{diff_url}'>#{@deploy.commit}</a> to <strong>#{@stage.name}</strong><br>" if @deploy.job.succeeded?

    subject = "#{@user.name} failed to <a href='#{deploy_url}'>deployed</a> <strong>#{@project.name}</strong> to <strong>#{@stage.name}</strong><br>" if @deploy.job.failed? || @deploy.job.errored?

    subject = "#{@user.name} cancelled <a href='#{deploy_url}'>deploy</a> <strong>#{@project.name}</strong> to <strong>#{@stage.name}</strong><br>" if @deploy.job.cancelled?

    subject
  else
    subject = "#{@user.name} successfully deployed <strong>#{@project.name}</strong> @ <a href='#{diff_url}'>#{@deploy.commit}</a> to <strong>#{@stage.name}</strong><br>" if @deploy.job.succeeded?
  end
end

#to_sObject



73
74
75
# File 'app/models/hipchat_notification.rb', line 73

def to_s
  content
end