debian-mirror-gitlab/app/models/release.rb

55 lines
1,014 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2015-11-26 14:37:03 +05:30
class Release < ActiveRecord::Base
2016-11-03 12:29:30 +05:30
include CacheMarkdownField
2019-02-13 22:33:31 +05:30
include Gitlab::Utils::StrongMemoize
2016-11-03 12:29:30 +05:30
cache_markdown_field :description
2015-11-26 14:37:03 +05:30
belongs_to :project
2019-02-13 22:33:31 +05:30
# 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
2015-11-26 14:37:03 +05:30
validates :description, :project, :tag, presence: true
2019-02-13 22:33:31 +05:30
scope :sorted, -> { order(created_at: :desc) }
delegate :repository, to: :project
def commit
strong_memoize(:commit) do
repository.commit(actual_sha)
end
end
def tag_missing?
actual_tag.nil?
end
def assets_count
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
end
def actual_tag
strong_memoize(:actual_tag) do
repository.find_tag(tag)
end
end
2015-11-26 14:37:03 +05:30
end