Class: HipchatNotification::Message

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

Instance Method Summary collapse

Constructor Details

#initialize(deploy) ⇒ Message

Returns a new instance of Message.



25
26
27
28
29
30
31
# File 'app/models/hipchat_notification.rb', line 25

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

Instance Method Details

#contentObject



55
56
57
58
# File 'app/models/hipchat_notification.rb', line 55

def content
  return subject if @deploy.job.succeeded? || @deploy.job.failed? || @deploy.job.errored?
  @content ||= HipchatNotificationRenderer.render(@deploy, subject)
end

#fromObject



37
38
39
# File 'app/models/hipchat_notification.rb', line 37

def from
  "Deploy"
end

#styleObject



33
34
35
# File 'app/models/hipchat_notification.rb', line 33

def style
  {:color => color}
end

#subjectObject



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

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

  subject = "#{@user.name} successfully deploy <strong>#{@project.name}</strong> @<a href='#{diff_url}'>#{@deploy.commit}...#{@changeset.try(:previous_commit)}</a> on <strong>#{@stage.name}</strong><br>" if @deploy.job.succeeded?

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

  subject
end

#to_sObject



51
52
53
# File 'app/models/hipchat_notification.rb', line 51

def to_s
  content
end