2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Finders::MergeRequest class
|
|
|
|
#
|
|
|
|
# Used to filter MergeRequests collections by set of params
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# current_user - which user use
|
|
|
|
# params:
|
2018-11-08 19:23:39 +05:30
|
|
|
# scope: 'created_by_me' or 'assigned_to_me' or 'all'
|
|
|
|
# state: 'open', 'closed', 'merged', 'locked', or 'all'
|
2014-09-02 18:07:02 +05:30
|
|
|
# group_id: integer
|
|
|
|
# project_id: integer
|
2017-08-17 22:00:37 +05:30
|
|
|
# milestone_title: string
|
2020-01-01 13:55:28 +05:30
|
|
|
# release_tag: string
|
2017-09-10 17:25:29 +05:30
|
|
|
# author_id: integer
|
2020-04-22 19:07:51 +05:30
|
|
|
# author_username: string
|
2014-09-02 18:07:02 +05:30
|
|
|
# assignee_id: integer
|
|
|
|
# search: string
|
2019-03-02 22:35:43 +05:30
|
|
|
# in: 'title', 'description', or a string joining them with comma
|
2014-09-02 18:07:02 +05:30
|
|
|
# label_name: string
|
|
|
|
# sort: string
|
2017-08-17 22:00:37 +05:30
|
|
|
# non_archived: boolean
|
2018-03-17 18:26:18 +05:30
|
|
|
# my_reaction_emoji: string
|
2018-03-27 19:54:05 +05:30
|
|
|
# source_branch: string
|
|
|
|
# target_branch: string
|
|
|
|
# created_after: datetime
|
|
|
|
# created_before: datetime
|
|
|
|
# updated_after: datetime
|
|
|
|
# updated_before: datetime
|
2014-09-02 18:07:02 +05:30
|
|
|
#
|
2015-04-26 12:48:37 +05:30
|
|
|
class MergeRequestsFinder < IssuableFinder
|
2020-10-24 23:57:45 +05:30
|
|
|
include MergedAtFilter
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
def self.scalar_params
|
2020-10-24 23:57:45 +05:30
|
|
|
@scalar_params ||= super + [:wip, :draft, :target_branch, :merged_after, :merged_before]
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def klass
|
|
|
|
MergeRequest
|
|
|
|
end
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def filter_items(_items)
|
2019-03-13 22:55:13 +05:30
|
|
|
items = by_commit(super)
|
2020-03-13 15:44:24 +05:30
|
|
|
items = by_deployment(items)
|
2019-03-13 22:55:13 +05:30
|
|
|
items = by_source_branch(items)
|
2020-10-24 23:57:45 +05:30
|
|
|
items = by_draft(items)
|
2019-07-07 11:18:12 +05:30
|
|
|
items = by_target_branch(items)
|
2020-10-24 23:57:45 +05:30
|
|
|
items = by_merged_at(items)
|
2019-07-07 11:18:12 +05:30
|
|
|
by_source_project_id(items)
|
2018-03-27 19:54:05 +05:30
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
private
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
def by_commit(items)
|
|
|
|
return items unless params[:commit_sha].presence
|
|
|
|
|
|
|
|
items.by_commit_sha(params[:commit_sha])
|
|
|
|
end
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
def source_branch
|
|
|
|
@source_branch ||= params[:source_branch].presence
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-27 19:54:05 +05:30
|
|
|
def by_source_branch(items)
|
|
|
|
return items unless source_branch
|
|
|
|
|
|
|
|
items.where(source_branch: source_branch)
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
def target_branch
|
|
|
|
@target_branch ||= params[:target_branch].presence
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-03-27 19:54:05 +05:30
|
|
|
def by_target_branch(items)
|
|
|
|
return items unless target_branch
|
|
|
|
|
|
|
|
items.where(target_branch: target_branch)
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def source_project_id
|
|
|
|
@source_project_id ||= params[:source_project_id].presence
|
|
|
|
end
|
|
|
|
|
|
|
|
def by_source_project_id(items)
|
|
|
|
return items unless source_project_id
|
|
|
|
|
|
|
|
items.where(source_project_id: source_project_id)
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def by_draft(items)
|
|
|
|
draft_param = params[:draft] || params[:wip]
|
|
|
|
|
|
|
|
if draft_param == 'yes'
|
2018-12-05 23:21:45 +05:30
|
|
|
items.where(wip_match(items.arel_table))
|
2020-10-24 23:57:45 +05:30
|
|
|
elsif draft_param == 'no'
|
2018-12-05 23:21:45 +05:30
|
|
|
items.where.not(wip_match(items.arel_table))
|
|
|
|
else
|
|
|
|
items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
# WIP is deprecated in favor of Draft. Currently both options are supported
|
2018-12-05 23:21:45 +05:30
|
|
|
def wip_match(table)
|
2020-10-24 23:57:45 +05:30
|
|
|
items =
|
|
|
|
table[:title].matches('WIP:%')
|
2018-12-05 23:21:45 +05:30
|
|
|
.or(table[:title].matches('WIP %'))
|
|
|
|
.or(table[:title].matches('[WIP]%'))
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
return items unless Feature.enabled?(:merge_request_draft_filter)
|
|
|
|
|
|
|
|
items
|
|
|
|
.or(table[:title].matches('Draft - %'))
|
|
|
|
.or(table[:title].matches('Draft:%'))
|
|
|
|
.or(table[:title].matches('[Draft]%'))
|
|
|
|
.or(table[:title].matches('(Draft)%'))
|
2018-12-05 23:21:45 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def by_deployment(items)
|
|
|
|
return items unless deployment_id
|
|
|
|
|
|
|
|
items.includes(:deployment_merge_requests)
|
|
|
|
.where(deployment_merge_requests: { deployment_id: deployment_id })
|
|
|
|
end
|
|
|
|
|
|
|
|
def deployment_id
|
|
|
|
@deployment_id ||= params[:deployment_id].presence
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
MergeRequestsFinder.prepend_if_ee('EE::MergeRequestsFinder')
|