From 6ebe886c82111e1ab9e71d4c02a888d2312898bc Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 10 Mar 2022 15:08:10 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/controllers/projects/releases_controller.rb | 33 +++++++++++++- app/finders/admin/projects_finder.rb | 2 +- app/presenters/ci/build_runner_presenter.rb | 57 ++++++++++++++++--------- 3 files changed, 68 insertions(+), 24 deletions(-) (limited to 'app') diff --git a/app/controllers/projects/releases_controller.rb b/app/controllers/projects/releases_controller.rb index 7fba6cc5bf4..62e607ae1af 100644 --- a/app/controllers/projects/releases_controller.rb +++ b/app/controllers/projects/releases_controller.rb @@ -7,6 +7,7 @@ class Projects::ReleasesController < Projects::ApplicationController before_action :authorize_read_release! before_action :authorize_update_release!, only: %i[edit update] before_action :authorize_create_release!, only: :new + before_action :validate_suffix_path, :fetch_latest_tag, only: :latest_permalink before_action only: :index do push_frontend_feature_flag(:releases_index_apollo_client, project, default_enabled: :yaml) end @@ -26,10 +27,24 @@ class Projects::ReleasesController < Projects::ApplicationController redirect_to link.url end + def latest_permalink + unless @latest_tag.present? + return render_404 + end + + query_parameters_except_order_by = request.query_parameters.except(:order_by) + + redirect_url = project_release_url(@project, @latest_tag) + redirect_url += "/#{params[:suffix_path]}" if params[:suffix_path] + redirect_url += "?#{query_parameters_except_order_by.compact.to_param}" if query_parameters_except_order_by.present? + + redirect_to redirect_url + end + private - def releases - ReleasesFinder.new(@project, current_user).execute + def releases(params = {}) + ReleasesFinder.new(@project, current_user, params).execute end def authorize_update_release! @@ -51,4 +66,18 @@ class Projects::ReleasesController < Projects::ApplicationController def sanitized_tag_name CGI.unescape(params[:tag]) end + + # Default order_by is 'released_at', which is set in ReleasesFinder. + # Also if the passed order_by is invalid, we reject and default to 'released_at'. + def fetch_latest_tag + allowed_values = ['released_at'] + + params.reject! { |key, value| key.to_sym == :order_by && allowed_values.any?(value) } + + @latest_tag = releases(order_by: params[:order_by]).first&.tag + end + + def validate_suffix_path + Gitlab::Utils.check_path_traversal!(params[:suffix_path]) if params[:suffix_path] + end end diff --git a/app/finders/admin/projects_finder.rb b/app/finders/admin/projects_finder.rb index 53dbf65c43a..fc18bb1984a 100644 --- a/app/finders/admin/projects_finder.rb +++ b/app/finders/admin/projects_finder.rb @@ -69,7 +69,7 @@ class Admin::ProjectsFinder end def sort(items) - sort = params.fetch(:sort) { 'latest_activity_desc' } + sort = params.fetch(:sort, 'latest_activity_desc') items.sort_by_attribute(sort) end end diff --git a/app/presenters/ci/build_runner_presenter.rb b/app/presenters/ci/build_runner_presenter.rb index 082993130a1..015dfc16df0 100644 --- a/app/presenters/ci/build_runner_presenter.rb +++ b/app/presenters/ci/build_runner_presenter.rb @@ -64,35 +64,50 @@ module Ci def create_archive(artifacts) return unless artifacts[:untracked] || artifacts[:paths] - archive = { - artifact_type: :archive, - artifact_format: :zip, - name: artifacts[:name], - untracked: artifacts[:untracked], - paths: artifacts[:paths], - when: artifacts[:when], - expire_in: artifacts[:expire_in] - } - - if artifacts.dig(:exclude).present? - archive.merge(exclude: artifacts[:exclude]) - else - archive + BuildArtifact.for_archive(artifacts).to_h.tap do |artifact| + artifact.delete(:exclude) unless artifact[:exclude].present? end end def create_reports(reports, expire_in:) return unless reports&.any? - reports.map do |report_type, report_paths| - { - artifact_type: report_type.to_sym, - artifact_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(report_type.to_sym), - name: ::Ci::JobArtifact::DEFAULT_FILE_NAMES.fetch(report_type.to_sym), - paths: report_paths, + reports.map { |report| BuildArtifact.for_report(report, expire_in).to_h.compact } + end + + BuildArtifact = Struct.new(:name, :untracked, :paths, :exclude, :when, :expire_in, :artifact_type, :artifact_format, keyword_init: true) do + def self.for_archive(artifacts) + self.new( + artifact_type: :archive, + artifact_format: :zip, + name: artifacts[:name], + untracked: artifacts[:untracked], + paths: artifacts[:paths], + when: artifacts[:when], + expire_in: artifacts[:expire_in], + exclude: artifacts[:exclude] + ) + end + + def self.for_report(report, expire_in) + type, params = report + + if type == :coverage_report + artifact_type = params[:coverage_format].to_sym + paths = [params[:path]] + else + artifact_type = type + paths = params + end + + self.new( + artifact_type: artifact_type, + artifact_format: ::Ci::JobArtifact::TYPE_AND_FORMAT_PAIRS.fetch(artifact_type), + name: ::Ci::JobArtifact::DEFAULT_FILE_NAMES.fetch(artifact_type), + paths: paths, when: 'always', expire_in: expire_in - } + ) end end -- cgit v1.2.3