diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2f8d4e69e38..4db67290b88 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,6 +14,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6.0.1 + with: + ref: ${{ github.event.pull_request.head.ref || github.ref }} - name: Setup Ruby uses: ruby/setup-ruby@v1.284.0 diff --git a/test/test_helper.rb b/test/test_helper.rb index 53b2984e6f7..3de10234929 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -273,6 +273,7 @@ def add_message(type, file, line_number, message) CACHE_FILE = File.expand_path("../.api-cache.json", __dir__) CACHE_TTL_SECONDS = 24 * 60 * 60 # 24 hours +# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity def load_api_cache! return unless File.exist?(CACHE_FILE) @@ -280,46 +281,44 @@ def load_api_cache! now = Time.now.to_i ttl = CACHE_TTL_SECONDS - if data["repos"] - data["repos"].each do |key, entry| - cached_at = entry["cached_at"] - next unless cached_at - next if now - cached_at.to_i > ttl - - result = entry["value"] - # Reconstruct a minimal object that responds to .full_name - cached = if result.nil? - nil - else - next unless result["full_name"] - - Struct.new(:full_name).new(result["full_name"]) - end - NewOctokit.class_variable_get(:@@repos)[key] = cached - end + data["repos"]&.each do |key, entry| + cached_at = entry["cached_at"] + next unless cached_at + next if now - cached_at.to_i > ttl + + result = entry["value"] + # Reconstruct a minimal object that responds to .full_name + cached = if result.nil? + nil + else + next unless result["full_name"] + + Struct.new(:full_name).new(result["full_name"]) + end + NewOctokit.class_variable_get(:@@repos)[key] = cached end - if data["users"] - data["users"].each do |key, entry| - cached_at = entry["cached_at"] - next unless cached_at - next if now - cached_at.to_i > ttl - - result = entry["value"] - cached = if result.nil? - nil - else - next unless result["login"] - - Struct.new(:login).new(result["login"]) - end - NewOctokit.class_variable_get(:@@users)[key] = cached - end + data["users"]&.each do |key, entry| + cached_at = entry["cached_at"] + next unless cached_at + next if now - cached_at.to_i > ttl + + result = entry["value"] + cached = if result.nil? + nil + else + next unless result["login"] + + Struct.new(:login).new(result["login"]) + end + NewOctokit.class_variable_get(:@@users)[key] = cached end -rescue JSON::ParserError, StandardError => e - warn "Failed to load API cache: #{e.message}" +rescue StandardError => error + warn "Failed to load API cache: #{error.message}" end +# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity +# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity def save_api_cache! now = Time.now.to_i repos_data = {} @@ -331,7 +330,11 @@ def save_api_cache! repos_data[key.to_s] = { "cached_at" => now, - "value" => value.nil? ? nil : { "full_name" => value.respond_to?(:full_name) ? value.full_name : value.to_s }, + "value" => if value.nil? + nil + else + { "full_name" => value.respond_to?(:full_name) ? value.full_name : value.to_s } + end, } end @@ -341,14 +344,19 @@ def save_api_cache! users_data[key.to_s] = { "cached_at" => now, - "value" => value.nil? ? nil : { "login" => value.respond_to?(:login) ? value.login : value.to_s }, + "value" => if value.nil? + nil + else + { "login" => value.respond_to?(:login) ? value.login : value.to_s } + end, } end File.write(CACHE_FILE, JSON.pretty_generate({ "repos" => repos_data, "users" => users_data })) -rescue StandardError => e - warn "Failed to save API cache: #{e.message}" +rescue StandardError => error + warn "Failed to save API cache: #{error.message}" end +# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity # Load cached API results at startup load_api_cache!