issue-db 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7e786c1b79b72e6ef52d8347d5d647f5275c714fd72699fd187032034ee0aae
4
- data.tar.gz: 6f18ea1176291ab1a6da20e90bc7e95d7ca3f727097c012a31bf3adb50faf1e3
3
+ metadata.gz: 6f4349ba13a8c9f2971aae3c557c6bcd8d0b1b3fc51ecb4a901e3db2a30538db
4
+ data.tar.gz: a59e1724a2f9068bd4596a311b051224ad48a8df158e0607f5dc51374f096033
5
5
  SHA512:
6
- metadata.gz: 4379608b58b9cc396deeabfed41e01753e927792483000f3047e4c600eb0b2cf02e49ee53c3b8c34a7de494713899f9abc944013d344263961a20e13197a2cab
7
- data.tar.gz: 11da329ed7e764483a38934d552ad87dddbec88b9be0136de249fa45d5519604b176b9a3fe2f33d5a13c61e37c64c1af374fc2e8cdbe774e45065bae28cf8d89
6
+ metadata.gz: e64935039edab751270a2fe8d924d32fff52035364baaa0a6455cf2fd0931fd4c51d39164b283435646c44cde628d3fb5cd98908673d8a1c0138a028855750d3
7
+ data.tar.gz: 28e242676837588f0dbadf5dc831569bc26e703d2533938daebe62e0eb45d59c3d243d8678d4f91dd03baeba371f40cc3272a4290d23af6b6bafd88aac8b2976
@@ -16,7 +16,13 @@ module Cache
16
16
  rescue StandardError => e
17
17
  retry_err_msg = "error search_issues() call: #{e.message}"
18
18
  @log.error(retry_err_msg)
19
- raise retry_err_msg
19
+ raise StandardError, retry_err_msg
20
+ end
21
+
22
+ # Safety check to ensure search_response and items are not nil
23
+ if search_response.nil? || search_response.items.nil?
24
+ @log.error("search_issues returned nil response or nil items")
25
+ raise StandardError, "search_issues returned invalid response"
20
26
  end
21
27
 
22
28
  @log.debug("issue cache updated - cached #{search_response.total_count} issues")
@@ -51,8 +51,11 @@ class Database
51
51
  # if we make it here, no existing issues were found so we can safely create one
52
52
  issue = @client.create_issue(@repo.full_name, key, body, { labels: @label })
53
53
 
54
- # append the newly created issue to the issues cache
55
- @issues << issue
54
+ # ensure the cache is initialized before appending and handle race conditions
55
+ current_issues = issues
56
+ if current_issues && !current_issues.include?(issue)
57
+ @issues << issue
58
+ end
56
59
 
57
60
  @log.debug("issue created: #{key}")
58
61
  return Record.new(issue)
@@ -89,7 +92,14 @@ class Database
89
92
  updated_issue = @client.update_issue(@repo.full_name, issue.number, key, body)
90
93
 
91
94
  # update the issue in the cache using the reference we have
92
- @issues[@issues.index(issue)] = updated_issue
95
+ index = @issues.index(issue)
96
+ if index
97
+ @issues[index] = updated_issue
98
+ else
99
+ @log.warn("issue not found in cache during update: #{key}")
100
+ # Force a cache refresh to ensure consistency
101
+ update_issue_cache!
102
+ end
93
103
 
94
104
  @log.debug("issue updated: #{key}")
95
105
  return Record.new(updated_issue)
@@ -105,8 +115,15 @@ class Database
105
115
 
106
116
  deleted_issue = @client.close_issue(@repo.full_name, issue.number)
107
117
 
108
- # remove the issue from the cache
109
- @issues.delete(issue)
118
+ # update the issue in the cache using the reference we have
119
+ index = @issues.index(issue)
120
+ if index
121
+ @issues[index] = deleted_issue
122
+ else
123
+ @log.warn("issue not found in cache during delete: #{key}")
124
+ # Force a cache refresh to ensure consistency
125
+ update_issue_cache!
126
+ end
110
127
 
111
128
  # return the deleted issue as a Record object as it may contain useful data
112
129
  return Record.new(deleted_issue)
@@ -120,7 +137,10 @@ class Database
120
137
  # options = {include_closed: true}
121
138
  # keys = db.list_keys(options)
122
139
  def list_keys(options = {})
