ruby-jira 0.1.0 → 0.3.0
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/CHANGELOG.md +24 -0
- data/README.md +200 -19
- data/lib/jira/client/agile_issues.rb +57 -0
- data/lib/jira/client/boards.rb +291 -0
- data/lib/jira/client/epics.rb +84 -0
- data/lib/jira/client/issue_comments.rb +80 -0
- data/lib/jira/client/issue_search.rb +60 -0
- data/lib/jira/client/issue_worklogs.rb +123 -0
- data/lib/jira/client/issues.rb +191 -0
- data/lib/jira/client/project_categories.rb +60 -0
- data/lib/jira/client/project_permission_schemes.rb +18 -0
- data/lib/jira/client/project_properties.rb +54 -0
- data/lib/jira/client/projects.rb +60 -0
- data/lib/jira/client/sprints.rb +139 -0
- data/lib/jira/client/time_tracking.rb +57 -0
- data/lib/jira/client.rb +10 -0
- data/lib/jira/configuration.rb +2 -0
- data/lib/jira/error.rb +3 -0
- data/lib/jira/logging.rb +15 -0
- data/lib/jira/pagination/collection_behavior.rb +72 -0
- data/lib/jira/pagination/cursor_paginated_response.rb +57 -41
- data/lib/jira/pagination/paginated_response.rb +46 -50
- data/lib/jira/request/rate_limiting.rb +6 -6
- data/lib/jira/request/request_building.rb +7 -6
- data/lib/jira/request/response_parsing.rb +82 -16
- data/lib/jira/request.rb +57 -23
- data/lib/jira/version.rb +1 -1
- data/lib/jira.rb +2 -0
- metadata +13 -2
- data/lib/jira/request/paginated_response.rb +0 -4
data/lib/jira/request.rb
CHANGED
|
@@ -6,6 +6,7 @@ require "json"
|
|
|
6
6
|
require "time"
|
|
7
7
|
require "uri"
|
|
8
8
|
|
|
9
|
+
require_relative "logging"
|
|
9
10
|
require_relative "request/authentication"
|
|
10
11
|
require_relative "request/rate_limiting"
|
|
11
12
|
require_relative "request/request_building"
|
|
@@ -15,6 +16,7 @@ module Jira
|
|
|
15
16
|
# @private
|
|
16
17
|
class Request
|
|
17
18
|
include HTTParty
|
|
19
|
+
include Logging
|
|
18
20
|
|
|
19
21
|
OAUTH_MISSING_CREDENTIALS_MESSAGE = Authenticator::OAUTH_MISSING_CREDENTIALS_MESSAGE
|
|
20
22
|
|
|
@@ -76,54 +78,86 @@ module Jira
|
|
|
76
78
|
|
|
77
79
|
private
|
|
78
80
|
|
|
79
|
-
def execute_request(method, path, options)
|
|
81
|
+
def execute_request(method, path, options, api_path: UrlBuilder::PLATFORM_API_PATH)
|
|
80
82
|
params = params_builder.build(options)
|
|
81
83
|
retries_left = retries_left_for(params)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
+
log "#{method.upcase} #{path} #{options.inspect}"
|
|
85
|
+
result = perform_request_with_retry(method, path, params, retries_left, api_path:)
|
|
86
|
+
log "→ #{result.class}"
|
|
87
|
+
setup_pagination_fetcher!(result, method, path, options, api_path:)
|
|
84
88
|
result
|
|
85
89
|
end
|
|
86
90
|
|
|
87
|
-
def perform_request_with_retry(method, path, params, retries_left)
|
|
88
|
-
response = perform_request(method, path, params)
|
|
91
|
+
def perform_request_with_retry(method, path, params, retries_left, api_path: UrlBuilder::PLATFORM_API_PATH)
|
|
92
|
+
response = perform_request(method, path, params, api_path:)
|
|
89
93
|
validate(response)
|
|
90
94
|
rescue Jira::Error::TooManyRequests, Jira::Error::ServiceUnavailable => e
|
|
91
95
|
raise e unless should_retry?(e, method, response, retries_left)
|
|
92
96
|
|
|
97
|
+
wait = retry_policy.wait_seconds(response: response, retries_left: retries_left - 1)
|
|
98
|
+
log "rate limited (HTTP #{response.code}), retrying in #{wait.round(1)}s (#{retries_left - 1} retries left)"
|
|
93
99
|
retry_policy.sleep_before_retry(response: response, retries_left: retries_left - 1)
|
|
94
100
|
retries_left -= 1
|
|
95
101
|
retry
|
|
96
102
|
end
|
|
97
103
|
|
|
98
|
-
def
|
|
99
|
-
result
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
def setup_pagination_fetcher!(result, method, path, options, api_path: UrlBuilder::PLATFORM_API_PATH)
|
|
105
|
+
case result
|
|
106
|
+
when PaginatedResponse
|
|
107
|
+
result.next_page_fetcher = next_page_lambda(method:, path:, options:, key: :startAt, api_path:)
|
|
108
|
+
when CursorPaginatedResponse
|
|
109
|
+
return unless result.fetcher_based_pagination?
|
|
110
|
+
return if result.cursor_parameter_key.nil?
|
|
111
|
+
|
|
112
|
+
result.next_page_fetcher = next_page_lambda(
|
|
113
|
+
method:, path:, options:, key: result.cursor_parameter_key, api_path:
|
|
114
|
+
)
|
|
108
115
|
end
|
|
109
116
|
end
|
|
110
117
|
|
|
111
|
-
def
|
|
112
|
-
|
|
118
|
+
def next_page_lambda(method:, path:, options:, key:, api_path: UrlBuilder::PLATFORM_API_PATH)
|
|
119
|
+
lambda do |value|
|
|
120
|
+
merged = duplicate_request_options(options)
|
|
121
|
+
inject_pagination_parameter!(options: merged, method:, key:, value:)
|
|
122
|
+
execute_request(method, path, merged, api_path:)
|
|
123
|
+
end
|
|
113
124
|
end
|
|
114
125
|
|
|
115
|
-
|
|
116
|
-
|
|
126
|
+
%w[get post put patch delete].each do |m|
|
|
127
|
+
define_method("agile_#{m}") { |path, opts = {}| execute_request(m, path, opts, api_path: UrlBuilder::AGILE_API_PATH) }
|
|
117
128
|
end
|
|
118
129
|
|
|
119
|
-
def
|
|
120
|
-
|
|
130
|
+
def duplicate_request_options(options)
|
|
131
|
+
duplicated = options.dup
|
|
132
|
+
duplicated[:query] = options[:query].dup if options[:query].is_a?(Hash)
|
|
133
|
+
duplicated[:body] = options[:body].dup if options[:body].is_a?(Hash)
|
|
134
|
+
duplicated
|
|
121
135
|
end
|
|
122
136
|
|
|
123
|
-
def
|
|
124
|
-
|
|
137
|
+
def inject_pagination_parameter!(options:, method:, key:, value:)
|
|
138
|
+
target = pagination_parameter_target(method:, options:)
|
|
139
|
+
options[target] = (options[target] || {}).merge(key => value)
|
|
125
140
|
end
|
|
126
141
|
|
|
142
|
+
def pagination_parameter_target(method:, options:)
|
|
143
|
+
return :query if method.to_s == "get"
|
|
144
|
+
return :body if options[:body].is_a?(Hash)
|
|
145
|
+
|
|
146
|
+
:query
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def perform_request(method, path, params, api_path: UrlBuilder::PLATFORM_API_PATH)
|
|
150
|
+
self.class.send(method, build_url(path, api_path:), params)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def retries_left_for(params)
|
|
154
|
+
params.delete(:ratelimit_retries) || ratelimit_retries || Configuration::DEFAULT_RATELIMIT_RETRIES
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def build_url(path, api_path: UrlBuilder::PLATFORM_API_PATH) = url_builder.build(path, api_path:)
|
|
158
|
+
|
|
159
|
+
def authorization_header = authenticator.authorization_header
|
|
160
|
+
|
|
127
161
|
def should_retry?(error, method, response, retries_left)
|
|
128
162
|
retry_policy.retryable?(error: error, method: method, response: response, retries_left: retries_left)
|
|
129
163
|
end
|
data/lib/jira/version.rb
CHANGED
data/lib/jira.rb
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "jira/version"
|
|
4
4
|
require_relative "jira/configuration"
|
|
5
|
+
require_relative "jira/logging"
|
|
5
6
|
require_relative "jira/error"
|
|
6
7
|
require_relative "jira/objectified_hash"
|
|
8
|
+
require_relative "jira/pagination/collection_behavior"
|
|
7
9
|
require_relative "jira/pagination/paginated_response"
|
|
8
10
|
require_relative "jira/pagination/cursor_paginated_response"
|
|
9
11
|
require_relative "jira/request"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-jira
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Maciej Kozak
|
|
@@ -36,17 +36,28 @@ files:
|
|
|
36
36
|
- lib/jira.rb
|
|
37
37
|
- lib/jira/api.rb
|
|
38
38
|
- lib/jira/client.rb
|
|
39
|
+
- lib/jira/client/agile_issues.rb
|
|
40
|
+
- lib/jira/client/boards.rb
|
|
41
|
+
- lib/jira/client/epics.rb
|
|
42
|
+
- lib/jira/client/issue_comments.rb
|
|
43
|
+
- lib/jira/client/issue_search.rb
|
|
44
|
+
- lib/jira/client/issue_worklogs.rb
|
|
39
45
|
- lib/jira/client/issues.rb
|
|
46
|
+
- lib/jira/client/project_categories.rb
|
|
40
47
|
- lib/jira/client/project_permission_schemes.rb
|
|
48
|
+
- lib/jira/client/project_properties.rb
|
|
41
49
|
- lib/jira/client/projects.rb
|
|
50
|
+
- lib/jira/client/sprints.rb
|
|
51
|
+
- lib/jira/client/time_tracking.rb
|
|
42
52
|
- lib/jira/configuration.rb
|
|
43
53
|
- lib/jira/error.rb
|
|
54
|
+
- lib/jira/logging.rb
|
|
44
55
|
- lib/jira/objectified_hash.rb
|
|
56
|
+
- lib/jira/pagination/collection_behavior.rb
|
|
45
57
|
- lib/jira/pagination/cursor_paginated_response.rb
|
|
46
58
|
- lib/jira/pagination/paginated_response.rb
|
|
47
59
|
- lib/jira/request.rb
|
|
48
60
|
- lib/jira/request/authentication.rb
|
|
49
|
-
- lib/jira/request/paginated_response.rb
|
|
50
61
|
- lib/jira/request/rate_limiting.rb
|
|
51
62
|
- lib/jira/request/request_building.rb
|
|
52
63
|
- lib/jira/request/response_parsing.rb
|