Module: Dependabot::GoModules::ResolvabilityErrors

Extended by:
T::Sig
Defined in:
lib/dependabot/go_modules/resolvability_errors.rb

Constant Summary collapse

GITHUB_REPO_REGEX =
%r{github.com/[^:@]*}

Class Method Summary collapse

Class Method Details

.handle(message, goprivate:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dependabot/go_modules/resolvability_errors.rb', line 14

def self.handle(message, goprivate:)
  mod_path = message.scan(GITHUB_REPO_REGEX).last
  unless mod_path && message.include?("If this is a private repository")
    raise Dependabot::DependencyFileNotResolvable, message
  end

  # Module not found on github.com - query for _any_ version to know if it
  # doesn't exist (or is private) or we were just given a bad revision by this manifest
  SharedHelpers.in_a_temporary_directory do
    File.write("go.mod", "module dummy\n")

    mod_path = T.cast(mod_path, String)
    mod_split = mod_path.split("/")
    repo_path = if mod_split.size > 3
                  T.must(mod_split[0..2]).join("/")
                else
                  mod_path
                end

    env = { "GOPRIVATE" => goprivate }
    _, _, status = Open3.capture3(env, SharedHelpers.escape_command("go list -m -versions #{repo_path}"))
    raise Dependabot::DependencyFileNotResolvable, message if status.success?

    raise Dependabot::GitDependenciesNotReachable, [repo_path]
  end
end