2018-09-11 15:08:34 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-02-25 12:15:08 -05:00
|
|
|
# Finders::MergeRequest class
|
|
|
|
#
|
|
|
|
# Used to filter MergeRequests collections by set of params
|
|
|
|
#
|
|
|
|
# Arguments:
|
|
|
|
# current_user - which user use
|
|
|
|
# params:
|
2018-05-13 22:07:53 -04:00
|
|
|
# scope: 'created_by_me' or 'assigned_to_me' or 'all'
|
2018-06-26 15:30:29 -04:00
|
|
|
# state: 'open', 'closed', 'merged', 'locked', or 'all'
|
2014-02-25 12:15:08 -05:00
|
|
|
# group_id: integer
|
|
|
|
# project_id: integer
|
2017-03-31 05:38:40 -04:00
|
|
|
# milestone_title: string
|
2017-07-24 16:07:37 -04:00
|
|
|
# author_id: integer
|
2014-02-25 12:15:08 -05:00
|
|
|
# assignee_id: integer
|
|
|
|
# search: string
|
2019-02-05 03:32:27 -05:00
|
|
|
# in: 'title', 'description', or a string joining them with comma
|
2014-02-25 12:15:08 -05:00
|
|
|
# label_name: string
|
|
|
|
# sort: string
|
2016-11-27 05:33:15 -05:00
|
|
|
# non_archived: boolean
|
2017-09-03 21:43:14 -04:00
|
|
|
# my_reaction_emoji: string
|
2018-02-23 11:04:20 -05:00
|
|
|
# source_branch: string
|
|
|
|
# target_branch: string
|
2018-02-28 06:16:29 -05:00
|
|
|
# created_after: datetime
|
|
|
|
# created_before: datetime
|
|
|
|
# updated_after: datetime
|
|
|
|
# updated_before: datetime
|
2014-02-25 12:15:08 -05:00
|
|
|
#
|
2014-09-02 08:28:27 -04:00
|
|
|
class MergeRequestsFinder < IssuableFinder
|
2018-10-03 04:15:00 -04:00
|
|
|
def self.scalar_params
|
2019-03-09 07:22:58 -05:00
|
|
|
@scalar_params ||= super + [:wip, :target_branch]
|
2018-10-03 04:15:00 -04:00
|
|
|
end
|
|
|
|
|
2014-02-25 12:15:08 -05:00
|
|
|
def klass
|
|
|
|
MergeRequest
|
|
|
|
end
|
2017-02-07 08:15:07 -05:00
|
|
|
|
2018-02-23 11:04:20 -05:00
|
|
|
def filter_items(_items)
|
2019-01-25 04:22:48 -05:00
|
|
|
items = by_commit(super)
|
|
|
|
items = by_source_branch(items)
|
2018-10-03 04:15:00 -04:00
|
|
|
items = by_wip(items)
|
2019-04-05 03:29:53 -04:00
|
|
|
items = by_target_branch(items)
|
|
|
|
by_source_project_id(items)
|
2018-02-23 11:04:20 -05:00
|
|
|
end
|
|
|
|
|
2017-02-07 08:15:07 -05:00
|
|
|
private
|
|
|
|
|
2019-01-25 04:22:48 -05:00
|
|
|
def by_commit(items)
|
|
|
|
return items unless params[:commit_sha].presence
|
|
|
|
|
|
|
|
items.by_commit_sha(params[:commit_sha])
|
|
|
|
end
|
|
|
|
|
2018-02-23 11:04:20 -05:00
|
|
|
def source_branch
|
|
|
|
@source_branch ||= params[:source_branch].presence
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-02-23 11:04:20 -05:00
|
|
|
def by_source_branch(items)
|
|
|
|
return items unless source_branch
|
|
|
|
|
|
|
|
items.where(source_branch: source_branch)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-02-23 11:04:20 -05:00
|
|
|
|
|
|
|
def target_branch
|
|
|
|
@target_branch ||= params[:target_branch].presence
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-02-23 11:04:20 -05:00
|
|
|
def by_target_branch(items)
|
|
|
|
return items unless target_branch
|
|
|
|
|
|
|
|
items.where(target_branch: target_branch)
|
|
|
|
end
|
2018-10-03 04:15:00 -04:00
|
|
|
|
2019-04-05 03:29:53 -04:00
|
|
|
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
|
|
|
|
|
2018-10-03 04:15:00 -04:00
|
|
|
def by_wip(items)
|
|
|
|
if params[:wip] == 'yes'
|
|
|
|
items.where(wip_match(items.arel_table))
|
|
|
|
elsif params[:wip] == 'no'
|
|
|
|
items.where.not(wip_match(items.arel_table))
|
|
|
|
else
|
|
|
|
items
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def wip_match(table)
|
|
|
|
table[:title].matches('WIP:%')
|
|
|
|
.or(table[:title].matches('WIP %'))
|
|
|
|
.or(table[:title].matches('[WIP]%'))
|
|
|
|
end
|
2014-02-25 12:15:08 -05:00
|
|
|
end
|