Commit 02b37c5c authored by Alexandru Croitor's avatar Alexandru Croitor

Add status, reporter and assignee search options

Add abiility to search by status, reporter and assignee
parent d1c59c6a
...@@ -12,6 +12,9 @@ module Jira ...@@ -12,6 +12,9 @@ module Jira
@jira_project_key = jira_project_key @jira_project_key = jira_project_key
@search = params[:search] @search = params[:search]
@labels = params[:labels] @labels = params[:labels]
@status = params[:status]
@reporter = params[:author_username]
@assignee = params[:assignee_username]
@sort = params[:sort] || DEFAULT_SORT @sort = params[:sort] || DEFAULT_SORT
@sort_direction = params[:sort_direction] || DEFAULT_SORT_DIRECTION @sort_direction = params[:sort_direction] || DEFAULT_SORT_DIRECTION
end end
...@@ -25,12 +28,15 @@ module Jira ...@@ -25,12 +28,15 @@ module Jira
private private
attr_reader :jira_project_key, :sort, :sort_direction, :search, :labels attr_reader :jira_project_key, :sort, :sort_direction, :search, :labels, :status, :reporter, :assignee
def jql_filters def jql_filters
[ [
by_project, by_project,
by_labels, by_labels,
by_status,
by_reporter,
by_assignee,
by_summary_and_description by_summary_and_description
].compact.join(' AND ') ].compact.join(' AND ')
end end
...@@ -52,10 +58,28 @@ module Jira ...@@ -52,10 +58,28 @@ module Jira
labels.map { |label| %Q[labels = "#{escape_quotes(label)}"] }.join(' AND ') labels.map { |label| %Q[labels = "#{escape_quotes(label)}"] }.join(' AND ')
end end
def by_status
return if status.blank?
%Q[status = "#{escape_quotes(status)}"]
end
def order_by def order_by
"order by #{sort} #{sort_direction}" "order by #{sort} #{sort_direction}"
end end
def by_reporter
return if reporter.blank?
%Q[reporter = "#{escape_quotes(reporter)}"]
end
def by_assignee
return if assignee.blank?
%Q[assignee = "#{escape_quotes(assignee)}"]
end
def escape_quotes(param) def escape_quotes(param)
param.gsub('\\', '\\\\\\').gsub('"', '\\"') param.gsub('\\', '\\\\\\').gsub('"', '\\"')
end end
......
...@@ -54,6 +54,30 @@ RSpec.describe Jira::JqlBuilderService do ...@@ -54,6 +54,30 @@ RSpec.describe Jira::JqlBuilderService do
end end
end end
context 'with status param' do
let(:params) { { status: "\"'try\"some'more\"quote'here\"" } }
it 'builds jql' do
expect(subject).to eq("project = PROJECT_KEY AND status = \"\\\"'try\\\"some'more\\\"quote'here\\\"\" order by created DESC")
end
end
context 'with author_username param' do
let(:params) { { author_username: "\"'try\"some'more\"quote'here\"" } }
it 'builds jql' do
expect(subject).to eq("project = PROJECT_KEY AND reporter = \"\\\"'try\\\"some'more\\\"quote'here\\\"\" order by created DESC")
end
end
context 'with assignee_username param' do
let(:params) { { assignee_username: "\"'try\"some'more\"quote'here\"" } }
it 'builds jql' do
expect(subject).to eq("project = PROJECT_KEY AND assignee = \"\\\"'try\\\"some'more\\\"quote'here\\\"\" order by created DESC")
end
end
context 'with sort params' do context 'with sort params' do
let(:params) { { sort: 'updated', sort_direction: 'ASC' } } let(:params) { { sort: 'updated', sort_direction: 'ASC' } }
......
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