Class: Dependabot::GoModules::FileUpdater::GoModUpdater
- Inherits:
-
Object
- Object
- Dependabot::GoModules::FileUpdater::GoModUpdater
- Defined in:
- lib/dependabot/go_modules/file_updater/go_mod_updater.rb
Instance Method Summary collapse
-
#initialize(dependencies:, go_mod:, go_sum:, credentials:) ⇒ GoModUpdater
constructor
A new instance of GoModUpdater.
- #updated_go_mod_content ⇒ Object
- #updated_go_sum_content ⇒ Object
Constructor Details
#initialize(dependencies:, go_mod:, go_sum:, credentials:) ⇒ GoModUpdater
Returns a new instance of GoModUpdater.
12 13 14 15 16 17 |
# File 'lib/dependabot/go_modules/file_updater/go_mod_updater.rb', line 12 def initialize(dependencies:, go_mod:, go_sum:, credentials:) @dependencies = dependencies @go_mod = go_mod @go_sum = go_sum @credentials = credentials end |
Instance Method Details
#updated_go_mod_content ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/dependabot/go_modules/file_updater/go_mod_updater.rb', line 19 def updated_go_mod_content @updated_go_mod_content ||= SharedHelpers.in_a_temporary_directory do SharedHelpers.with_git_configured(credentials: credentials) do File.write("go.mod", go_mod.content) deps = dependencies.map do |dep| { name: dep.name, version: "v" + dep.version.sub(/^v/i, ""), indirect: dep.requirements.empty? } end SharedHelpers.run_helper_subprocess( command: NativeHelpers.helper_path, env: { "GO111MODULE" => "on" }, function: "updateDependencyFile", args: { dependencies: deps } ) end end end |
#updated_go_sum_content ⇒ Object
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 70 71 72 73 |
# File 'lib/dependabot/go_modules/file_updater/go_mod_updater.rb', line 43 def updated_go_sum_content return nil unless go_sum # This needs to be run separately so we don't nest subprocess calls prepared_go_mod_content @updated_go_sum_content ||= SharedHelpers.in_a_temporary_directory do SharedHelpers.with_git_configured(credentials: credentials) do # Create a fake empty module for each local module so that # `go get -d` works, even if some modules have been `replace`d # with a local module that we don't have access to. local_replacements.each do |_, stub_path| Dir.mkdir(stub_path) unless Dir.exist?(stub_path) FileUtils.touch(File.join(stub_path, "go.mod")) end File.write("go.mod", prepared_go_mod_content) File.write("go.sum", go_sum.content) File.write("main.go", dummy_main_go) env = { "GO111MODULE" => "on" } _, stderr, status = Open3.capture3(env, "go get -d") unless status.success? handle_subprocess_error(go_sum.path, stderr) end File.read("go.sum") end end end |