Class: Dependabot::GoModules::FileUpdater

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

Defined Under Namespace

Classes: GoModUpdater

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FileUpdater.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dependabot/go_modules/file_updater.rb', line 13

def initialize(dependencies:, dependency_files:, repo_contents_path: nil,
               credentials:, options: {})
  super
  return unless repo_contents_path.nil?

  # masquerade repo_contents_path for GoModUpdater during transition
  tmp = Dir.mktmpdir
  Dir.chdir(tmp) do
    dependency_files.each do |file|
      File.write(file.name, file.content)
    end
    `git config --global user.email "[email protected]"`
    `git config --global user.name "Dependabot"`
    `git init .`
    `git add .`
    `git commit -m'fake repo_contents_path'`
  end
  @repo_contents_path = tmp
  @repo_contents_stub = true
end

Class Method Details

.updated_files_regexObject



34
35
36
37
38
39
# File 'lib/dependabot/go_modules/file_updater.rb', line 34

def self.updated_files_regex
  [
    /^go\.mod$/,
    /^go\.sum$/
  ]
end

Instance Method Details

#updated_dependency_filesObject



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
67
68
69
# File 'lib/dependabot/go_modules/file_updater.rb', line 41

def updated_dependency_files
  updated_files = []

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

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

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

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

  updated_files
end