123
- keys = issues.select do |issue|
140
+ current_issues = issues
141
+ return [] if current_issues.nil?
142
+
143
+ keys = current_issues.select do |issue|
124
144
  options[:include_closed] || issue[:state] == "open"
125
145
  end.map do |issue|
126
146
  issue[:title]
@@ -137,7 +157,10 @@ class Database
137
157
  # options = {include_closed: true}
138
158
  # records = db.list(options)
139
159
  def list(options = {})
140
- records = issues.select do |issue|
160
+ current_issues = issues
161
+ return [] if current_issues.nil?
162
+
163
+ records = current_issues.select do |issue|
141
164
  options[:include_closed] || issue[:state] == "open"
142
165
  end.map do |issue|
143
166
  Record.new(issue)
@@ -187,9 +210,8 @@ class Database
187
210
  # update the issues cache if it is nil
188
211
  update_issue_cache! if @issues.nil?
189
212
 
190
- # update the cache if it has expired
191
- issues_cache_expired = (Time.now - @issues_last_updated) > @cache_expiry
192
- if issues_cache_expired
213
+ # update the cache if it has expired (with nil safety)
214
+ if !@issues_last_updated.nil? && (Time.now - @issues_last_updated) > @cache_expiry
193
215
  @log.debug("issue cache expired - last updated: #{@issues_last_updated} - refreshing now")
194
216
  update_issue_cache!
195
217
  end
@@ -276,7 +276,10 @@ class GitHub
276
276
  # @param args [Array] The arguments passed to the method.
277
277
  # @param block [Proc] An optional block passed to the method.
278
278
  # @return [Object] The result of the method call on the Octokit client.
279
- def method_missing(method, *args, &block)
279
+ def method_missing(method, *args, **kwargs, &block)
280
+ # Check if retry is explicitly disabled for this call
281
+ disable_retry = kwargs.delete(:disable_retry) || false
282
+
280
283
  # Determine the rate limit type based on the method name and arguments
281
284
  rate_limit_type = case method.to_s
282
285
  when /search_/
@@ -296,10 +299,16 @@ class GitHub
296
299
 
297
300
  # Handle special case for search_issues which can hit secondary rate limits
298
301
  if method.to_s == "search_issues"
302
+ request_proc = proc do
303
+ wait_for_rate_limit!(rate_limit_type)
304
+ client.send(method, *args, **kwargs, &block) # rubocop:disable GitHub/AvoidObjectSendWithDynamicMethod
305
+ end
306
+
299
307
  begin
300
- retry_request do
301
- wait_for_rate_limit!(rate_limit_type)
302
- client.send(method, *args, &block) # rubocop:disable GitHub/AvoidObjectSendWithDynamicMethod
308
+ if disable_retry
309
+ request_proc.call
310
+ else
311
+ retry_request(&request_proc)
303
312
  end
304
313
  rescue StandardError => e
305
314
  # re-raise the error but if its a secondary rate limit error, just sleep for a minute
@@ -311,9 +320,15 @@ class GitHub
311
320
  end
312
321
  else
313
322
  # For all other methods, use standard retry and rate limiting
314
- retry_request do
323
+ request_proc = proc do
315
324
  wait_for_rate_limit!(rate_limit_type)
316
- client.send(method, *args, &block) # rubocop:disable GitHub/AvoidObjectSendWithDynamicMethod
325
+ client.send(method, *args, **kwargs, &block) # rubocop:disable GitHub/AvoidObjectSendWithDynamicMethod
326
+ end
327
+
328
+ if disable_retry
329
+ request_proc.call
330
+ else
331
+ retry_request(&request_proc)
317
332
  end
318
333
  end
319
334
  end
@@ -9,10 +9,11 @@ module Init
9
9
  @repo.full_name,
10
10
  @label,
11
11
  "000000",
12
- { description: "This issue is managed by the issue-db Ruby library. Please do not remove this label." }
12
+ { description: "This issue is managed by the issue-db Ruby library. Please do not remove this label." },
13
+ disable_retry: true
13
14
  )
14
15
  rescue StandardError => e
15
- if e.message.include?("code: already_exists")
16
+ if e.message.include?("already_exists")
16
17
  @log.debug("label #{@label} already exists")
17
18
  else
18
19
  @log.error("error creating label: #{e.message}") unless ENV.fetch("ENV", nil) == "acceptance"
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Version
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: issue-db
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - runwaylab