Commit 57e6c04b authored by Etienne Baqué's avatar Etienne Baqué

Added queries for release filter in issue search

Added new scopes related to issues and releases.
Updated IssuableFinder with use of new scopes.
parent d2320457
......@@ -13,6 +13,7 @@
# group_id: integer
# project_id: integer
# milestone_title: string
# release_tag: string
# author_id: integer
# author_username: string
# assignee_id: integer or 'None' or 'Any'
......@@ -59,6 +60,7 @@ class IssuableFinder
author_username
label_name
milestone_title
release_tag
my_reaction_emoji
search
in
......@@ -126,6 +128,7 @@ class IssuableFinder
items = by_non_archived(items)
items = by_iids(items)
items = by_milestone(items)
items = by_release(items)
items = by_label(items)
by_my_reaction_emoji(items)
end
......@@ -364,6 +367,10 @@ class IssuableFinder
end
end
def releases?
params[:release_tag].present?
end
private
def force_cte?
......@@ -570,6 +577,20 @@ class IssuableFinder
end
# rubocop: enable CodeReuse/ActiveRecord
def by_release(items)
if releases?
items = if filter_by_no_release?
items.left_joins_milestones_joins_no_release
elsif filter_by_any_release?
items.left_joins_milestones_joins_releases
else
items.with_release(params[:release_tag])
end
end
items
end
def filter_by_no_milestone?
# Accepts `No Milestone` for compatibility
params[:milestone_title].to_s.downcase == FILTER_NONE || params[:milestone_title] == Milestone::None.title
......@@ -588,6 +609,14 @@ class IssuableFinder
params[:milestone_title] == Milestone::Started.name
end
def filter_by_no_release?
params[:release_tag].to_s.downcase == FILTER_NONE
end
def filter_by_any_release?
params[:release_tag].to_s.downcase == FILTER_ANY
end
def by_label(items)
return items unless labels?
......
......@@ -12,6 +12,7 @@
# group_id: integer
# project_id: integer
# milestone_title: string
# release_tag: string
# author_id: integer
# assignee_id: integer
# search: string
......
......@@ -100,6 +100,8 @@ module Issuable
scope :of_milestones, ->(ids) { where(milestone_id: ids) }
scope :any_milestone, -> { where('milestone_id IS NOT NULL') }
scope :with_milestone, ->(title) { left_joins_milestones.where(milestones: { title: title }) }
scope :any_release, -> { left_joins_milestones_joins_releases }
scope :with_release, -> (tag) { left_joins_milestones_joins_releases.where( milestones: { releases: { tag: tag } } ) }
scope :opened, -> { with_state(:opened) }
scope :only_opened, -> { with_state(:opened) }
scope :closed, -> { with_state(:closed) }
......@@ -121,6 +123,22 @@ module Issuable
scope :order_milestone_due_desc, -> { left_joins_milestones.reorder(Arel.sql('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date DESC')) }
scope :order_milestone_due_asc, -> { left_joins_milestones.reorder(Arel.sql('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date ASC')) }
scope :left_joins_milestones_joins_no_release, -> do
joins("LEFT OUTER JOIN milestones
LEFT OUTER JOIN milestone_releases ON milestones.id = milestone_releases.milestone_id
ON #{table_name}.milestone_id = milestones.id"
).where('milestone_releases.release_id IS NULL')
end
scope :left_joins_milestones_joins_releases, -> do
joins("LEFT OUTER JOIN milestones
JOIN milestone_releases
JOIN releases ON milestone_releases.release_id = releases.id
ON milestones.id = milestone_releases.milestone_id
ON #{table_name}.milestone_id = milestones.id"
).where('milestone_releases.release_id IS NOT NULL').distinct
end
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :any_label, -> { joins(:label_links).group(:id) }
scope :join_project, -> { joins(:project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment