Skip to content

Commit 319d229

Browse files
committed
Fix rubocop freakouts
Rubocop was unhappy with the `save_api_cache!` and `load_api_cache!` methods introduced in #5042 - some were legit problems but it had spurious errors around method length and Cyclomatic Complexity, which are not worth fixing.
1 parent a97571f commit 319d229

File tree

2 files changed

+59
-39
lines changed

2 files changed

+59
-39
lines changed

.rubocop.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@ Style/TrailingCommaInArrayLiteral:
3232

3333
Style/TrailingCommaInHashLiteral:
3434
EnforcedStyleForMultiline: consistent_comma
35+
36+
Metrics/AbcSize:
37+
Exclude:
38+
- 'test/test_helper.rb'
39+
40+
Metrics/MethodLength:
41+
Exclude:
42+
- 'test/test_helper.rb'
43+
44+
Metrics/CyclomaticComplexity:
45+
Exclude:
46+
- 'test/test_helper.rb'
47+
48+
Metrics/PerceivedComplexity:
49+
Exclude:
50+
- 'test/test_helper.rb'

test/test_helper.rb

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -280,44 +280,40 @@ def load_api_cache!
280280
now = Time.now.to_i
281281
ttl = CACHE_TTL_SECONDS
282282

283-
if data["repos"]
284-
data["repos"].each do |key, entry|
285-
cached_at = entry["cached_at"]
286-
next unless cached_at
287-
next if now - cached_at.to_i > ttl
288-
289-
result = entry["value"]
290-
# Reconstruct a minimal object that responds to .full_name
291-
cached = if result.nil?
292-
nil
293-
else
294-
next unless result["full_name"]
295-
296-
Struct.new(:full_name).new(result["full_name"])
297-
end
298-
NewOctokit.class_variable_get(:@@repos)[key] = cached
299-
end
283+
data["repos"]&.each do |key, entry|
284+
cached_at = entry["cached_at"]
285+
next unless cached_at
286+
next if now - cached_at.to_i > ttl
287+
288+
result = entry["value"]
289+
# Reconstruct a minimal object that responds to .full_name
290+
cached = if result.nil?
291+
nil
292+
else
293+
next unless result["full_name"]
294+
295+
Struct.new(:full_name).new(result["full_name"])
296+
end
297+
NewOctokit.class_variable_get(:@@repos)[key] = cached
300298
end
301299

302-
if data["users"]
303-
data["users"].each do |key, entry|
304-
cached_at = entry["cached_at"]
305-
next unless cached_at
306-
next if now - cached_at.to_i > ttl
307-
308-
result = entry["value"]
309-
cached = if result.nil?
310-
nil
311-
else
312-
next unless result["login"]
313-
314-
Struct.new(:login).new(result["login"])
315-
end
316-
NewOctokit.class_variable_get(:@@users)[key] = cached
317-
end
300+
data["users"]&.each do |key, entry|
301+
cached_at = entry["cached_at"]
302+
next unless cached_at
303+
next if now - cached_at.to_i > ttl
304+
305+
result = entry["value"]
306+
cached = if result.nil?
307+
nil
308+
else
309+
next unless result["login"]
310+
311+
Struct.new(:login).new(result["login"])
312+
end
313+
NewOctokit.class_variable_get(:@@users)[key] = cached
318314
end
319-
rescue JSON::ParserError, StandardError => e
320-
warn "Failed to load API cache: #{e.message}"
315+
rescue StandardError => error
316+
warn "Failed to load API cache: #{error.message}"
321317
end
322318

323319
def save_api_cache!
@@ -331,7 +327,11 @@ def save_api_cache!
331327

332328
repos_data[key.to_s] = {
333329
"cached_at" => now,
334-
"value" => value.nil? ? nil : { "full_name" => value.respond_to?(:full_name) ? value.full_name : value.to_s },
330+
"value" => if value.nil?
331+
nil
332+
else
333+
{ "full_name" => value.respond_to?(:full_name) ? value.full_name : value.to_s }
334+
end,
335335
}
336336
end
337337

@@ -341,13 +341,17 @@ def save_api_cache!
341341

342342
users_data[key.to_s] = {
343343
"cached_at" => now,
344-
"value" => value.nil? ? nil : { "login" => value.respond_to?(:login) ? value.login : value.to_s },
344+
"value" => if value.nil?
345+
nil
346+
else
347+
{ "login" => value.respond_to?(:login) ? value.login : value.to_s }
348+
end,
345349
}
346350
end
347351

348352
File.write(CACHE_FILE, JSON.pretty_generate({ "repos" => repos_data, "users" => users_data }))
349-
rescue StandardError => e
350-
warn "Failed to save API cache: #{e.message}"
353+
rescue StandardError => error
354+
warn "Failed to save API cache: #{error.message}"
351355
end
352356

353357
# Load cached API results at startup

0 commit comments

Comments
 (0)