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 ...@@ -13,6 +13,7 @@ module Jira
@search = params[:search] @search = params[:search]
@labels = params[:labels] @labels = params[:labels]
@status = params[:status] @status = params[:status]
@state = params[:state]
@reporter = params[:author_username] @reporter = params[:author_username]
@assignee = params[:assignee_username] @assignee = params[:assignee_username]
@sort = params[:sort] || DEFAULT_SORT @sort = params[:sort] || DEFAULT_SORT
...@@ -28,7 +29,7 @@ module Jira ...@@ -28,7 +29,7 @@ module Jira
private 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 def jql_filters
[ [
...@@ -37,6 +38,7 @@ module Jira ...@@ -37,6 +38,7 @@ module Jira
by_status, by_status,
by_reporter, by_reporter,
by_assignee, by_assignee,
by_open_and_closed,
by_summary_and_description by_summary_and_description
].compact.join(' AND ') ].compact.join(' AND ')
end end
...@@ -80,6 +82,19 @@ module Jira ...@@ -80,6 +82,19 @@ module Jira
%Q[assignee = "#{escape_quotes(assignee)}"] %Q[assignee = "#{escape_quotes(assignee)}"]
end 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) def escape_quotes(param)
param.gsub('\\', '\\\\\\').gsub('"', '\\"') param.gsub('\\', '\\\\\\').gsub('"', '\\"')
end end
......
...@@ -85,5 +85,29 @@ RSpec.describe Jira::JqlBuilderService do ...@@ -85,5 +85,29 @@ RSpec.describe Jira::JqlBuilderService do
expect(subject).to eq('project = PROJECT_KEY order by updated ASC') expect(subject).to eq('project = PROJECT_KEY order by updated ASC')
end end
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
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