summaryrefslogtreecommitdiff
path: root/app/models/deployment.rb
blob: d9006b70e3058b67571ab73cb77ade553bf6c8db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Deployment < ActiveRecord::Base
  include InternalId

  belongs_to :project
  belongs_to :environment
  belongs_to :user
  belongs_to :deployable, polymorphic: true

  validates :sha, presence: true
  validates :ref, presence: true
  validates :project, associated: true
  validates :environment, associated: true

  delegate :name, to: :environment, prefix: true

  def commit
    project.commit(sha)
  end

  def commit_title
    commit.try(:title)
  end

  def short_sha
    Commit.truncate_sha(sha)
  end

  def last?
    self == environment.last_deployment
  end
end