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



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

def content
  if @is_multi_message
    return subject if @deploy.job.succeeded? || @deploy.job.failed? || @deploy.job.errored?
    @content ||= HipchatNotificationRenderer.render(@deploy, subject)
  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 => true}
end

#subjectObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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> on <strong>#{@stage.name}</strong><br>"

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

    subject = "#{@user.name} failed to <a href='#{deploy_url}'>deployed</a> <strong>#{@project.name}</strong> on <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> on <strong>#{@stage.name}</strong><br>" if @deploy.job.cancelled?

    subject
  else
    #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} successfully deploy <strong>#{@project.name}</strong> @ <a href='#{diff_url}'>#{@deploy.commit}</a> on <strong>#{@stage.name}</strong><br>" if @deploy.job.succeeded?
  end
end

#to_sObject



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

def to_s
  content
end