Class: Dependabot::GoModules::FileUpdater

Inherits:
FileUpdaters::Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/go_modules/file_updater.rb,
lib/dependabot/go_modules/file_updater/go_mod_updater.rb

Defined Under Namespace

Classes: GoModUpdater

Instance Method Summary collapse

Constructor Details

#initialize(dependencies:, dependency_files:, credentials:, repo_contents_path: nil, options: {}) ⇒ FileUpdater

Returns a new instance of FileUpdater.

Raises:

  • (ArgumentError)


32
33
34
35
36
# File 'lib/dependabot/go_modules/file_updater.rb', line 32

def initialize(dependencies:, dependency_files:, credentials:, repo_contents_path: nil, options: {})
  super

  raise ArgumentError, "repo_contents_path is required" if repo_contents_path.nil?
end

Instance Method Details

#updated_dependency_filesObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dependabot/go_modules/file_updater.rb', line 39

def updated_dependency_files
  updated_files = []

  if go_mod && dependency_changed?(T.must(go_mod))
    updated_files <<
      updated_file(
        file: T.must(go_mod),
        content: T.must(file_updater.updated_go_mod_content)
      )

    if go_sum && T.must(go_sum).content != file_updater.updated_go_sum_content
      updated_files <<
        updated_file(
          file: T.must(go_sum),
          content: T.must(file_updater.updated_go_sum_content)
        )
    end

    vendor_updater.updated_files(base_directory: T.must(directory))
                  .each do |file|
      updated_files << file
    end
  end

  raise "No files changed!" if updated_files.none?

  updated_files
end