summaryrefslogtreecommitdiff
path: root/app/models/deployment.rb
blob: 44a0a7fdd101c70e756721b1b54e8bab9ac5b4e4 (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
class Deployment < ActiveRecord::Base
  include InternalId

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

  validates_presence_of :sha
  validates_presence_of :ref
  validates_associated :project
  validates_associated :environment

  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
end