jira-ruby 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,8 +15,8 @@ API version 2).
15
15
 
16
16
  issue.comments.each {|comment| ... }
17
17
 
18
- comment = issue.comments.build({'body':'My new comment'})
19
- comment.save
18
+ comment = issue.comments.build
19
+ comment.save({'body':'My new comment'})
20
20
  comment.delete
21
21
 
22
22
  == Links to JIRA REST API documentation
data/Rakefile CHANGED
@@ -6,7 +6,17 @@ require 'rake/rdoctask'
6
6
 
7
7
  Dir.glob('lib/tasks/*.rake').each { |r| import r }
8
8
 
9
- task :default => [:spec]
9
+ task :default => [:test]
10
+
11
+ task :test => [:prepare, :spec]
12
+
13
+ describe "Prepare and run rspec tests"
14
+ task :prepare do
15
+ rsa_key = File.expand_path('rsakey.pem')
16
+ if !File.exists?(rsa_key)
17
+ raise "rsakey.pem does not exist, tests will fail. Run `rake jira:generate_public_cert` first"
18
+ end
19
+ end
10
20
 
11
21
  desc "Run RSpec tests"
12
22
  RSpec::Core::RakeTask.new(:spec)
data/example.rb CHANGED
@@ -52,6 +52,12 @@ pp issue
52
52
  # puts "#{issue.id} - #{issue.fields['summary']}"
53
53
  # end
54
54
  #
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
+ #
55
61
  # # Delete an issue
56
62
  # # ---------------
57
63
  # issue = client.Issue.find('SAMPLEPROJECT-2')
@@ -49,6 +49,12 @@ end
49
49
  # puts "#{issue.id} - #{issue.fields['summary']}"
50
50
  # end
51
51
  #
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
+ #
52
58
  # # Delete an issue
53
59
  # # ---------------
54
60
  # issue = client.Issue.find('SAMPLEPROJECT-2')
@@ -38,7 +38,7 @@ module JIRA
38
38
  # The priciple purpose of this class is to delegate methods to the corresponding
39
39
  # non-factory class and automatically prepend the client argument to the argument
40
40
  # list.
41
- delegate_to_target_class :all, :find, :collection_path, :singular_path
41
+ delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql
42
42
 
43
43
  # This method needs special handling as it has a default argument value
44
44
  def build(attrs={})
data/lib/jira/client.rb CHANGED
@@ -137,7 +137,7 @@ module JIRA
137
137
 
138
138
  # Sends the specified HTTP request to the REST API through the
139
139
  # appropriate method (oauth, basic).
140
- def request(http_method, path, body = '', headers)
140
+ def request(http_method, path, body = '', headers={})
141
141
  @request_client.request(http_method, path, body, headers)
142
142
  end
143
143
 
@@ -15,8 +15,8 @@ module JIRA
15
15
  @options = DEFAULT_OPTIONS.merge(options)
16
16
  end
17
17
 
18
- def make_request(http_method, path, body='', headers)
19
- request = Net::HTTP.const_get(http_method.capitalize).new(path, headers)
18
+ def make_request(http_method, path, body='', headers={})
19
+ request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
20
20
  request.body = body unless body.nil?
21
21
  request.basic_auth(@options[:username], @options[:password])
22
22
  response = basic_auth_http_conn.request(request)
@@ -71,7 +71,7 @@ module JIRA
71
71
  @access_token
72
72
  end
73
73
 
74
- def make_request(http_method, path, body='', headers)
74
+ def make_request(http_method, path, body='', headers={})
75
75
  case http_method
76
76
  when :delete, :get, :head
77
77
  response = access_token.send http_method, path, headers
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  module JIRA
2
4
  module Resource
3
5
 
@@ -37,6 +39,15 @@ module JIRA
37
39
  end
38
40
  end
39
41
 
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
+
40
51
  def respond_to?(method_name)
41
52
  if attrs.keys.include?('fields') && attrs['fields'].keys.include?(method_name.to_s)
42
53
  true
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -74,5 +74,21 @@ describe JIRA::Resource::Issue do
74
74
 
75
75
  end
76
76
 
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
+
77
93
  end
78
94
  end
@@ -23,16 +23,14 @@ describe JIRA::HttpClient do
23
23
  basic_auth_http_conn = mock()
24
24
  request = mock()
25
25
  basic_client.stub(:basic_auth_http_conn => basic_auth_http_conn)
26
- request.should_receive(:basic_auth)
27
- .with(basic_client.options[:username], basic_client.options[:password])
28
- .exactly(5).times.and_return(request)
26
+ request.should_receive(:basic_auth).with(basic_client.options[:username], basic_client.options[:password]).exactly(5).times.and_return(request)
29
27
  basic_auth_http_conn.should_receive(:request).exactly(5).times.with(request).and_return(response)
30
28
  [:delete, :get, :head].each do |method|
31
- Net::HTTP.const_get(method.capitalize).should_receive(:new).with('/path', headers).and_return(request)
29
+ Net::HTTP.const_get(method.to_s.capitalize).should_receive(:new).with('/path', headers).and_return(request)
32
30
  basic_client.make_request(method, '/path', nil, headers).should == response
33
31
  end
34
32
  [:post, :put].each do |method|
35
- Net::HTTP.const_get(method.capitalize).should_receive(:new).with('/path', headers).and_return(request)
33
+ Net::HTTP.const_get(method.to_s.capitalize).should_receive(:new).with('/path', headers).and_return(request)
36
34
  request.should_receive(:body=).with(body).and_return(request)
37
35
  basic_client.make_request(method, '/path', body, headers).should == response
38
36
  end
@@ -1,3 +1,5 @@
1
+ require 'cgi'
2
+
1
3
  def get_mock_from_path(method, options = {})
2
4
  if defined? belongs_to
3
5
  prefix = belongs_to.path_component + '/'
@@ -79,6 +81,20 @@ shared_examples "a resource with a collection GET endpoint" do
79
81
 
80
82
  end
81
83
 
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
+
82
98
  shared_examples "a resource with a singular GET endpoint" do
83
99
 
84
100
  it "GETs a single resource" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000Z
12
+ date: 2012-08-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth
16
- requirement: &70203258317280 !ruby/object:Gem::Requirement
16
+ requirement: &70287782974040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70203258317280
24
+ version_requirements: *70287782974040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: oauth
27
- requirement: &70203258316860 !ruby/object:Gem::Requirement
27
+ requirement: &70287782973620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70203258316860
35
+ version_requirements: *70287782973620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: railties
38
- requirement: &70203258316440 !ruby/object:Gem::Requirement
38
+ requirement: &70287782973200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70203258316440
46
+ version_requirements: *70287782973200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: railties
49
- requirement: &70203258316020 !ruby/object:Gem::Requirement
49
+ requirement: &70287782972780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70203258316020
57
+ version_requirements: *70287782972780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70203258315600 !ruby/object:Gem::Requirement
60
+ requirement: &70287782972360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70203258315600
68
+ version_requirements: *70287782972360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &70203258315180 !ruby/object:Gem::Requirement
71
+ requirement: &70287782971940 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70203258315180
79
+ version_requirements: *70287782971940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: webmock
82
- requirement: &70203258314760 !ruby/object:Gem::Requirement
82
+ requirement: &70287782971520 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70203258314760
90
+ version_requirements: *70287782971520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &70203258314340 !ruby/object:Gem::Requirement
93
+ requirement: &70287782987480 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70203258314340
101
+ version_requirements: *70287782987480
102
102
  description: API for JIRA 5
103
103
  email:
104
104
  executables: []