Skip to content

Commit e76a464

Browse files
authored
fix missing base_commit_sha in mark_as_processed during exceptional behavior (#13300)
1 parent 5c0bdca commit e76a464

File tree

7 files changed

+31
-274
lines changed

7 files changed

+31
-274
lines changed

updater/lib/dependabot/update_files_command.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def perform_job
3939
handle_parser_error(e)
4040
# If dependency file parsing has failed, there's nothing more we can do,
4141
# so let's mark the job as processed and stop.
42-
return service.mark_job_as_processed(Environment.job_definition["base_commit_sha"])
42+
return service.mark_job_as_processed(base_commit_sha)
4343
end
4444

4545
# Update the service's metadata about this project
@@ -50,14 +50,10 @@ def perform_job
5050
# As above, we can remove the responsibility for handling fatal/job halting
5151
# errors from Dependabot::Updater entirely.
5252
begin
53-
Dependabot::Updater.new(
54-
service: service,
55-
job: job,
56-
dependency_snapshot: dependency_snapshot
57-
).run
53+
Dependabot::Updater.new(service:, job:, dependency_snapshot:).run
5854
rescue Dependabot::DependencyFileNotParseable => e
5955
handle_dependency_file_not_parseable_error(e)
60-
return service.mark_job_as_processed(Environment.job_definition["base_commit_sha"])
56+
return service.mark_job_as_processed(base_commit_sha)
6157
end
6258

6359
# Wait for all PRs to be created
@@ -66,7 +62,7 @@ def perform_job
6662
# Finally, mark the job as processed. The Dependabot::Updater may have
6763
# reported errors to the service, but we always consider the job as
6864
# successfully processed unless it actually raises.
69-
service.mark_job_as_processed(dependency_snapshot.base_commit_sha)
65+
service.mark_job_as_processed(base_commit_sha)
7066
end
7167
end
7268

@@ -84,7 +80,7 @@ def job
8480

8581
sig { override.returns(T.nilable(String)) }
8682
def base_commit_sha
87-
Environment.job_definition["base_commit_sha"]
83+
@fetched_files.base_commit_sha
8884
end
8985

9086
private

updater/spec/dependabot/update_files_command_spec.rb

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222
)
2323
end
2424
let(:job_definition) do
25-
JSON.parse(fixture("file_fetcher_output/output.json"))
25+
JSON.parse(fixture("jobs/job_without_credentials.json"))
26+
end
27+
let(:manifest) do
28+
Dependabot::DependencyFile.new(
29+
name: "Gemfile",
30+
content: fixture("bundler/original/Gemfile"),
31+
directory: "/"
32+
)
2633
end
2734
let(:fetched_files) do
2835
# We no longer write encoded files to disk, need to migrate the fixtures in this test
2936
Dependabot::FetchedFiles.new(
30-
dependency_files: job_definition["base64_dependency_files"].map do |file|
31-
Dependabot::DependencyFile.new(
32-
name: file["name"],
33-
content: Base64.decode64(file["content"]),
34-
directory: file["directory"] || "/"
35-
)
36-
end,
37-
base_commit_sha: job_definition["base_commit_sha"]
37+
dependency_files: [manifest],
38+
base_commit_sha: "1c6331732c41e4557a16dacb82534f1d1c831848"
3839
)
3940
end
4041
let(:job_id) { "123123" }
@@ -66,53 +67,11 @@
6667
expect(dummy_runner).to receive(:run)
6768
expect(service).to receive(:mark_job_as_processed)
6869
.with(base_commit_sha)
69-
70-
perform_job
71-
end
72-
73-
it "sends dependency metadata to the service" do
7470
expect(service).to receive(:update_dependency_list)
7571
.with(dependency_snapshot: an_instance_of(Dependabot::DependencySnapshot))
7672

