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

110 lines
2.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
2019-12-26 22:10:19 +05:30
include Presentable
2016-11-03 12:29:30 +05:30
include CacheMarkdownField
2020-03-09 13:42:32 +05:30
include Importable
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-12-04 20:38:33 +05:30
has_many :milestone_releases
has_many :milestones, through: :milestone_releases
2019-12-21 20:55:43 +05:30
has_one :evidence
2019-12-04 20:38:33 +05:30
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-12-04 20:38:33 +05:30
validates_associated :milestone_releases, message: -> (_, obj) { obj[:value].map(&:errors).map(&:full_messages).join(",") }
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
scope :sorted, -> { order(released_at: :desc) }
2019-12-26 22:10:19 +05:30
scope :preloaded, -> { includes(project: :namespace) }
2019-12-21 20:55:43 +05:30
scope :with_project_and_namespace, -> { includes(project: :namespace) }
2019-12-26 22:10:19 +05:30
scope :recent, -> { sorted.limit(MAX_NUMBER_TO_DISPLAY) }
2019-02-15 15:39:39 +05:30
delegate :repository, to: :project
2020-03-09 13:42:32 +05:30
after_commit :notify_new_release, on: :create, unless: :importing?
2019-12-21 20:55:43 +05:30
2019-12-26 22:10:19 +05:30
MAX_NUMBER_TO_DISPLAY = 3
def to_param
CGI.escape(tag)
end
2019-02-15 15:39:39 +05:30
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
2020-03-09 13:42:32 +05:30
def historical_release?
released_at.present? && released_at < created_at
end
2019-12-26 22:10:19 +05:30
def name
self.read_attribute(:name) || tag
end
2020-01-01 13:55:28 +05:30
def evidence_sha
evidence&.summary_sha
end
def evidence_summary
evidence&.summary || {}
end
2020-03-09 13:42:32 +05:30
def milestone_titles
self.milestones.map {|m| m.title }.sort.join(", ")
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
2019-12-21 20:55:43 +05:30
def notify_new_release
NewReleaseWorker.perform_async(id)
end
2015-11-26 14:37:03 +05:30
end
2019-12-21 20:55:43 +05:30
Release.prepend_if_ee('EE::Release')