gitlab-org--gitlab-foss/app/models/deployment.rb

47 lines
882 B
Ruby
Raw Normal View History

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