Skip to content

Commit a799ef5

Browse files
committed
Add scanned_manifests_path metadata to snapshots
1 parent 066042f commit a799ef5

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

updater/lib/github_api/dependency_submission.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def payload
110110
manifests: manifests,
111111
metadata: {
112112
status: status.serialize,
113-
reason: reason
113+
reason: reason,
114+
scanned_manifest_paths: scanned_manifest_paths
114115
}.compact
115116
}
116117
end
@@ -179,5 +180,24 @@ def manifests
179180
}
180181
}
181182
end
183+
184+
# Returns the manifest paths this snapshot scanned.
185+
#
186+
# This allows the snapshot service to check the snapshot against those requested
187+
# even if the `manifests` property is empty.
188+
#
189+
# Note: We currently submit each manifest path separately, but we use an array
190+
# to align with the `manifests` property and allow flexibility in future.
191+
sig do
192+
returns(T::Array[T::Hash[Symbol, String]])
193+
end
194+
def scanned_manifest_paths
195+
[
196+
{
197+
ecosystem: GithubApi::EcosystemMapper.ecosystem_for(package_manager),
198+
manifest_path: File.dirname(manifest_file.path)
199+
}
200+
]
201+
end
182202
end
183203
end

updater/spec/dependabot/update_graph_processor_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@
388388
# It should contain the expected metadata
389389
expect(payload[:metadata][:status]).to eql(GithubApi::DependencySubmission::SnapshotStatus::FAILED.serialize)
390390
expect(payload[:metadata][:reason]).to eql("dependency_file_not_evaluatable")
391+
expect(payload[:metadata][:scanned_manifest_paths]).to eql([{ ecosystem: "rubygems", manifest_path: "/" }])
391392
end
392393

393394
it "correctly snapshots the second directory" do
@@ -418,6 +419,10 @@
418419
# We should have metadata indicating a successful snapshot
419420
expect(payload[:metadata][:status]).to eql(GithubApi::DependencySubmission::SnapshotStatus::SUCCESS.serialize)
420421
expect(payload[:metadata][:reason]).to be_nil
422+
expect(payload[:metadata][:scanned_manifest_paths]).to eql(
423+
[{ ecosystem: "rubygems",
424+
manifest_path: "/subproject" }]
425+
)
421426
end
422427
end
423428
end
@@ -557,6 +562,7 @@
557562
# It should contain the expected metadata
558563
expect(payload[:metadata][:status]).to eq(GithubApi::DependencySubmission::SnapshotStatus::SKIPPED.serialize)
559564
expect(payload[:metadata][:reason]).to eq(GithubApi::DependencySubmission::EMPTY_REASON_NO_MANIFESTS)
565+
expect(payload[:metadata][:scanned_manifest_paths]).to eql([{ ecosystem: "rubygems", manifest_path: "/" }])
560566
end
561567

562568
update_graph_processor.run
@@ -665,6 +671,7 @@ def fetch_subdependencies(_dependency)
665671
# We should have metadata indicating a successful snapshot
666672
expect(payload[:metadata][:status]).to eql(GithubApi::DependencySubmission::SnapshotStatus::DEGRADED.serialize)
667673
expect(payload[:metadata][:reason]).to eql(GithubApi::DependencySubmission::DEGRADED_REASON_SUBDEPENDENCY_ERR)
674+
expect(payload[:metadata][:scanned_manifest_paths]).to eql([{ ecosystem: "rubygems", manifest_path: "/" }])
668675
end
669676

670677
expect(service).to receive(:record_update_job_warning) do |args|

updater/spec/github_api/dependency_submission_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@
111111
expect(payload[:detector][:version]).to eq(Dependabot::VERSION)
112112
expect(payload[:job][:correlator]).to eq("dependabot-bundler")
113113
expect(payload[:job][:id]).to eq("9999")
114+
115+
# Check dependabot-specific metadata keys
116+
expect(payload[:metadata][:status]).to eql("ok")
117+
expect(payload[:metadata][:reason]).to be_nil
118+
expect(payload[:metadata][:scanned_manifest_paths]).to eql([{ ecosystem: "rubygems", manifest_path: "/" }])
114119
end
115120

116121
it "affixes to use the updater sha if available" do

0 commit comments

Comments
 (0)