diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 21:10:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-23 21:10:40 +0300 |
commit | c37dd28c4afd33fee46cff8ddfdada8a3f54564c (patch) | |
tree | c4fb2a3f93338991784cf89b3b1547ab23c1b5e1 /app/finders | |
parent | 5ff5047fdc2c614f347de5c388424b50a5460165 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/finders')
3 files changed, 64 insertions, 121 deletions
diff --git a/app/finders/ci/daily_build_group_report_results_finder.rb b/app/finders/ci/daily_build_group_report_results_finder.rb index ef97ccb4c0f..976f3a21b72 100644 --- a/app/finders/ci/daily_build_group_report_results_finder.rb +++ b/app/finders/ci/daily_build_group_report_results_finder.rb @@ -1,56 +1,86 @@ # frozen_string_literal: true +# DailyBuildGroupReportResultsFinder +# +# Used to filter DailyBuildGroupReportResults by set of params +# +# Arguments: +# current_user +# params: +# project: integer +# group: integer +# coverage: boolean +# ref_path: string +# start_date: date +# end_date: date +# sort: boolean +# limit: integer + module Ci class DailyBuildGroupReportResultsFinder include Gitlab::Allowable - def initialize(current_user:, project:, ref_path: nil, start_date:, end_date:, limit: nil) + MAX_ITEMS = 1_000 + + attr_reader :params, :current_user + + def initialize(params: {}, current_user: nil) + @params = params @current_user = current_user - @project = project - @ref_path = ref_path - @start_date = start_date - @end_date = end_date - @limit = limit end def execute - return none unless query_allowed? + return Ci::DailyBuildGroupReportResult.none unless query_allowed? - query + collection = Ci::DailyBuildGroupReportResult.by_projects(params[:project]) + collection = filter_report_results(collection) + collection end - protected + private - attr_reader :current_user, :project, :ref_path, :start_date, :end_date, :limit + def query_allowed? + can?(current_user, :read_build_report_results, params[:project]) + end + + def filter_report_results(collection) + collection = by_coverage(collection) + collection = by_ref_path(collection) + collection = by_dates(collection) - def query - Ci::DailyBuildGroupReportResult.recent_results( - query_params, - limit: limit - ) + collection = sort(collection) + collection = limit_by(collection) + collection end - def query_allowed? - can?(current_user, :read_build_report_results, project) + def by_coverage(items) + params[:coverage].present? ? items.with_coverage : items end - def query_params - params = { - project_id: project, - date: start_date..end_date - } + def by_ref_path(items) + params[:ref_path].present? ? items.by_ref_path(params[:ref_path]) : items.with_default_branch + end + + def by_dates(items) + params[:start_date].present? && params[:end_date].present? ? items.by_dates(params[:start_date], params[:end_date]) : items + end - if ref_path.present? - params[:ref_path] = ref_path - else - params[:default_branch] = true - end + def sort(items) + params[:sort].present? ? items.ordered_by_date_and_group_name : items + end - params + # rubocop: disable CodeReuse/ActiveRecord + def limit_by(items) + items.limit(limit) end + # rubocop: enable CodeReuse/ActiveRecord + + def limit + return MAX_ITEMS unless params[:limit].present? - def none - Ci::DailyBuildGroupReportResult.none + [params[:limit].to_i, MAX_ITEMS].min end end end + +Ci::DailyBuildGroupReportResultsFinder.prepend_if_ee('::EE::Ci::DailyBuildGroupReportResultsFinder') diff --git a/app/finders/ci/testing/daily_build_group_report_results_finder.rb b/app/finders/ci/testing/daily_build_group_report_results_finder.rb deleted file mode 100644 index 70d9e55dc47..00000000000 --- a/app/finders/ci/testing/daily_build_group_report_results_finder.rb +++ /dev/null @@ -1,88 +0,0 @@ -# frozen_string_literal: true - -# DailyBuildGroupReportResultsFinder -# -# Used to filter DailyBuildGroupReportResults by set of params -# -# Arguments: -# current_user -# params: -# project: integer -# group: integer -# coverage: boolean -# ref_path: string -# start_date: date -# end_date: date -# sort: boolean -# limit: integer - -module Ci - module Testing - class DailyBuildGroupReportResultsFinder - include Gitlab::Allowable - - MAX_ITEMS = 1_000 - - attr_reader :params, :current_user - - def initialize(params: {}, current_user: nil) - @params = params - @current_user = current_user - end - - def execute - return Ci::DailyBuildGroupReportResult.none unless query_allowed? - - collection = Ci::DailyBuildGroupReportResult.by_projects(params[:project]) - collection = filter_report_results(collection) - collection - end - - private - - def query_allowed? - can?(current_user, :read_build_report_results, params[:project]) - end - - def filter_report_results(collection) - collection = by_coverage(collection) - collection = by_ref_path(collection) - collection = by_dates(collection) - - collection = sort(collection) - collection = limit_by(collection) - collection - end - - def by_coverage(items) - params[:coverage].present? ? items.with_coverage : items - end - - def by_ref_path(items) - params[:ref_path].present? ? items.by_ref_path(params[:ref_path]) : items.with_default_branch - end - - def by_dates(items) - params[:start_date].present? && params[:end_date].present? ? items.by_dates(params[:start_date], params[:end_date]) : items - end - - def sort(items) - params[:sort].present? ? items.ordered_by_date_and_group_name : items - end - - # rubocop: disable CodeReuse/ActiveRecord - def limit_by(items) - items.limit(limit) - end - # rubocop: enable CodeReuse/ActiveRecord - - def limit - return MAX_ITEMS unless params[:limit].present? - - [params[:limit].to_i, MAX_ITEMS].min - end - end - end -end - -Ci::Testing::DailyBuildGroupReportResultsFinder.prepend_if_ee('::EE::Ci::Testing::DailyBuildGroupReportResultsFinder') diff --git a/app/finders/repositories/previous_tag_finder.rb b/app/finders/repositories/previous_tag_finder.rb index 150a6332c29..cf27132975d 100644 --- a/app/finders/repositories/previous_tag_finder.rb +++ b/app/finders/repositories/previous_tag_finder.rb @@ -16,12 +16,13 @@ module Repositories # This finder expects that all tags to consider meet the following # requirements: # - # * They start with the letter "v" - # * They use semantic versioning for the tag format + # * They start with the letter "v" followed by a version, or immediately start + # with a version + # * They use semantic versioning for the version format # # Tags not meeting these requirements are ignored. class PreviousTagFinder - TAG_REGEX = /\Av(?<version>#{Gitlab::Regex.unbounded_semver_regex})\z/.freeze + TAG_REGEX = /\Av?(?<version>#{Gitlab::Regex.unbounded_semver_regex})\z/.freeze def initialize(project) @project = project |