2016-06-10 21:36:54 +00:00
|
|
|
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
|
2016-06-14 11:51:12 +00:00
|
|
|
validates_associated :project
|
|
|
|
validates_associated :environment
|
2016-06-10 21:36:54 +00:00
|
|
|
|
|
|
|
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
|
2016-06-14 12:47:00 +00:00
|
|
|
|
|
|
|
def last?
|
|
|
|
self == environment.last_deployment
|
|
|
|
end
|
2016-06-10 21:36:54 +00:00
|
|
|
end
|