2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-05 05:03:02 -05:00
|
|
|
class Release < ActiveRecord::Base
|
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'
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :links, allow_destroy: true
|
|
|
|
|
2015-11-09 09:30:50 -05:00
|
|
|
validates :description, :project, :tag, presence: true
|
2018-12-13 06:08:53 -05:00
|
|
|
|
2018-12-21 09:51:46 -05:00
|
|
|
scope :sorted, -> { order(created_at: :desc) }
|
|
|
|
|
2018-12-13 06:08:53 -05:00
|
|
|
delegate :repository, to: :project
|
|
|
|
|
|
|
|
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-01-01 20:40:33 -05:00
|
|
|
def assets_count
|
2019-01-02 20:26:14 -05:00
|
|
|
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
|
|
|
|
|
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
|
2015-11-05 05:03:02 -05:00
|
|
|
end
|