Class: Ci::Catalog::Resources::Version

Inherits:
ApplicationRecord show all
Includes:
BulkInsertableAssociations, CacheMarkdownField, SemanticVersionable
Defined in:
app/models/ci/catalog/resources/version.rb

Overview

This class represents a CI/CD Catalog resource version. Only versions which contain valid CI components are included in this table.

Constant Summary

Constants included from CacheMarkdownField

CacheMarkdownField::INVALIDATED_BY

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from HasCheckConstraints

HasCheckConstraints::NOT_NULL_CHECK_PATTERN

Constants included from ResetOnColumnErrors

ResetOnColumnErrors::MAX_RESET_PERIOD

Instance Attribute Summary

Attributes included from CacheMarkdownField

#skip_markdown_cache_validation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CacheMarkdownField

#attribute_invalidated?, #banzai_render_context, #cached_html_for, #cached_html_up_to_date?, #can_cache_field?, #invalidated_markdown_cache?, #latest_cached_markdown_version, #mentionable_attributes_changed?, #mentioned_filtered_user_ids_for, #parent_user, #refresh_markdown_cache, #refresh_markdown_cache!, #rendered_field_content, #skip_project_check?, #store_mentions!, #store_mentions_after_commit?, #updated_cached_html_for

Methods included from BulkInsertableAssociations

#bulk_insert_associations!, bulk_inserts_enabled?, with_bulk_insert

Methods inherited from ApplicationRecord

===, cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, nullable_column?, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from ResetOnColumnErrors

#reset_on_union_error, #reset_on_unknown_attribute_error

Methods included from Gitlab::SensitiveSerializableHash

#serializable_hash

Class Method Details

.latest(major = nil, minor = nil) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/ci/catalog/resources/version.rb', line 42

def latest(major = nil, minor = nil)
  raise ArgumentError, 'semver minor version used without major version' if minor.present? &&
    major.blank?

  relation = with_semver
  relation = relation.without_prerelease
  relation = relation.where(semver_major: major) if major
  relation = relation.where(semver_minor: minor) if minor

  relation.order_by_semantic_version_desc.first
end

.versions_for_catalog_resources(catalog_resources) ⇒ Object



54
55
56
57
58
# File 'app/models/ci/catalog/resources/version.rb', line 54

def versions_for_catalog_resources(catalog_resources)
  return none if catalog_resources.empty?

  for_catalog_resources(catalog_resources).with_semver.order_by_semantic_version_desc
end

Instance Method Details

#commitObject



65
66
67
# File 'app/models/ci/catalog/resources/version.rb', line 65

def commit
  project.commit_by(oid: sha)
end

#nameObject



61
62
63
# File 'app/models/ci/catalog/resources/version.rb', line 61

def name
  semver.to_s
end

#pathObject



69
70
71
# File 'app/models/ci/catalog/resources/version.rb', line 69

def path
  Gitlab::Routing.url_helpers.project_tag_path(project, name)
end

#readmeObject



73
74
75
76
77
# File 'app/models/ci/catalog/resources/version.rb', line 73

def readme
  return unless project.repo_exists?

  project.repository.tree(sha).readme&.data
end

#sync_with_release!Object



79
80
81
82
# File 'app/models/ci/catalog/resources/version.rb', line 79

def sync_with_release!
  sync_with_release
  save!
end