diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-30 21:10:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-10-30 21:10:11 +0300 |
commit | c51425915fb1b2c367d6d828449b5cc7772ac104 (patch) | |
tree | e0bb2d9f3e0c9aaec6fe71a9da26f9bab5d9890c /app | |
parent | f65227a163435d66e3f0b80f4c52ae59d8df39a2 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/models/ci/catalog/resource.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 36 | ||||
-rw-r--r-- | app/services/ci/pipelines/update_metadata_service.rb | 31 |
3 files changed, 33 insertions, 38 deletions
diff --git a/app/models/ci/catalog/resource.rb b/app/models/ci/catalog/resource.rb index c3e8955d2a2..38841cc309d 100644 --- a/app/models/ci/catalog/resource.rb +++ b/app/models/ci/catalog/resource.rb @@ -17,8 +17,8 @@ module Ci scope :for_projects, ->(project_ids) { where(project_id: project_ids) } scope :order_by_created_at_desc, -> { reorder(created_at: :desc) } scope :order_by_created_at_asc, -> { reorder(created_at: :asc) } - scope :order_by_name_desc, -> { joins(:project).merge(Project.sorted_by_name_desc) } - scope :order_by_name_asc, -> { joins(:project).merge(Project.sorted_by_name_asc) } + scope :order_by_name_desc, -> { reorder(arel_table[:name].desc.nulls_last) } + scope :order_by_name_asc, -> { reorder(arel_table[:name].asc.nulls_last) } scope :order_by_latest_released_at_desc, -> { reorder(arel_table[:latest_released_at].desc.nulls_last) } scope :order_by_latest_released_at_asc, -> { reorder(arel_table[:latest_released_at].asc.nulls_last) } diff --git a/app/models/project.rb b/app/models/project.rb index f7e994d4beb..28b640cdf06 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -624,42 +624,6 @@ class Project < ApplicationRecord .or(arel_table[:storage_version].eq(nil))) end - scope :sorted_by_name_desc, -> { - keyset_order = Gitlab::Pagination::Keyset::Order.build([ - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: :name, - column_expression: Project.arel_table[:name], - order_expression: Project.arel_table[:name].desc, - distinct: false, - nullable: :nulls_last - ), - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: :id, - order_expression: Project.arel_table[:id].desc - ) - ]) - - reorder(keyset_order) - } - - scope :sorted_by_name_asc, -> { - keyset_order = Gitlab::Pagination::Keyset::Order.build([ - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: :name, - column_expression: Project.arel_table[:name], - order_expression: Project.arel_table[:name].asc, - distinct: false, - nullable: :nulls_last - ), - Gitlab::Pagination::Keyset::ColumnOrderDefinition.new( - attribute_name: :id, - order_expression: Project.arel_table[:id].asc - ) - ]) - - reorder(keyset_order) - } - scope :sorted_by_updated_asc, -> { reorder(self.arel_table['updated_at'].asc) } scope :sorted_by_updated_desc, -> { reorder(self.arel_table['updated_at'].desc) } scope :sorted_by_stars_desc, -> { reorder(self.arel_table['star_count'].desc) } diff --git a/app/services/ci/pipelines/update_metadata_service.rb b/app/services/ci/pipelines/update_metadata_service.rb new file mode 100644 index 00000000000..2f2d648c13d --- /dev/null +++ b/app/services/ci/pipelines/update_metadata_service.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Ci + module Pipelines + class UpdateMetadataService + def initialize(pipeline, params) + @pipeline = pipeline + @params = params + end + + def execute + metadata = pipeline.pipeline_metadata + + metadata = pipeline.build_pipeline_metadata(project: pipeline.project) if metadata.nil? + + params[:name] = params[:name].strip if params.key?(:name) + + if metadata.update(params) + ServiceResponse.success(message: 'Pipeline metadata was updated', payload: pipeline) + else + ServiceResponse.error(message: 'Failed to update pipeline', payload: metadata.errors.full_messages, + reason: :bad_request) + end + end + + private + + attr_reader :pipeline, :params + end + end +end |