Skip to content

Commit 02c3686

Browse files
committed
Client JQL query support
1 parent 05686ad commit 02c3686

File tree

6 files changed

+56
-1
lines changed

6 files changed

+56
-1
lines changed

example.rb

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
# puts "#{issue.id} - #{issue.fields['summary']}"
5353
# end
5454
#
55+
# # List issues by JQL query
56+
# # ------------------------
57+
# client.Issue.jql('PROJECT = "SAMPLEPROJECT"').each do |issue|
58+
# puts "#{issue.id} - #{issue.fields['summary']}"
59+
# end
60+
#
5561
# # Delete an issue
5662
# # ---------------
5763
# issue = client.Issue.find('SAMPLEPROJECT-2')

http-basic-example.rb

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
# puts "#{issue.id} - #{issue.fields['summary']}"
5050
# end
5151
#
52+
# # List issues by JQL query
53+
# # ------------------------
54+
# client.Issue.jql('PROJECT = "SAMPLEPROJECT"').each do |issue|
55+
# puts "#{issue.id} - #{issue.fields['summary']}"
56+
# end
57+
#
5258
# # Delete an issue
5359
# # ---------------
5460
# issue = client.Issue.find('SAMPLEPROJECT-2')

lib/jira/base_factory.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def self.delegate_to_target_class(*method_names)
3838
# The priciple purpose of this class is to delegate methods to the corresponding
3939
# non-factory class and automatically prepend the client argument to the argument
4040
# list.
41-
delegate_to_target_class :all, :find, :collection_path, :singular_path
41+
delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql
4242

4343
# This method needs special handling as it has a default argument value
4444
def build(attrs={})

lib/jira/resource/issue.rb

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'cgi'
2+
13
module JIRA
24
module Resource
35

@@ -37,6 +39,15 @@ def self.all(client)
3739
end
3840
end
3941

42+
def self.jql(client, jql)
43+
url = client.options[:rest_base_path] + "/search?jql=" + CGI.escape(jql)
44+
response = client.get(url)
45+
json = parse_json(response.body)
46+
json['issues'].map do |issue|
47+
client.Issue.build(issue)
48+
end
49+
end
50+
4051
def respond_to?(method_name)
4152
if attrs.keys.include?('fields') && attrs['fields'].keys.include?(method_name.to_s)
4253
true

spec/integration/issue_spec.rb

+16
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,21 @@
7474

7575
end
7676

77+
describe "GET jql issues" do # JIRA::Resource::Issue.jql uses the search endpoint
78+
jql_query_string = "PROJECT = 'SAMPLEPROJECT'"
79+
let(:client) { client }
80+
let(:site_url) { site_url }
81+
let(:jql_query_string) { jql_query_string }
82+
83+
let(:expected_attributes) {
84+
{
85+
"id"=>"10014",
86+
"self"=>"http://localhost:2990/jira/rest/api/2/issue/10014",
87+
"key"=>"SAMPLEPROJECT-13"
88+
}
89+
}
90+
it_should_behave_like "a resource with JQL inputs and a collection GET endpoint"
91+
end
92+
7793
end
7894
end

spec/support/shared_examples/integration.rb

+16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'cgi'
2+
13
def get_mock_from_path(method, options = {})
24
if defined? belongs_to
35
prefix = belongs_to.path_component + '/'
@@ -79,6 +81,20 @@ def build_receiver
7981

8082
end
8183

84+
shared_examples "a resource with JQL inputs and a collection GET endpoint" do
85+
86+
it "should get the collection" do
87+
stub_request(:get, site_url + client.options[:rest_base_path] + '/search?jql=' + CGI.escape(jql_query_string)).
88+
to_return(:status => 200, :body => get_mock_response('issue.json'))
89+
collection = build_receiver.jql(jql_query_string)
90+
collection.length.should == expected_collection_length
91+
92+
first = collection.first
93+
first.should have_attributes(expected_attributes)
94+
end
95+
96+
end
97+
8298
shared_examples "a resource with a singular GET endpoint" do
8399

84100
it "GETs a single resource" do

0 commit comments

Comments
 (0)