gitlab-org--gitlab-foss/app/models/release.rb
Jason Goodman 7ecffe2987 Show upcoming status for releases
Add released_at field to releases API
Add released_at column to releases table
Return releases to the API sorted by released_at
2019-07-03 09:12:15 +00:00

66 lines
1.3 KiB
Ruby

# frozen_string_literal: true
class Release < ApplicationRecord
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'
default_value_for :released_at, allows_nil: false do
Time.zone.now
end
accepts_nested_attributes_for :links, allow_destroy: true
validates :description, :project, :tag, presence: true
validates :name, presence: true, on: :create
scope :sorted, -> { order(released_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(except: [])
links_count = links.count
sources_count = except.include?(:sources) ? 0 : sources.count
links_count + sources_count
end
def sources
strong_memoize(:sources) do
Releases::Source.all(project, tag)
end
end
def upcoming_release?
released_at.present? && released_at > Time.zone.now
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
end