Skip to content

Commit

Permalink
Remove double git configuration blocks
Browse files Browse the repository at this point in the history
This logic already run inside a `with_git_configured` block, so not
necessary to wrap it in another nested block.
  • Loading branch information
deivid-rodriguez committed Aug 23, 2023
1 parent 7def42f commit 02d75d6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def handle_subprocess_error(stderr) # rubocop:disable Metrics/AbcSize
repo_error_regex = REPO_RESOLVABILITY_ERROR_REGEXES.find { |r| stderr =~ r }
if repo_error_regex
error_message = filter_error_message(message: stderr, regex: repo_error_regex)
ResolvabilityErrors.handle(error_message, credentials: credentials, goprivate: @goprivate)
ResolvabilityErrors.handle(error_message, goprivate: @goprivate)
end

path_regex = MODULE_PATH_MISMATCH_REGEXES.find { |r| stderr =~ r }
Expand Down
26 changes: 12 additions & 14 deletions go_modules/lib/dependabot/go_modules/resolvability_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,27 @@ module GoModules
module ResolvabilityErrors
GITHUB_REPO_REGEX = %r{github.com/[^:@]*}

def self.handle(message, credentials:, goprivate:)
def self.handle(message, goprivate:)
mod_path = message.scan(GITHUB_REPO_REGEX).last
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")
File.write("go.mod", "module dummy\n")

mod_split = mod_path.split("/")
repo_path = if mod_split.size > 3
mod_split[0..2].join("/")
else
mod_path
end
mod_split = mod_path.split("/")
repo_path = if mod_split.size > 3
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?
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
raise Dependabot::GitDependenciesNotReachable, [repo_path]
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def fetch_available_versions

def handle_subprocess_error(error)
if RESOLVABILITY_ERROR_REGEXES.any? { |rgx| error.message =~ rgx }
ResolvabilityErrors.handle(error.message, credentials: credentials, goprivate: @goprivate)
ResolvabilityErrors.handle(error.message, goprivate: @goprivate)
elsif INVALID_VERSION_REGEX.match?(error.message)
raise Dependabot::DependencyFileNotResolvable, error.message
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,13 @@ def handle_pipenv_errors(error)
# errors when failing to update
def check_original_requirements_resolvable
SharedHelpers.in_a_temporary_directory do
SharedHelpers.with_git_configured(credentials: credentials) do
write_temporary_dependency_files(update_pipfile: false)
write_temporary_dependency_files(update_pipfile: false)

run_pipenv_command("pyenv exec pipenv lock")
run_pipenv_command("pyenv exec pipenv lock")

true
rescue SharedHelpers::HelperSubprocessFailed => e
handle_pipenv_errors_resolving_original_reqs(e)
end
true
rescue SharedHelpers::HelperSubprocessFailed => e
handle_pipenv_errors_resolving_original_reqs(e)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,18 @@ def check_original_requirements_resolvable
return @original_reqs_resolvable if @original_reqs_resolvable

SharedHelpers.in_a_temporary_directory do
SharedHelpers.with_git_configured(credentials: credentials) do
write_temporary_dependency_files(update_pyproject: false)
write_temporary_dependency_files(update_pyproject: false)

run_poetry_update_command
run_poetry_update_command

@original_reqs_resolvable = true
rescue SharedHelpers::HelperSubprocessFailed => e
raise unless e.message.include?("SolverProblemError") ||
e.message.include?("not found") ||
e.message.include?("version solving failed.")
@original_reqs_resolvable = true
rescue SharedHelpers::HelperSubprocessFailed => e
raise unless e.message.include?("SolverProblemError") ||
e.message.include?("not found") ||
e.message.include?("version solving failed.")

msg = clean_error_message(e.message)
raise DependencyFileNotResolvable, msg
end
msg = clean_error_message(e.message)
raise DependencyFileNotResolvable, msg
end
end

Expand Down

0 comments on commit 02d75d6

Please sign in to comment.