Commit 8f20f89c authored by Brett Walker's avatar Brett Walker

Filter by open and closed state

for Jira issues
parent 67fdd183
......@@ -13,6 +13,7 @@ module Jira
@search = params[:search]
@labels = params[:labels]
@status = params[:status]
@state = params[:state]
@reporter = params[:author_username]
@assignee = params[:assignee_username]
@sort = params[:sort] || DEFAULT_SORT
......@@ -28,7 +29,7 @@ module Jira
private
attr_reader :jira_project_key, :sort, :sort_direction, :search, :labels, :status, :reporter, :assignee
attr_reader :jira_project_key, :sort, :sort_direction, :search, :labels, :status, :reporter, :assignee, :state
def jql_filters
[
......@@ -37,6 +38,7 @@ module Jira
by_status,
by_reporter,
by_assignee,
by_open_and_closed,
by_summary_and_description
].compact.join(' AND ')
end
......@@ -80,6 +82,19 @@ module Jira
%Q[assignee = "#{escape_quotes(assignee)}"]
end
def by_open_and_closed
return if state.blank?
case state
when 'opened'
%q[statusCategory != Done]
when 'closed'
%q[statusCategory = Done]
else
return
end
end
def escape_quotes(param)
param.gsub('\\', '\\\\\\').gsub('"', '\\"')
end
......
......@@ -85,5 +85,29 @@ RSpec.describe Jira::JqlBuilderService do
expect(subject).to eq('project = PROJECT_KEY order by updated ASC')
end
end
context 'with opened state param' do
let(:params) { { state: 'opened' } }
it 'builds jql' do
expect(subject).to eq('project = PROJECT_KEY AND statusCategory != Done order by created DESC')
end
end
context 'with closed state param' do
let(:params) { { state: 'closed' } }
it 'builds jql' do
expect(subject).to eq('project = PROJECT_KEY AND statusCategory = Done order by created DESC')
end
end
context 'with any other state param' do
let(:params) { { state: 'all' } }
it 'builds jql' do
expect(subject).to eq('project = PROJECT_KEY order by created DESC')
end
end
end
end
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