Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion common/lib/dependabot/file_fetchers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ def commit
def clone_repo_contents
@clone_repo_contents ||=
_clone_repo_contents(target_directory: repo_contents_path)
rescue Dependabot::SharedHelpers::HelperSubprocessFailed
rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e
if e.message.include?("fatal: Remote branch #{target_branch} not found in upstream origin")
raise Dependabot::BranchNotFound, target_branch
end

raise Dependabot::RepoNotFound, source
end

Expand Down
10 changes: 10 additions & 0 deletions common/spec/dependabot/file_fetchers/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,16 @@ def fetch_files
expect { subject }.to raise_error(Dependabot::RepoNotFound)
end
end

context "when the branch can't be found" do
let(:branch) do
"notfound"
end

it "raises a not found error" do
expect { subject }.to raise_error(Dependabot::BranchNotFound)
end
end
end
end
end
20 changes: 7 additions & 13 deletions updater/lib/dependabot/file_fetcher_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
module Dependabot
class FileFetcherJob < BaseJob
def perform_job
@base_commit_sha = nil

begin
connectivity_check if ENV["ENABLE_CONNECTIVITY_CHECK"] == "1"
clone_repo_contents
base_commit_sha
@base_commit_sha = file_fetcher.commit || "unknown"
dependency_files
rescue StandardError => e
@base_commit_sha ||= "unknown"
if Octokit::RATE_LIMITED_ERRORS.include?(e.class)
remaining = rate_limit_error_remaining(e)
logger_error("Repository is rate limited, attempting to retry in " \
Expand All @@ -22,14 +25,14 @@ def perform_job
logger_error("Error during file fetching; aborting")
end
handle_file_fetcher_error(e)
service.mark_job_as_processed(job_id, base_commit_sha)
service.mark_job_as_processed(job_id, @base_commit_sha)
clear_repo_contents_path
return
end

File.write(Environment.output_path, JSON.dump(
base64_dependency_files: base64_dependency_files.map(&:to_h),
base_commit_sha: base_commit_sha
base_commit_sha: @base_commit_sha
))

save_job_details
Expand All @@ -40,7 +43,7 @@ def save_job_details

File.write(Environment.job_path, JSON.dump(
base64_dependency_files: base64_dependency_files.map(&:to_h),
base_commit_sha: base_commit_sha,
base_commit_sha: @base_commit_sha,
job: job_definition["job"]
))
end
Expand Down Expand Up @@ -84,15 +87,6 @@ def job
@job ||= Job.new(attrs)
end

def base_commit_sha
@base_commit_sha ||= file_fetcher.commit || "unknown"
rescue StandardError
# If an error occurs, set the commit SHA instance variable (so that we
# don't raise when recording the error later) and re-raise
@base_commit_sha = "unknown"
raise
end

def file_fetcher
return @file_fetcher if defined? @file_fetcher

Expand Down
21 changes: 21 additions & 0 deletions updater/spec/dependabot/file_fetcher_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@
expect(Dir.exist?(Dependabot::Environment.repo_contents_path)).to be_truthy
expect(Dir.empty?(Dependabot::Environment.repo_contents_path)).to be_truthy
end

context "when the fetcher raises a BranchNotFound error while cloning" do
before do
allow_any_instance_of(Dependabot::GoModules::FileFetcher).
to receive(:clone_repo_contents).
and_raise(Dependabot::BranchNotFound, "my_branch")
end

it "tells the backend about the error (and doesn't re-raise it)" do
expect(api_client).
to receive(:record_update_job_error).
with(
job_id,
error_details: { "branch-name": "my_branch" },
error_type: "branch_not_found"
)
expect(api_client).to receive(:mark_job_as_processed)

expect { perform_job }.to output(/Error during file fetching; aborting/).to_stdout_from_any_process
end
end
end

context "when the connectivity check is enabled", vcr: true do
Expand Down