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

67 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2019-07-07 11:18:12 +05:30
class Release < ApplicationRecord
2016-11-03 12:29:30 +05:30
include CacheMarkdownField
2019-02-15 15:39:39 +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-15 15:39:39 +05:30
# releases prior to 11.7 have no author
belongs_to :author, class_name: 'User'
has_many :links, class_name: 'Releases::Link'
2019-09-30 21:07:59 +05:30
default_value_for :released_at, allows_nil: false do
Time.zone.now
end
2019-02-15 15:39:39 +05:30
accepts_nested_attributes_for :links, allow_destroy: true
2015-11-26 14:37:03 +05:30
validates :description, :project, :tag, presence: true
2019-07-31 22:56:46 +05:30
validates :name, presence: true, on: :create
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
scope :sorted, -> { order(released_at: :desc) }
2019-02-15 15:39:39 +05:30
delegate :repository, to: :project
def commit
strong_memoize(:commit) do
repository.commit(actual_sha)
end
end
def tag_missing?
actual_tag.nil?
end
2019-07-31 22:56:46 +05:30
def assets_count(except: [])
links_count = links.count
sources_count = except.include?(:sources) ? 0 : sources.count
links_count + sources_count
2019-02-15 15:39:39 +05:30
end
def sources
strong_memoize(:sources) do
Releases::Source.all(project, tag)
end
end
2019-09-30 21:07:59 +05:30
def upcoming_release?
released_at.present? && released_at > Time.zone.now
end
2019-02-15 15:39:39 +05:30
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