2016-06-10 17:36:54 -04:00
|
|
|
class Deployment < ActiveRecord::Base
|
|
|
|
include InternalId
|
|
|
|
|
2016-06-15 09:09:50 -04:00
|
|
|
belongs_to :project, required: true, validate: true
|
|
|
|
belongs_to :environment, required: true, validate: true
|
2016-06-10 17:36:54 -04:00
|
|
|
belongs_to :user
|
|
|
|
belongs_to :deployable, polymorphic: true
|
|
|
|
|
2016-06-14 12:34:48 -04:00
|
|
|
validates :sha, presence: true
|
|
|
|
validates :ref, presence: true
|
2016-06-10 17:36:54 -04:00
|
|
|
|
|
|
|
delegate :name, to: :environment, prefix: true
|
|
|
|
|
2016-06-20 13:22:08 -04:00
|
|
|
after_save :keep_around_commit
|
|
|
|
|
2016-06-10 17:36:54 -04:00
|
|
|
def commit
|
|
|
|
project.commit(sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_title
|
|
|
|
commit.try(:title)
|
|
|
|
end
|
|
|
|
|
|
|
|
def short_sha
|
2016-06-14 12:34:48 -04:00
|
|
|
Commit.truncate_sha(sha)
|
2016-06-10 17:36:54 -04:00
|
|
|
end
|
2016-06-14 08:47:00 -04:00
|
|
|
|
|
|
|
def last?
|
|
|
|
self == environment.last_deployment
|
|
|
|
end
|
2016-06-20 13:22:08 -04:00
|
|
|
|
|
|
|
def keep_around_commit
|
|
|
|
project.repository.keep_around(self.sha)
|
|
|
|
end
|
2016-07-16 12:39:58 -04:00
|
|
|
|
2016-07-16 17:06:34 -04:00
|
|
|
def manual_actions
|
2016-07-16 19:48:51 -04:00
|
|
|
deployable.try(:other_actions)
|
2016-07-16 12:39:58 -04:00
|
|
|
end
|
2016-08-02 08:01:22 -04:00
|
|
|
|
2016-08-09 09:11:14 -04:00
|
|
|
def includes_commit?(commit)
|
2016-08-02 08:01:22 -04:00
|
|
|
return false unless commit
|
|
|
|
|
2016-08-03 07:37:39 -04:00
|
|
|
project.repository.is_ancestor?(commit.id, sha)
|
2016-08-02 08:01:22 -04:00
|
|
|
end
|
2016-06-10 17:36:54 -04:00
|
|
|
end
|