2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 09:17:42 -04:00
|
|
|
class Release < ApplicationRecord
|
2019-10-23 17:06:17 -04:00
|
|
|
include Presentable
|
2016-10-06 17:17:11 -04:00
|
|
|
include CacheMarkdownField
|
2018-12-25 04:48:26 -05:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2016-10-06 17:17:11 -04:00
|
|
|
|
|
|
|
cache_markdown_field :description
|
|
|
|
|
2015-11-06 09:29:04 -05:00
|
|
|
belongs_to :project
|
2018-12-13 06:08:53 -05:00
|
|
|
# releases prior to 11.7 have no author
|
2018-12-12 04:56:43 -05:00
|
|
|
belongs_to :author, class_name: 'User'
|
2015-11-06 09:29:04 -05:00
|
|
|
|
2019-01-01 20:40:33 -05:00
|
|
|
has_many :links, class_name: 'Releases::Link'
|
|
|
|
|
2019-09-16 11:06:26 -04:00
|
|
|
has_many :milestone_releases
|
|
|
|
has_many :milestones, through: :milestone_releases
|
2019-10-17 11:06:17 -04:00
|
|
|
has_one :evidence
|
2019-09-03 05:38:59 -04:00
|
|
|
|
2019-07-03 05:12:15 -04:00
|
|
|
default_value_for :released_at, allows_nil: false do
|
|
|
|
Time.zone.now
|
|
|
|
end
|
|
|
|
|
2019-01-01 20:40:33 -05:00
|
|
|
accepts_nested_attributes_for :links, allow_destroy: true
|
|
|
|
|
2015-11-09 09:30:50 -05:00
|
|
|
validates :description, :project, :tag, presence: true
|
2019-09-16 11:06:26 -04:00
|
|
|
validates_associated :milestone_releases, message: -> (_, obj) { obj[:value].map(&:errors).map(&:full_messages).join(",") }
|
2018-12-13 06:08:53 -05:00
|
|
|
|
2019-07-03 05:12:15 -04:00
|
|
|
scope :sorted, -> { order(released_at: :desc) }
|
2019-10-31 23:06:26 -04:00
|
|
|
scope :preloaded, -> { includes(project: :namespace) }
|
2019-11-04 10:07:36 -05:00
|
|
|
scope :with_project_and_namespace, -> { includes(project: :namespace) }
|
|
|
|
scope :recent, -> { sorted.limit(MAX_NUMBER_TO_DISPLAY) }
|
2018-12-21 09:51:46 -05:00
|
|
|
|
2018-12-13 06:08:53 -05:00
|
|
|
delegate :repository, to: :project
|
|
|
|
|
2019-10-17 11:06:17 -04:00
|
|
|
after_commit :create_evidence!, on: :create
|
2019-10-17 14:08:05 -04:00
|
|
|
after_commit :notify_new_release, on: :create
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2019-11-04 10:07:36 -05:00
|
|
|
MAX_NUMBER_TO_DISPLAY = 3
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
def to_param
|
|
|
|
CGI.escape(tag)
|
|
|
|
end
|
|
|
|
|
2018-12-13 06:08:53 -05:00
|
|
|
def commit
|
2018-12-25 04:48:26 -05:00
|
|
|
strong_memoize(:commit) do
|
|
|
|
repository.commit(actual_sha)
|
|
|
|
end
|
2018-12-13 06:08:53 -05:00
|
|
|
end
|
2018-12-21 09:13:23 -05:00
|
|
|
|
2018-12-25 04:48:26 -05:00
|
|
|
def tag_missing?
|
|
|
|
actual_tag.nil?
|
2018-12-21 09:13:23 -05:00
|
|
|
end
|
|
|
|
|
2019-05-03 09:29:20 -04:00
|
|
|
def assets_count(except: [])
|
|
|
|
links_count = links.count
|
|
|
|
sources_count = except.include?(:sources) ? 0 : sources.count
|
|
|
|
|
|
|
|
links_count + sources_count
|
2019-01-01 20:40:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def sources
|
|
|
|
strong_memoize(:sources) do
|
|
|
|
Releases::Source.all(project, tag)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-03 05:12:15 -04:00
|
|
|
def upcoming_release?
|
|
|
|
released_at.present? && released_at > Time.zone.now
|
|
|
|
end
|
|
|
|
|
2019-11-12 16:06:30 -05:00
|
|
|
def name
|
|
|
|
self.read_attribute(:name) || tag
|
|
|
|
end
|
|
|
|
|
2019-11-19 04:06:16 -05:00
|
|
|
def evidence_sha
|
|
|
|
evidence&.summary_sha
|
|
|
|
end
|
|
|
|
|
|
|
|
def evidence_summary
|
|
|
|
evidence&.summary || {}
|
|
|
|
end
|
|
|
|
|
2018-12-25 04:48:26 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def actual_sha
|
|
|
|
sha || actual_tag&.dereferenced_target
|
2018-12-21 09:13:23 -05:00
|
|
|
end
|
|
|
|
|
2018-12-25 04:48:26 -05:00
|
|
|
def actual_tag
|
|
|
|
strong_memoize(:actual_tag) do
|
|
|
|
repository.find_tag(tag)
|
|
|
|
end
|
2018-12-21 09:13:23 -05:00
|
|
|
end
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
def create_evidence!
|
|
|
|
CreateEvidenceWorker.perform_async(self.id)
|
|
|
|
end
|
2019-10-17 14:08:05 -04:00
|
|
|
|
|
|
|
def notify_new_release
|
|
|
|
NewReleaseWorker.perform_async(id)
|
|
|
|
end
|
2015-11-05 05:03:02 -05:00
|
|
|
end
|
2019-10-03 20:06:03 -04:00
|
|
|
|
|
|
|
Release.prepend_if_ee('EE::Release')
|