Class: Release
Constant Summary
collapse
- MAX_NUMBER_TO_DISPLAY =
3
- MAX_NUMBER_TO_PUBLISH =
5000
CacheMarkdownField::INVALIDATED_BY
ApplicationRecord::MAX_PLUCK
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
ResetOnColumnErrors::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
#importing, #user_contributions
#skip_markdown_cache_validation
Class Method Summary
collapse
Instance Method Summary
collapse
#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?, #store_mentions_after_commit?, #updated_cached_html_for
#present
===, cached_column_list, #create_or_load_association, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, sharding_keys, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
#reset_on_union_error, #reset_on_unknown_attribute_error
#serializable_hash
Class Method Details
.latest(order_by: 'released_at') ⇒ Object
79
80
81
|
# File 'app/models/release.rb', line 79
def latest(order_by: 'released_at')
sort_by_attribute("#{order_by}_desc").first
end
|
.latest_for_projects(projects, order_by: 'released_at') ⇒ Object
This query uses LATERAL JOIN to find the latest release for each project. To avoid joining the ‘projects` table, we build an in-memory table using the project ids. Example: SELECT … FROM (VALUES (PROJECT_ID_1),(PROJECT_ID_2)) projects (id) INNER JOIN LATERAL (…)
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'app/models/release.rb', line 89
def latest_for_projects(projects, order_by: 'released_at')
return Release.none if projects.empty?
projects_table = Project.arel_table
releases_table = Release.arel_table
join_query = Release
.where(projects_table[:id].eq(releases_table[:project_id]))
.sort_by_attribute("#{order_by}_desc")
.limit(1)
project_ids_list = projects.map { |project| "(#{project.id})" }.join(',')
Release
.from("(VALUES #{project_ids_list}) projects (id)")
.joins("INNER JOIN LATERAL (#{join_query.to_sql}) #{Release.table_name} ON TRUE")
end
|
.waiting_for_publish_event ⇒ Object
107
108
109
|
# File 'app/models/release.rb', line 107
def waiting_for_publish_event
unpublished.released_within_2hrs.joins(:project).merge(Project.with_feature_enabled(:releases)).limit(MAX_NUMBER_TO_PUBLISH)
end
|
Instance Method Details
#assets_count(except: []) ⇒ Object
126
127
128
129
130
131
|
# File 'app/models/release.rb', line 126
def assets_count(except: [])
links_count = links.size
sources_count = except.include?(:sources) ? 0 : sources.size
links_count + sources_count
end
|
#commit ⇒ Object
120
121
122
123
124
|
# File 'app/models/release.rb', line 120
def commit
strong_memoize(:commit) do
repository.commit(actual_sha)
end
end
|
#execute_hooks(action) ⇒ Object
159
160
161
162
|
# File 'app/models/release.rb', line 159
def execute_hooks(action)
hook_data = to_hook_data(action)
project.execute_hooks(hook_data, :release_hooks)
end
|
#historical_release? ⇒ Boolean
143
144
145
|
# File 'app/models/release.rb', line 143
def historical_release?
released_at.present? && released_at.to_i < created_at.to_i
end
|
#milestone_titles ⇒ Object
151
152
153
|
# File 'app/models/release.rb', line 151
def milestone_titles
self.milestones.order_by_dates_and_title.map(&:title).join(', ')
end
|
#name ⇒ Object
147
148
149
|
# File 'app/models/release.rb', line 147
def name
self.read_attribute(:name) || tag
end
|
164
165
166
167
168
169
170
|
# File 'app/models/release.rb', line 164
def related_deployments
Deployment
.with(Gitlab::SQL::CTE.new(:available_environments, project.environments.available.select(:id)).to_arel)
.where('environment_id IN (SELECT * FROM available_environments)')
.where(ref: tag)
.with_environment_page_associations
end
|
#sha_unchanged ⇒ Object
112
113
114
|
# File 'app/models/release.rb', line 112
def sha_unchanged
errors.add(:sha, "cannot be changed") if sha_changed?
end
|
#sources ⇒ Object
133
134
135
136
137
|
# File 'app/models/release.rb', line 133
def sources
strong_memoize(:sources) do
Releases::Source.all(project, tag)
end
end
|
#to_hook_data(action) ⇒ Object
155
156
157
|
# File 'app/models/release.rb', line 155
def to_hook_data(action)
Gitlab::HookData::ReleaseBuilder.new(self).build(action)
end
|
#to_param ⇒ Object
116
117
118
|
# File 'app/models/release.rb', line 116
def to_param
tag
end
|
#upcoming_release? ⇒ Boolean
139
140
141
|
# File 'app/models/release.rb', line 139
def upcoming_release?
released_at.present? && released_at.to_i > Time.zone.now.to_i
end
|