jira-ruby-dmg 0.1.20 → 0.1.21
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 +4 -4
- data/lib/jira/client.rb +24 -4
- data/lib/jira/request_cache.rb +80 -0
- data/lib/jira/resource/agileboard.rb +0 -21
- data/lib/jira/resource/sprint.rb +9 -41
- data/lib/jira/resource/sprint_report.rb +10 -0
- data/lib/jira/version.rb +1 -1
- data/lib/jira.rb +2 -1
- data/spec/jira/request_cache_spec.rb +81 -0
- metadata +6 -3
- data/lib/jira/resource/velocity.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18f7433fcfcb7649f1e731d8a1ddbcb4212a0a18
|
4
|
+
data.tar.gz: 02b14bcdbcd1b9fb4b5bc1bbcd59fab6e18ecf94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd2554cc7e779ebb9355e23a34a2ffe9e7f7eece1814f3aad9f55b0ff68d8a9fc835a77a047334808faaa18dd43b8676b514557bb1caf604947cee5bcaa2f713
|
7
|
+
data.tar.gz: 1b7b34c9b5e1640b31c659c687bd8d54bc103c0a47fb64cc55247e3d05a60a2ff0a8161a3dd1d956f6e2a17e1b37c2ef9a2d18137c735f0ebed404a9dc09b88e
|
data/lib/jira/client.rb
CHANGED
@@ -50,7 +50,9 @@ module JIRA
|
|
50
50
|
:rest_base_path => "/rest/api/2",
|
51
51
|
:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
52
52
|
:use_ssl => true,
|
53
|
-
:auth_type => :oauth
|
53
|
+
:auth_type => :oauth,
|
54
|
+
:enable_caching => false,
|
55
|
+
:cache_ttl => 86400000 # 1 day
|
54
56
|
}
|
55
57
|
|
56
58
|
def initialize(options={})
|
@@ -66,6 +68,8 @@ module JIRA
|
|
66
68
|
@request_client = HttpClient.new(@options)
|
67
69
|
end
|
68
70
|
|
71
|
+
@cache = JIRA::RequestCache.new(@options[:cache_ttl])
|
72
|
+
|
69
73
|
@options.freeze
|
70
74
|
end
|
71
75
|
|
@@ -133,8 +137,8 @@ module JIRA
|
|
133
137
|
JIRA::Resource::AgileboardFactory.new(self)
|
134
138
|
end
|
135
139
|
|
136
|
-
def
|
137
|
-
JIRA::Resource::
|
140
|
+
def SprintReport # :nodoc:
|
141
|
+
JIRA::Resource::SprintReportFactory.new(self)
|
138
142
|
end
|
139
143
|
|
140
144
|
# HTTP methods without a body
|
@@ -143,9 +147,25 @@ module JIRA
|
|
143
147
|
end
|
144
148
|
|
145
149
|
def get(path, headers = {})
|
146
|
-
|
150
|
+
if @options[:enable_caching]
|
151
|
+
get_from_cache(path, headers)
|
152
|
+
else
|
153
|
+
request(:get, path, nil, merge_default_headers(headers))
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def get_from_cache(path, headers)
|
158
|
+
response = @cache.load(path)
|
159
|
+
|
160
|
+
if response == nil
|
161
|
+
response = request(:get, path, nil, merge_default_headers(headers))
|
162
|
+
@cache.save(path, response)
|
163
|
+
end
|
164
|
+
|
165
|
+
response
|
147
166
|
end
|
148
167
|
|
168
|
+
|
149
169
|
def head(path, headers = {})
|
150
170
|
request(:head, path, nil, merge_default_headers(headers))
|
151
171
|
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module JIRA
|
2
|
+
|
3
|
+
class RequestCache
|
4
|
+
|
5
|
+
def initialize(time_to_live)
|
6
|
+
@time_to_live = time_to_live
|
7
|
+
end
|
8
|
+
|
9
|
+
def load(path)
|
10
|
+
key = cache_key(path)
|
11
|
+
cache_object = cache(path)
|
12
|
+
response = verify cache_object[key]
|
13
|
+
|
14
|
+
if response == :expired
|
15
|
+
cache_object.delete(key)
|
16
|
+
cache_file(path, 'w+').write(Marshal.dump(cache_object))
|
17
|
+
nil
|
18
|
+
else
|
19
|
+
response
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save(path, response)
|
24
|
+
now = Time.now.to_i
|
25
|
+
|
26
|
+
new_cache = cache(path)
|
27
|
+
new_cache[cache_key(path)] = {
|
28
|
+
'data' => response,
|
29
|
+
'timestamp' => now
|
30
|
+
}
|
31
|
+
|
32
|
+
cache_file(path, 'w+').write(Marshal.dump(new_cache))
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def verify(cache_value)
|
39
|
+
now = Time.now.to_i
|
40
|
+
#binding.pry
|
41
|
+
if cache_value == nil
|
42
|
+
return nil
|
43
|
+
elsif cache_value['timestamp'] < (now - @time_to_live)
|
44
|
+
:expired
|
45
|
+
else
|
46
|
+
cache_value['data']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def cache(path)
|
51
|
+
#binding.pry
|
52
|
+
if File.exists? 'cache/' + path
|
53
|
+
Marshal.restore(cache_file(path, 'r+').read())
|
54
|
+
else
|
55
|
+
{}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def cache_key(path)
|
60
|
+
return "key"
|
61
|
+
#Marshal.dump(path)
|
62
|
+
end
|
63
|
+
|
64
|
+
def cache_file(path, mode)
|
65
|
+
dir = cache_dir
|
66
|
+
File.new(dir + '/' + path, mode)
|
67
|
+
end
|
68
|
+
|
69
|
+
def cache_dir
|
70
|
+
dir = 'cache'
|
71
|
+
|
72
|
+
unless Dir.exists? dir
|
73
|
+
FileUtils.mkdir_p(dir)
|
74
|
+
end
|
75
|
+
|
76
|
+
dir
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -47,27 +47,6 @@ module JIRA
|
|
47
47
|
client.Sprint.build(sprint)
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
51
|
-
# get velocities of agile board
|
52
|
-
def velocities
|
53
|
-
search_url = client.options[:site] +
|
54
|
-
'/rest/greenhopper/1.0/rapid/charts/velocity.json?rapidViewId=' + id.to_s
|
55
|
-
|
56
|
-
begin
|
57
|
-
response = client.get(search_url)
|
58
|
-
rescue
|
59
|
-
return []
|
60
|
-
end
|
61
|
-
|
62
|
-
json = self.class.parse_json(response.body)
|
63
|
-
json['velocityStatEntries'].map do |velocity|
|
64
|
-
client.Velocity.build({
|
65
|
-
"sprint_id" => velocity[0],
|
66
|
-
"estimated" => velocity[1]['estimated']['value'],
|
67
|
-
"completed" => velocity[1]['completed']['value']
|
68
|
-
})
|
69
|
-
end
|
70
|
-
end
|
71
50
|
|
72
51
|
end
|
73
52
|
end
|
data/lib/jira/resource/sprint.rb
CHANGED
@@ -30,52 +30,20 @@ module JIRA
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
def velocity
|
38
|
-
unless attrs.keys.include? "velocity"
|
39
|
-
@attrs["velocity"] = get_velocity
|
40
|
-
end
|
41
|
-
|
42
|
-
@attrs["velocity"]
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
def get_velocity
|
47
|
-
search_url = client.options[:site] +
|
48
|
-
'/rest/greenhopper/1.0/rapid/charts/velocity.json?rapidViewId=' + agileboard_id.to_s
|
49
|
-
begin
|
50
|
-
response = client.get(search_url).body
|
51
|
-
rescue
|
52
|
-
return empty_velocity
|
33
|
+
def sprint_report
|
34
|
+
if @sprint_report
|
35
|
+
return @sprint_report
|
53
36
|
end
|
54
37
|
|
55
|
-
|
56
|
-
|
57
|
-
sprint_id.to_i == id.to_i
|
58
|
-
end
|
59
|
-
|
60
|
-
if resultVelocity.length == 0
|
61
|
-
return empty_velocity
|
62
|
-
end
|
38
|
+
search_url = client.options[:site] + "/rest/greenhopper/1.0/rapid/charts/sprintreport?rapidViewId=" +
|
39
|
+
agileboard_id.to_s + "&sprintId=" + id.to_s
|
63
40
|
|
64
|
-
client.
|
65
|
-
|
66
|
-
"estimated" => resultVelocity[id.to_s]['estimated']['value'],
|
67
|
-
"completed" => resultVelocity[id.to_s]['completed']['value']
|
68
|
-
})
|
69
|
-
end
|
41
|
+
response = client.get(search_url)
|
42
|
+
json = self.class.parse_json(response.body)
|
70
43
|
|
71
|
-
|
72
|
-
client.Velocity.build({
|
73
|
-
"sprint_id" => id,
|
74
|
-
"estimated" => 0,
|
75
|
-
"completed" => 0
|
76
|
-
})
|
44
|
+
client.SprintReport.build(json['contents'])
|
77
45
|
end
|
78
46
|
|
79
47
|
end
|
80
48
|
end
|
81
|
-
end
|
49
|
+
end
|
data/lib/jira/version.rb
CHANGED
data/lib/jira.rb
CHANGED
@@ -18,7 +18,7 @@ require 'jira/resource/version'
|
|
18
18
|
require 'jira/resource/status'
|
19
19
|
require 'jira/resource/transition'
|
20
20
|
require 'jira/resource/filter'
|
21
|
-
require 'jira/resource/
|
21
|
+
require 'jira/resource/sprint_report'
|
22
22
|
require 'jira/resource/sprint'
|
23
23
|
require 'jira/resource/project'
|
24
24
|
require 'jira/resource/priority'
|
@@ -28,6 +28,7 @@ require 'jira/resource/issue'
|
|
28
28
|
require 'jira/resource/field'
|
29
29
|
require 'jira/resource/agileboard'
|
30
30
|
|
31
|
+
require 'jira/request_cache'
|
31
32
|
require 'jira/request_client'
|
32
33
|
require 'jira/oauth_client'
|
33
34
|
require 'jira/http_client'
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe JIRA::RequestCache do
|
4
|
+
|
5
|
+
subject {
|
6
|
+
JIRA::RequestCache.new(86400000)
|
7
|
+
}
|
8
|
+
|
9
|
+
let(:now) { Time.now.to_i }
|
10
|
+
let(:response) { {"key" => {"data" => "foo", "timestamp" => now}} }
|
11
|
+
let(:test_file) { double("test_file", :read => Marshal.dump(response), :write => nil) }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
File.stub(:exists?) { true }
|
15
|
+
Dir.stub(:exists?) { true }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'load' do
|
19
|
+
|
20
|
+
context "existing cache file" do
|
21
|
+
|
22
|
+
before(:each) do
|
23
|
+
File.should_receive(:new).with('cache/test_path', 'r+').and_return(test_file)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create cache dir if not exists" do
|
27
|
+
Dir.stub(:exists?) { false }
|
28
|
+
FileUtils.should_receive(:mkdir_p).at_least(1).times.with('cache')
|
29
|
+
subject.load('test_path')
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should load from correct path" do
|
33
|
+
subject.load('test_path')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return the correct result" do
|
37
|
+
subject.load('test_path').should == 'foo'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should delete expired entries" do
|
41
|
+
Time.should_receive(:now).and_return(double('now', { :to_i => 572349597437239075456456 }))
|
42
|
+
File.should_receive(:new).with('cache/test_path', 'w+').and_return(test_file)
|
43
|
+
test_file.should_receive(:write).with(Marshal.dump({}))
|
44
|
+
|
45
|
+
subject.load('test_path')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "without existing cache file" do
|
50
|
+
|
51
|
+
it "should not try to load file if not exists" do
|
52
|
+
File.stub(:exists?) { false }
|
53
|
+
File.should_receive(:new).exactly(0).times
|
54
|
+
subject.load('test_path')
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'save' do
|
61
|
+
|
62
|
+
before(:each) do
|
63
|
+
Time.stub(:now) { double({:to_i => 42}) }
|
64
|
+
File.should_receive(:new).with('cache/test_path', 'r+').and_return(test_file)
|
65
|
+
File.should_receive(:new).with('cache/test_path', 'w+').and_return(test_file)
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:test_response) { 'bar' }
|
69
|
+
|
70
|
+
it "should load from correct path" do
|
71
|
+
subject.save('test_path', test_response)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should save the correct response" do
|
75
|
+
expected_cache = {"key" => {"data" => test_response, "timestamp" => 42}}
|
76
|
+
test_file.should_receive(:write).with(Marshal.dump(expected_cache))
|
77
|
+
|
78
|
+
subject.save('test_path', test_response)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jira-ruby-dmg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ThisIs! DMG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/jira/http_error.rb
|
119
119
|
- lib/jira/oauth_client.rb
|
120
120
|
- lib/jira/railtie.rb
|
121
|
+
- lib/jira/request_cache.rb
|
121
122
|
- lib/jira/request_client.rb
|
122
123
|
- lib/jira/resource/agileboard.rb
|
123
124
|
- lib/jira/resource/attachment.rb
|
@@ -130,10 +131,10 @@ files:
|
|
130
131
|
- lib/jira/resource/priority.rb
|
131
132
|
- lib/jira/resource/project.rb
|
132
133
|
- lib/jira/resource/sprint.rb
|
134
|
+
- lib/jira/resource/sprint_report.rb
|
133
135
|
- lib/jira/resource/status.rb
|
134
136
|
- lib/jira/resource/transition.rb
|
135
137
|
- lib/jira/resource/user.rb
|
136
|
-
- lib/jira/resource/velocity.rb
|
137
138
|
- lib/jira/resource/version.rb
|
138
139
|
- lib/jira/resource/worklog.rb
|
139
140
|
- lib/jira/tasks.rb
|
@@ -159,6 +160,7 @@ files:
|
|
159
160
|
- spec/jira/http_client_spec.rb
|
160
161
|
- spec/jira/http_error_spec.rb
|
161
162
|
- spec/jira/oauth_client_spec.rb
|
163
|
+
- spec/jira/request_cache_spec.rb
|
162
164
|
- spec/jira/request_client_spec.rb
|
163
165
|
- spec/jira/resource/attachment_spec.rb
|
164
166
|
- spec/jira/resource/filter_spec.rb
|
@@ -254,6 +256,7 @@ test_files:
|
|
254
256
|
- spec/jira/http_client_spec.rb
|
255
257
|
- spec/jira/http_error_spec.rb
|
256
258
|
- spec/jira/oauth_client_spec.rb
|
259
|
+
- spec/jira/request_cache_spec.rb
|
257
260
|
- spec/jira/request_client_spec.rb
|
258
261
|
- spec/jira/resource/attachment_spec.rb
|
259
262
|
- spec/jira/resource/filter_spec.rb
|