Class: Dependabot::Bazel::UpdateChecker::RegistryClient
- Inherits:
-
Object
- Object
- Dependabot::Bazel::UpdateChecker::RegistryClient
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/bazel/update_checker/registry_client.rb
Constant Summary collapse
- GITHUB_REPO =
T.let("bazelbuild/bazel-central-registry", String)
- RAW_BASE =
T.let("https://raw.githubusercontent.com/#{GITHUB_REPO}/main".freeze, String)
Instance Method Summary collapse
- #all_module_versions(module_name) ⇒ Object
- #get_metadata(module_name) ⇒ Object
- #get_module_bazel(module_name, version) ⇒ Object
- #get_source(module_name, version) ⇒ Object
- #get_version_release_date(module_name, version) ⇒ Object
-
#initialize(credentials:) ⇒ RegistryClient
constructor
A new instance of RegistryClient.
- #latest_module_version(module_name) ⇒ Object
- #module_version_exists?(module_name, version) ⇒ Boolean
Constructor Details
#initialize(credentials:) ⇒ RegistryClient
Returns a new instance of RegistryClient.
23 24 25 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 23 def initialize(credentials:) @credentials = credentials end |
Instance Method Details
#all_module_versions(module_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 28 def all_module_versions(module_name) contents = T.unsafe(github_client).contents(GITHUB_REPO, path: "modules/#{module_name}") return [] unless contents.is_a?(Array) versions = contents.filter_map do |item| next unless item[:type] == "dir" item[:name] end versions.sort_by { |v| version_sort_key(v) } rescue Octokit::NotFound Dependabot.logger.info("Module '#{module_name}' not found in registry") [] end |
#get_metadata(module_name) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 53 def (module_name) versions = all_module_versions(module_name) return nil if versions.empty? { "name" => module_name, "versions" => versions, "latest_version" => latest_module_version(module_name) } end |
#get_module_bazel(module_name, version) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 81 def get_module_bazel(module_name, version) file_path = "modules/#{module_name}/#{version}/MODULE.bazel" begin content = T.unsafe(github_client).contents(GITHUB_REPO, path: file_path) return nil unless content Base64.decode64(content.content) rescue StandardError => e Dependabot.logger.warn("Failed to get MODULE.bazel for #{module_name}@#{version}: #{e.}") nil end end |
#get_source(module_name, version) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 65 def get_source(module_name, version) file_path = "modules/#{module_name}/#{version}/source.json" begin content = T.unsafe(github_client).contents(GITHUB_REPO, path: file_path) return nil unless content decoded_content = Base64.decode64(content.content) JSON.parse(decoded_content) rescue StandardError => e Dependabot.logger.warn("Failed to get source for #{module_name}@#{version}: #{e.}") nil end end |
#get_version_release_date(module_name, version) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 101 def get_version_release_date(module_name, version) file_path = "modules/#{module_name}/#{version}/MODULE.bazel" commits = begin T.unsafe(github_client).commits("bazelbuild/bazel-central-registry", path: file_path, per_page: 1) rescue StandardError => e Dependabot.logger.warn("Failed to get release date for #{module_name} #{version}: #{e.}") end return nil unless commits&.any? commits.first.commit.committer.date end |
#latest_module_version(module_name) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 45 def latest_module_version(module_name) versions = all_module_versions(module_name) return nil if versions.empty? versions.max_by { |v| version_sort_key(v) } end |
#module_version_exists?(module_name, version) ⇒ Boolean
96 97 98 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 96 def module_version_exists?(module_name, version) !get_source(module_name, version).nil? end |