Class: Dependabot::GoModules::ReplaceStubber

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/go_modules/replace_stubber.rb

Overview

Given a go.mod file, find all ‘replace` directives pointing to a path on the local filesystem outside of the current checkout, and return a hash mapping the original path to a hash of the path.

This lets us substitute all parts of the go.mod that are dependent on the layout of the filesystem with a structure we can reproduce (i.e. no paths such as ../../../foo), run the Go tooling, then reverse the process afterwards.

Instance Method Summary collapse

Constructor Details

#initialize(repo_contents_path) ⇒ ReplaceStubber

Returns a new instance of ReplaceStubber.



20
21
22
# File 'lib/dependabot/go_modules/replace_stubber.rb', line 20

def initialize(repo_contents_path)
  @repo_contents_path = repo_contents_path
end

Instance Method Details

#stub_paths(manifest, directory) ⇒ Object



27
28
29
30
31
32
# File 'lib/dependabot/go_modules/replace_stubber.rb', line 27

def stub_paths(manifest, directory)
  (manifest["Replace"] || [])
    .filter_map { |r| r["New"]["Path"] }
    .select { |p| stub_replace_path?(p, directory) }
    .to_h { |p| [p, "./" + Digest::SHA2.hexdigest(p)] }
end