-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2949 from dependabot/go-raise-git-unreachable
go_modules raise GitDependenciesNotReachable
- Loading branch information
Showing
4 changed files
with
61 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
go_modules/lib/dependabot/go_modules/resolvability_errors.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Dependabot | ||
module GoModules | ||
module ResolvabilityErrors | ||
GITHUB_REPO_REGEX = %r{github.com/[^:@]*}.freeze | ||
|
||
def self.handle(message, credentials:) | ||
mod_path = message.scan(GITHUB_REPO_REGEX).first | ||
raise Dependabot::DependencyFileNotResolvable, message unless mod_path | ||
|
||
# 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 | ||
SharedHelpers.with_git_configured(credentials: credentials) do | ||
File.write("go.mod", "module dummy\n") | ||
|
||
env = { "GOPRIVATE" => "*" } | ||
_, _, status = Open3.capture3(env, SharedHelpers.escape_command("go get #{mod_path}")) | ||
raise Dependabot::DependencyFileNotResolvable, message if status.success? | ||
|
||
mod_split = mod_path.split("/") | ||
repo_path = if mod_split.size > 3 | ||
mod_split[0..2].join("/") | ||
else | ||
mod_path | ||
end | ||
raise Dependabot::GitDependenciesNotReachable, [repo_path] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters