Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/jira/resource/issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ def self.all(client)
end
end


def self.jql_v2(client, jql, options = {fields: nil, start_at: nil, max_results: nil, expand: nil})
url = client.options[:rest_base_path] + "/search?jql=" + CGI.escape(jql)

url << "&fields=#{options[:fields].map{ |value| CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if options[:fields]
url << "&startAt=#{CGI.escape(options[:start_at].to_s)}" if options[:start_at]
url << "&maxResults=#{CGI.escape(options[:max_results].to_s)}" if options[:max_results]

if options[:expand]
options[:expand] = [options[:expand]] if options[:expand].is_a?(String)
url << "&expand=#{options[:expand].to_a.map{ |value| CGI.escape(value.to_s) }.join(',')}"
end

response = client.get(url)
json = parse_json(response.body)
json['issues'].map do |issue|
client.Issue.build(issue)
end
end

def self.jql(client, jql, options = {fields: nil, next_page_token: nil, max_results: nil, expand: nil})
url = client.options[:rest_base_path_v3] + "/search/jql?jql=" + CGI.escape(jql)

Expand Down
70 changes: 70 additions & 0 deletions spec/jira/resource/issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,75 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
expect(JIRA::Resource::Issue.jql(client,'foo bar', expand: %w(transitions))).to eq("issues" =>[""])
end

it "should search an issue with a jql query string for v2 version" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
expect(client).to receive(:get).with('/jira/rest/api/2/search?jql=foo+bar').
and_return(response)
expect(client).to receive(:Issue).and_return(issue)
expect(issue).to receive(:build).with(["key", "foo"]).and_return('')

expect(JIRA::Resource::Issue.jql_v2(client,'foo bar')).to eq([''])
end

it "should search an issue with a jql query string and fields for v2 version" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
expect(client).to receive(:get)
.with('/jira/rest/api/2/search?jql=foo+bar&fields=foo,bar')
.and_return(response)
expect(client).to receive(:Issue).and_return(issue)
expect(issue).to receive(:build).with(["key", "foo"]).and_return('')

expect(JIRA::Resource::Issue.jql_v2(client, 'foo bar', fields: ['foo','bar'])).to eq([''])
end

it "should search an issue with a jql query string, start at, and maxResults for v2 version" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
expect(client).to receive(:get)
.with('/jira/rest/api/2/search?jql=foo+bar&startAt=1&maxResults=3')
.and_return(response)
expect(client).to receive(:Issue).and_return(issue)
expect(issue).to receive(:build).with(["key", "foo"]).and_return('')

expect(JIRA::Resource::Issue.jql_v2(client,'foo bar', start_at: 1, max_results: 3)).to eq([''])
end

it "should search an issue with a jql query string and string expand for v2 version" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
expect(client).to receive(:get)
.with('/jira/rest/api/2/search?jql=foo+bar&expand=transitions')
.and_return(response)
expect(client).to receive(:Issue).and_return(issue)
expect(issue).to receive(:build).with(["key", "foo"]).and_return('')

expect(JIRA::Resource::Issue.jql_v2(client,'foo bar', expand: 'transitions')).to eq([''])
end

it "should search an issue with a jql query string and array expand for v2 version" do
response = double()
issue = double()

allow(response).to receive(:body).and_return('{"issues": {"key":"foo"}}')
expect(client).to receive(:get)
.with('/jira/rest/api/2/search?jql=foo+bar&expand=transitions')
.and_return(response)
expect(client).to receive(:Issue).and_return(issue)
expect(issue).to receive(:build).with(["key", "foo"]).and_return('')

expect(JIRA::Resource::Issue.jql_v2(client,'foo bar', expand: %w(transitions))).to eq([''])
end

it 'should return meta data available for editing an issue' do
subject = JIRA::Resource::Issue.new(client, :attrs => {'fields' => {'key' =>'TST=123'}})
response = double()
Expand Down Expand Up @@ -222,3 +291,4 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
end
end
end