Class: Dependabot::Bazel::FileUpdater::LockfileUpdater

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/bazel/file_updater/lockfile_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependency_files:, dependencies:, credentials:) ⇒ LockfileUpdater

Returns a new instance of LockfileUpdater.



24
25
26
27
28
# File 'lib/dependabot/bazel/file_updater/lockfile_updater.rb', line 24

def initialize(dependency_files:, dependencies:, credentials:)
  @dependency_files = dependency_files
  @dependencies = dependencies
  @credentials = credentials
end

Instance Method Details

#determine_bazel_versionObject



53
54
55
56
57
58
59
# File 'lib/dependabot/bazel/file_updater/lockfile_updater.rb', line 53

def determine_bazel_version
  bazelversion_file = dependency_files.find { |f| f.name == ".bazelversion" }
  return Dependabot::Bazel::DEFAULT_BAZEL_VERSION unless bazelversion_file

  version = T.must(bazelversion_file.content).strip
  version.empty? ? Dependabot::Bazel::DEFAULT_BAZEL_VERSION : version
end

#updated_lockfileObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dependabot/bazel/file_updater/lockfile_updater.rb', line 31

def updated_lockfile
  return nil unless needs_lockfile_update?

  existing_lockfile = lockfile
  updated_content = generate_lockfile_content

  if existing_lockfile
    return nil if existing_lockfile.content == updated_content

    existing_lockfile.dup.tap { |f| f.content = updated_content }
  else
    Dependabot::DependencyFile.new(
      name: "MODULE.bazel.lock",
      content: updated_content,
      directory: module_file.directory
    )
  end
rescue SharedHelpers::HelperSubprocessFailed => e
  handle_bazel_error_for_lockfile(e)
end