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 =
"bazelbuild/bazel-central-registry"- 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.
24 25 26 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 24 def initialize(credentials:) @credentials = credentials end |
Instance Method Details
#all_module_versions(module_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 29 def all_module_versions(module_name) contents = 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
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 54 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
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 80 def get_module_bazel(module_name, version) file_path = "modules/#{module_name}/#{version}/MODULE.bazel" begin Base64.decode64(github_file_content(file_path)) 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
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 66 def get_source(module_name, version) file_path = "modules/#{module_name}/#{version}/source.json" begin content = github_file_content(file_path) decoded_content = Base64.decode64(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
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 97 def get_version_release_date(module_name, version) file_path = "modules/#{module_name}/#{version}/MODULE.bazel" commits = begin 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.}") nil end commit = commits&.first return nil unless commit commit_details = resource_field(commit, :commit, "commit details") committer = resource_field(commit_details, :committer, "committer") value = T.cast(committer[:date], Object) return value if value.is_a?(Time) return Time.parse(value) if value.is_a?(String) raise TypeError, "committer date must be a time or string" end |
#latest_module_version(module_name) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 46 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
92 93 94 |
# File 'lib/dependabot/bazel/update_checker/registry_client.rb', line 92 def module_version_exists?(module_name, version) !get_source(module_name, version).nil? end |