7773
perform_job
7874
end
79-
80-
context "with vendoring_dependencies" do
81-
let(:snapshot) do
82-
instance_double(
83-
Dependabot::DependencySnapshot,
84-
base_commit_sha: "1c6331732c41e4557a16dacb82534f1d1c831848"
85-
)
86-
end
87-
let(:repo_contents_path) { "repo/path" }
88-
89-
let(:job_definition) do
90-
JSON.parse(fixture("file_fetcher_output/vendoring_output.json"))
91-
end
92-
93-
before do
94-
allow(Dependabot::Environment).to receive(:repo_contents_path).and_return(repo_contents_path)
95-
allow(Dependabot::DependencySnapshot).to receive(:create_from_job_definition).and_return(snapshot)
96-
end
97-
98-
it "delegates to Dependabot::Updater" do
99-
dummy_runner = double(run: nil)
100-
base_commit_sha = "1c6331732c41e4557a16dacb82534f1d1c831848"
101-
expect(Dependabot::Updater)
102-
.to receive(:new)
103-
.with(
104-
service: service,
105-
job: an_object_having_attributes(id: job_id, repo_contents_path: repo_contents_path),
106-
dependency_snapshot: snapshot
107-
)
108-
.and_return(dummy_runner)
109-
expect(dummy_runner).to receive(:run)
110-
expect(service).to receive(:mark_job_as_processed)
111-
.with(base_commit_sha)
112-
113-
perform_job
114-
end
115-
end
11675
end
11776

11877
describe "#perform_job when there is an error parsing the dependency files" do

updater/spec/dependabot/update_graph_command_spec.rb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222
)
2323
end
2424
let(:job_definition) do
25-
JSON.parse(fixture("file_fetcher_output/output-directories-only.json"))
25+
JSON.parse(fixture("jobs/bundler_directories.json"))
26+
end
27+
let(:manifest) do
28+
Dependabot::DependencyFile.new(
29+
name: "Gemfile",
30+
content: fixture("bundler/original/Gemfile"),
31+
directory: "/"
32+
)
2633
end
2734
let(:fetched_files) do
2835
# We no longer write encoded files to disk, need to migrate the fixtures in this test
2936
Dependabot::FetchedFiles.new(
30-
dependency_files: job_definition["base64_dependency_files"].map do |file|
31-
Dependabot::DependencyFile.new(
32-
name: file["name"],
33-
content: Base64.decode64(file["content"]),
34-
directory: file["directory"] || "/"
35-
)
36-
end,
37-
base_commit_sha: job_definition["base_commit_sha"]
37+
dependency_files: [manifest],
38+
base_commit_sha: "1c6331732c41e4557a16dacb82534f1d1c831848"
3839
)
3940
end
4041
let(:job_id) { "123123" }
@@ -67,8 +68,11 @@
6768
describe "#perform_job when the directory is empty or doesn't exist" do
6869
subject(:perform_job) { job.perform_job }
6970

70-
let(:job_definition) do
71-
JSON.parse(fixture("file_fetcher_output/output-empty-directory.json"))
71+
let(:fetched_files) do
72+
Dependabot::FetchedFiles.new(
73+
dependency_files: [],
74+
base_commit_sha: "1c6331732c41e4557a16dacb82534f1d1c831848"
75+
)
7276
end
7377

7478
before do
@@ -78,7 +82,7 @@
7882

7983
it "emits a create_dependency_submission call to the Dependabot service with an empty snapshot" do
8084
expect(service).to receive(:create_dependency_submission) do |args|
81-
expected_manifest_file = Dependabot::DependencyFile.new(name: "", content: "", directory: "/foo")
85+
expected_manifest_file = Dependabot::DependencyFile.new(name: "", content: "", directory: "/")
8286

8387
expect(args[:dependency_submission]).to be_a(GithubApi::DependencySubmission)
8488

updater/spec/fixtures/file_fetcher_output/output-empty-directory.json

Lines changed: 0 additions & 62 deletions
This file was deleted.

updater/spec/fixtures/file_fetcher_output/output.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

updater/spec/fixtures/file_fetcher_output/vendoring_output.json

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)