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
@jira_project_key = jira_project_key
@search = params[:search]
@labels = params[:labels]
@status = params[:status]
@reporter = params[:author_username]
@assignee = params[:assignee_username]
@sort = params[:sort] || DEFAULT_SORT
@sort_direction = params[:sort_direction] || DEFAULT_SORT_DIRECTION
end
......@@ -25,12 +28,15 @@ module Jira
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
[
by_project,
by_labels,
by_status,
by_reporter,
by_assignee,
by_summary_and_description
].compact.join(' AND ')
end
......@@ -52,10 +58,28 @@ module Jira
labels.map { |label| %Q[labels = "#{escape_quotes(label)}"] }.join(' AND ')
end
def by_status
return if status.blank?
%Q[status = "#{escape_quotes(status)}"]
end
def order_by
"order by #{sort} #{sort_direction}"
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)
param.gsub('\\', '\\\\\\').gsub('"', '\\"')
end
......
......@@ -54,6 +54,30 @@ RSpec.describe Jira::JqlBuilderService do
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
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