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

55 lines
1,014 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class Release < ActiveRecord::Base
include CacheMarkdownField
include Gitlab::Utils::StrongMemoize
cache_markdown_field :description
belongs_to :project
# releases prior to 11.7 have no author
belongs_to :author, class_name: 'User'
has_many :links, class_name: 'Releases::Link'
accepts_nested_attributes_for :links, allow_destroy: true
validates :description, :project, :tag, presence: true
scope :sorted, -> { order(created_at: :desc) }
delegate :repository, to: :project
def commit
strong_memoize(:commit) do
repository.commit(actual_sha)
end
end
2018-12-21 09:13:23 -05:00
def tag_missing?
actual_tag.nil?
2018-12-21 09:13:23 -05:00
end
def assets_count
2019-01-02 20:26:14 -05:00
links.count + sources.count
end
def sources
strong_memoize(:sources) do
Releases::Source.all(project, tag)
end
end
private
def actual_sha
sha || actual_tag&.dereferenced_target
2018-12-21 09:13:23 -05:00
end
def actual_tag
strong_memoize(:actual_tag) do
repository.find_tag(tag)
end
2018-12-21 09:13:23 -05:00
end
end