Class: Dependabot::GoModules::ReplaceStubber

Inherits:
Object
  • Object
show all
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.


14
15
16
# File 'lib/dependabot/go_modules/replace_stubber.rb', line 14

def initialize(repo_contents_path)
  @repo_contents_path = repo_contents_path
end

Instance Method Details

#stub_paths(manifest, directory) ⇒ Object


18
19
20
21
22
23
24
25
# File 'lib/dependabot/go_modules/replace_stubber.rb', line 18

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