jira-ruby 2.0.0 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5226fc516e3462a036601589022516b7b81d341e
4
- data.tar.gz: 3383609edaa34f0c8b78ac7002e21d051a02fbea
2
+ SHA256:
3
+ metadata.gz: 293138e5626828e965e7862b82752fdcdc28a7f063b5e335dbcc1017f0ff371e
4
+ data.tar.gz: 8172bc08099f9a44bae653c69e347eab2356acbaa1df3aa001e5baa38b4e60fa
5
5
  SHA512:
6
- metadata.gz: d94d3e49e1bdb3abe978049db45eb5a1ed4698822900b3df3fe3f6660cdfb739968af5366f2f359006a39af6fbddc926bd670126ce9daf3de0ef95d138d7ffb3
7
- data.tar.gz: 9b53adb2af3746bd00703afc0afa33aa825003261b4afa1328a99ba54183bfb43e865a568c7dbfb8d2b38fd6c8ae5f75f05bf8bf6f59e4bf1fc864378e370ab7
6
+ metadata.gz: 699f1f8410ab65069f4f0a569bf8c2d2f4ec5903f0487ee075014be3ba48dc940efa1b0ccace8523418b9199c18c0eb3cd4d9aa1dd3c3f5d6dcf14c460583211
7
+ data.tar.gz: d0c35fcd9ccf3dfce329809588ae3d245447d942167097a3f5aafe28e5dc253c39eb468166bcbf53d4dca0dd2a22882b103e7114917fd80b3a5696532741a6a8
data/.gitignore CHANGED
@@ -9,3 +9,5 @@ pkg/*
9
9
  .DS_STORE
10
10
  doc
11
11
  .ruby-version
12
+
13
+ .rakeTasks
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - 2.4
4
4
  - 2.5
5
5
  - 2.6
6
- - ruby-head
6
+ - 2.7
7
7
  before_script:
8
8
  - rake jira:generate_public_cert
9
9
  script: bundle exec rake spec
data/README.md CHANGED
@@ -163,7 +163,7 @@ api_token = "myApiToken"
163
163
  options = {
164
164
  :username => username,
165
165
  :password => api_token,
166
- :site => 'http://localhost:8080/', # or 'https://<your_subdomain>.atlassian.net'
166
+ :site => 'http://localhost:8080/', # or 'https://<your_subdomain>.atlassian.net/'
167
167
  :context_path => '/myjira', # often blank
168
168
  :auth_type => :basic,
169
169
  :read_timeout => 120
@@ -307,7 +307,7 @@ class App < Sinatra::Base
307
307
  # site uri, and the request token, access token, and authorize paths
308
308
  before do
309
309
  options = {
310
- :site => 'http://localhost:2990',
310
+ :site => 'http://localhost:2990/',
311
311
  :context_path => '/jira',
312
312
  :signature_method => 'RSA-SHA1',
313
313
  :request_token_path => "/plugins/servlet/oauth/request-token",
@@ -405,7 +405,7 @@ require 'pp'
405
405
  require 'jira-ruby'
406
406
 
407
407
  options = {
408
- :site => 'http://localhost:2990',
408
+ :site => 'http://localhost:2990/',
409
409
  :context_path => '/jira',
410
410
  :signature_method => 'RSA-SHA1',
411
411
  :private_key_file => "rsakey.pem",
data/lib/jira/base.rb CHANGED
@@ -424,7 +424,7 @@ module JIRA
424
424
  end
425
425
  if @attrs['self']
426
426
  the_url = @attrs['self']
427
- the_url = the_url.sub(@client.options[:site], '') if @client.options[:site]
427
+ the_url = the_url.sub(@client.options[:site].chomp('/'), '') if @client.options[:site]
428
428
  the_url
429
429
  elsif key_value
430
430
  self.class.singular_path(client, key_value.to_s, prefix)
data/lib/jira/client.rb CHANGED
@@ -6,7 +6,7 @@ module JIRA
6
6
  # This class is the main access point for all JIRA::Resource instances.
7
7
  #
8
8
  # The client must be initialized with an options hash containing
9
- # configuration options. The available options are:
9
+ # configuration options. The available options are:
10
10
  #
11
11
  # :site => 'http://localhost:2990',
12
12
  # :context_path => '/jira',
@@ -14,6 +14,7 @@ module JIRA
14
14
  # :request_token_path => "/plugins/servlet/oauth/request-token",
15
15
  # :authorize_path => "/plugins/servlet/oauth/authorize",
16
16
  # :access_token_path => "/plugins/servlet/oauth/access-token",
17
+ # :private_key => nil,
17
18
  # :private_key_file => "rsakey.pem",
18
19
  # :rest_base_path => "/rest/api/2",
19
20
  # :consumer_key => nil,
@@ -28,8 +29,17 @@ module JIRA
28
29
  # :proxy_port => nil,
29
30
  # :proxy_username => nil,
30
31
  # :proxy_password => nil,
32
+ # :use_cookies => nil,
31
33
  # :additional_cookies => nil,
32
- # :default_headers => {}
34
+ # :default_headers => {},
35
+ # :use_client_cert => false,
36
+ # :read_timeout => nil,
37
+ # :http_debug => false,
38
+ # :shared_secret => nil,
39
+ # :cert_path => nil,
40
+ # :key_path => nil,
41
+ # :ssl_client_cert => nil,
42
+ # :ssl_client_key => nil
33
43
  #
34
44
  # See the JIRA::Base class methods for all of the available methods on these accessor
35
45
  # objects.
@@ -48,6 +58,43 @@ module JIRA
48
58
 
49
59
  def_delegators :@request_client, :init_access_token, :set_access_token, :set_request_token, :request_token, :access_token, :authenticated?
50
60
 
61
+ DEFINED_OPTIONS = [
62
+ :site,
63
+ :context_path,
64
+ :signature_method,
65
+ :request_token_path,
66
+ :authorize_path,
67
+ :access_token_path,
68
+ :private_key,
69
+ :private_key_file,
70
+ :rest_base_path,
71
+ :consumer_key,
72
+ :consumer_secret,
73
+ :ssl_verify_mode,
74
+ :ssl_version,
75
+ :use_ssl,
76
+ :username,
77
+ :password,
78
+ :auth_type,
79
+ :proxy_address,
80
+ :proxy_port,
81
+ :proxy_username,
82
+ :proxy_password,
83
+ :use_cookies,
84
+ :additional_cookies,
85
+ :default_headers,
86
+ :use_client_cert,
87
+ :read_timeout,
88
+ :http_debug,
89
+ :issuer,
90
+ :base_url,
91
+ :shared_secret,
92
+ :cert_path,
93
+ :key_path,
94
+ :ssl_client_cert,
95
+ :ssl_client_key
96
+ ].freeze
97
+
51
98
  DEFAULT_OPTIONS = {
52
99
  site: 'http://localhost:2990',
53
100
  context_path: '/jira',
@@ -65,11 +112,15 @@ module JIRA
65
112
  @options = options
66
113
  @options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]
67
114
 
115
+ unknown_options = options.keys.reject { |o| DEFINED_OPTIONS.include?(o) }
116
+ raise ArgumentError, "Unknown option(s) given: #{unknown_options}" unless unknown_options.empty?
117
+
68
118
  if options[:use_client_cert]
69
- raise ArgumentError, 'Options: :cert_path must be set when :use_client_cert is true' unless @options[:cert_path]
70
- raise ArgumentError, 'Options: :key_path must be set when :use_client_cert is true' unless @options[:key_path]
71
- @options[:cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path]))
72
- @options[:key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path]))
119
+ @options[:ssl_client_cert] = OpenSSL::X509::Certificate.new(File.read(@options[:cert_path])) if @options[:cert_path]
120
+ @options[:ssl_client_key] = OpenSSL::PKey::RSA.new(File.read(@options[:key_path])) if @options[:key_path]
121
+
122
+ raise ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true' unless @options[:ssl_client_cert]
123
+ raise ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true' unless @options[:ssl_client_key]
73
124
  end
74
125
 
75
126
  case options[:auth_type]
@@ -250,6 +301,11 @@ module JIRA
250
301
  @request_client.request(http_method, path, body, headers)
251
302
  end
252
303
 
304
+ # Stops sensitive client information from being displayed in logs
305
+ def inspect
306
+ "#<JIRA::Client:#{object_id}>"
307
+ end
308
+
253
309
  protected
254
310
 
255
311
  def merge_default_headers(headers)
@@ -53,8 +53,8 @@ module JIRA
53
53
  http_conn = http_class.new(uri.host, uri.port)
54
54
  http_conn.use_ssl = @options[:use_ssl]
55
55
  if @options[:use_client_cert]
56
- http_conn.cert = @options[:cert]
57
- http_conn.key = @options[:key]
56
+ http_conn.cert = @options[:ssl_client_cert]
57
+ http_conn.key = @options[:ssl_client_key]
58
58
  end
59
59
  http_conn.verify_mode = @options[:ssl_verify_mode]
60
60
  http_conn.ssl_version = @options[:ssl_version] if @options[:ssl_version]
@@ -38,6 +38,8 @@ module JIRA
38
38
  @options[:request_token_path] = @options[:context_path] + @options[:request_token_path]
39
39
  @options[:authorize_path] = @options[:context_path] + @options[:authorize_path]
40
40
  @options[:access_token_path] = @options[:context_path] + @options[:access_token_path]
41
+ # proxy_address does not exist in oauth's gem context but proxy does
42
+ @options[:proxy] = @options[:proxy_address] if @options[:proxy_address]
41
43
  OAuth::Consumer.new(@options[:consumer_key], @options[:consumer_secret], @options)
42
44
  end
43
45
 
@@ -5,7 +5,7 @@ module JIRA
5
5
 
6
6
  class Sprint < JIRA::Base
7
7
  def self.find(client, key)
8
- response = client.get("#{client.options[:site]}/rest/agile/1.0/sprint/#{key}")
8
+ response = client.get(agile_path(client, key))
9
9
  json = parse_json(response.body)
10
10
  client.Sprint.build(json)
11
11
  end
@@ -19,7 +19,7 @@ module JIRA
19
19
 
20
20
  def add_issue(issue)
21
21
  request_body = { issues: [issue.id] }.to_json
22
- response = client.post(client.options[:site] + "/rest/agile/1.0/sprint/#{id}/issue", request_body)
22
+ response = client.post("#{agile_path}/issue", request_body)
23
23
  true
24
24
  end
25
25
 
@@ -47,8 +47,8 @@ module JIRA
47
47
  end
48
48
 
49
49
  def get_sprint_details
50
- search_url = client.options[:site] + '/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=' +
51
- rapidview_id.to_s + '&sprintId=' + id.to_s
50
+ search_url =
51
+ "#{client.options[:site]}#{client.options[:client_path]}/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=#{rapidview_id}&sprintId=#{id}"
52
52
  begin
53
53
  response = client.get(search_url)
54
54
  rescue StandardError
@@ -76,12 +76,12 @@ module JIRA
76
76
 
77
77
  def save(attrs = {}, _path = nil)
78
78
  attrs = @attrs if attrs.empty?
79
- super(attrs, agile_url)
79
+ super(attrs, agile_path)
80
80
  end
81
81
 
82
82
  def save!(attrs = {}, _path = nil)
83
83
  attrs = @attrs if attrs.empty?
84
- super(attrs, agile_url)
84
+ super(attrs, agile_path)
85
85
  end
86
86
 
87
87
  # WORK IN PROGRESS
@@ -93,8 +93,12 @@ module JIRA
93
93
 
94
94
  private
95
95
 
96
- def agile_url
97
- "#{client.options[:site]}/rest/agile/1.0/sprint/#{id}"
96
+ def agile_path
97
+ self.class.agile_path(client, id)
98
+ end
99
+
100
+ def self.agile_path(client, key)
101
+ "#{client.options[:context_path]}/rest/agile/1.0/sprint/#{key}"
98
102
  end
99
103
  end
100
104
  end
@@ -18,7 +18,7 @@ module JIRA
18
18
 
19
19
  # Cannot retrieve more than 1,000 users through the api, please see: https://jira.atlassian.com/browse/JRASERVER-65089
20
20
  def self.all(client)
21
- response = client.get("/rest/api/2/user/search?username=_&maxResults=#{MAX_RESULTS}")
21
+ response = client.get("/rest/api/2/users/search?username=_&maxResults=#{MAX_RESULTS}")
22
22
  all_users = JSON.parse(response.body)
23
23
 
24
24
  all_users.flatten.uniq.map do |user|
data/lib/jira/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.1.5'.freeze
3
3
  end
@@ -21,18 +21,18 @@ describe JIRA::Resource::User do
21
21
  describe '#all' do
22
22
  let(:client) do
23
23
  client = double(options: { rest_base_path: '/jira/rest/api/2' })
24
- allow(client).to receive(:get).with('/rest/api/2/user/search?username=_&maxResults=1000').and_return(JIRA::Resource::UserFactory.new(client))
24
+ allow(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000').and_return(JIRA::Resource::UserFactory.new(client))
25
25
  client
26
26
  end
27
27
 
28
28
  before do
29
29
  allow(client).to receive(:get)
30
- .with('/rest/api/2/user/search?username=_&maxResults=1000') { OpenStruct.new(body: '["User1"]') }
30
+ .with('/rest/api/2/users/search?username=_&maxResults=1000') { OpenStruct.new(body: '["User1"]') }
31
31
  allow(client).to receive_message_chain(:User, :build).with('users') { [] }
32
32
  end
33
33
 
34
34
  it 'gets users with maxResults of 1000' do
35
- expect(client).to receive(:get).with('/rest/api/2/user/search?username=_&maxResults=1000')
35
+ expect(client).to receive(:get).with('/rest/api/2/users/search?username=_&maxResults=1000')
36
36
  expect(client).to receive_message_chain(:User, :build).with('User1')
37
37
  JIRA::Resource::User.all(client)
38
38
  end
@@ -369,6 +369,18 @@ describe JIRA::Base do
369
369
  expect(subject.url).to eq('http://foo/bar')
370
370
  end
371
371
 
372
+ it 'returns path as the URL if set and site options is specified' do
373
+ allow(client).to receive(:options) { { site: 'http://foo' } }
374
+ attrs['self'] = 'http://foo/bar'
375
+ expect(subject.url).to eq('/bar')
376
+ end
377
+
378
+ it 'returns path as the URL if set and site options is specified and ends with a slash' do
379
+ allow(client).to receive(:options) { { site: 'http://foo/' } }
380
+ attrs['self'] = 'http://foo/bar'
381
+ expect(subject.url).to eq('/bar')
382
+ end
383
+
372
384
  it 'generates the URL from id if self not set' do
373
385
  attrs['self'] = nil
374
386
  attrs['id'] = '98765'
@@ -59,6 +59,19 @@ RSpec.shared_examples 'Client Common Tests' do
59
59
  expect(subject.Project.find('123')).to eq(find_result)
60
60
  end
61
61
  end
62
+
63
+ describe 'SSL client options' do
64
+ context 'without certificate and key' do
65
+ let(:options) { { use_client_cert: true } }
66
+ subject { JIRA::Client.new(options) }
67
+
68
+ it 'raises an ArgumentError' do
69
+ expect { subject }.to raise_exception(ArgumentError, 'Options: :cert_path or :ssl_client_cert must be set when :use_client_cert is true')
70
+ options[:ssl_client_cert] = '<cert></cert>'
71
+ expect { subject }.to raise_exception(ArgumentError, 'Options: :key_path or :ssl_client_key must be set when :use_client_cert is true')
72
+ end
73
+ end
74
+ end
62
75
  end
63
76
 
64
77
  RSpec.shared_examples 'HttpClient tests' do
@@ -266,4 +279,13 @@ describe JIRA::Client do
266
279
 
267
280
  include_examples 'OAuth Common Tests'
268
281
  end
282
+
283
+ context 'with unknown options' do
284
+ let(:options) { { 'username' => 'foo', 'password' => 'bar', auth_type: :basic } }
285
+ subject { JIRA::Client.new(options) }
286
+
287
+ it 'raises an ArgumentError' do
288
+ expect { subject }.to raise_exception(ArgumentError, 'Unknown option(s) given: ["username", "password"]')
289
+ end
290
+ end
269
291
  end
@@ -280,8 +280,8 @@ describe JIRA::HttpClient do
280
280
  expect(http_conn).to receive(:use_ssl=).with(basic_client.options[:use_ssl])
281
281
  expect(http_conn).to receive(:verify_mode=).with(basic_client.options[:ssl_verify_mode])
282
282
  expect(http_conn).to receive(:read_timeout=).with(basic_client.options[:read_timeout])
283
- expect(http_conn).to receive(:cert=).with(basic_client_cert_client.options[:cert])
284
- expect(http_conn).to receive(:key=).with(basic_client_cert_client.options[:key])
283
+ expect(http_conn).to receive(:cert=).with(basic_client_cert_client.options[:ssl_client_cert])
284
+ expect(http_conn).to receive(:key=).with(basic_client_cert_client.options[:ssl_client_key])
285
285
  expect(basic_client_cert_client.http_conn(uri)).to eq(http_conn)
286
286
  end
287
287
 
@@ -1,12 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe JIRA::Resource::Sprint do
4
- describe 'peristence' do
5
- let(:sprint) { described_class.new(client) }
6
- let(:client) { double('Client', options: { site: 'https://foo.bar.com' }) }
4
+ let(:client) do
5
+ client = double(options: { site: 'https://foo.bar.com', context_path: '/jira' })
6
+ allow(client).to receive(:Sprint).and_return(JIRA::Resource::SprintFactory.new(client))
7
+ client
8
+ end
9
+ let(:sprint) { described_class.new(client) }
10
+ let(:agile_sprint_path) { "#{sprint.client.options[:context_path]}/rest/agile/1.0/sprint/#{sprint.id}" }
7
11
 
12
+ describe '::find' do
13
+ let(:response) { double('Response', body: '{"some_detail":"some detail"}') }
14
+
15
+ it 'fetches the sprint from JIRA' do
16
+ expect(client).to receive(:get).with('/jira/rest/agile/1.0/sprint/111').and_return(response)
17
+ expect(JIRA::Resource::Sprint.find(client, '111')).to be_a(JIRA::Resource::Sprint)
18
+ end
19
+ end
20
+
21
+ describe 'peristence' do
8
22
  describe '#save' do
9
- let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
10
23
  let(:instance_attrs) { { start_date: '2016-06-01' } }
11
24
 
12
25
  before do
@@ -17,7 +30,7 @@ describe JIRA::Resource::Sprint do
17
30
  let(:given_attrs) { { start_date: '2016-06-10' } }
18
31
 
19
32
  it 'calls save on the super class with the given attributes & agile url' do
20
- expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_url)
33
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(given_attrs, agile_sprint_path)
21
34
 
22
35
  sprint.save(given_attrs)
23
36
  end
@@ -25,7 +38,7 @@ describe JIRA::Resource::Sprint do
25
38
 
26
39
  context 'when attributes are not specified' do
27
40
  it 'calls save on the super class with the instance attributes & agile url' do
28
- expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
41
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
29
42
 
30
43
  sprint.save
31
44
  end
@@ -33,7 +46,7 @@ describe JIRA::Resource::Sprint do
33
46
 
34
47
  context 'when providing the path argument' do
35
48
  it 'ignores it' do
36
- expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_url)
49
+ expect_any_instance_of(JIRA::Base).to receive(:save).with(instance_attrs, agile_sprint_path)
37
50
 
38
51
  sprint.save({}, 'mavenlink.com')
39
52
  end
@@ -41,7 +54,6 @@ describe JIRA::Resource::Sprint do
41
54
  end
42
55
 
43
56
  describe '#save!' do
44
- let(:agile_sprint_url) { "#{sprint.client.options[:site]}/rest/agile/1.0/sprint/#{sprint.id}" }
45
57
  let(:instance_attrs) { { start_date: '2016-06-01' } }
46
58
 
47
59
  before do
@@ -52,7 +64,7 @@ describe JIRA::Resource::Sprint do
52
64
  let(:given_attrs) { { start_date: '2016-06-10' } }
53
65
 
54
66
  it 'calls save! on the super class with the given attributes & agile url' do
55
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_url)
67
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(given_attrs, agile_sprint_path)
56
68
 
57
69
  sprint.save!(given_attrs)
58
70
  end
@@ -60,7 +72,7 @@ describe JIRA::Resource::Sprint do
60
72
 
61
73
  context 'when attributes are not specified' do
62
74
  it 'calls save! on the super class with the instance attributes & agile url' do
63
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
75
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
64
76
 
65
77
  sprint.save!
66
78
  end
@@ -68,7 +80,7 @@ describe JIRA::Resource::Sprint do
68
80
 
69
81
  context 'when providing the path argument' do
70
82
  it 'ignores it' do
71
- expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_url)
83
+ expect_any_instance_of(JIRA::Base).to receive(:save!).with(instance_attrs, agile_sprint_path)
72
84
 
73
85
  sprint.save!({}, 'mavenlink.com')
74
86
  end
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: 2.0.0
4
+ version: 2.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-16 00:00:00.000000000 Z
12
+ date: 2021-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -385,8 +385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
385
  - !ruby/object:Gem::Version
386
386
  version: '0'
387
387
  requirements: []
388
- rubyforge_project:
389
- rubygems_version: 2.5.1
388
+ rubygems_version: 3.1.2
390
389
  signing_key:
391
390
  specification_version: 4
392
391
  summary: Ruby Gem for use with the Atlassian JIRA REST API