Skip to content

Commit 74b0614

Browse files
authored
Merge pull request #13447 from dependabot/brrygrdn/dg-8274-prefer-sha-if-known
[Graphs] Prefer to use a DEPENDABOT_UPDATER_SHA as the detector version, if set
2 parents 7261748 + f8c7ef7 commit 74b0614

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

updater/lib/dependabot/environment.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def self.github_actions?
5454
@github_actions ||= T.let(b, T.nilable(T::Boolean))
5555
end
5656

57+
sig { returns(T.nilable(String)) }
58+
def self.updater_sha
59+
@updater_sha ||= T.let(environment_variable("DEPENDABOT_UPDATER_SHA", nil), T.nilable(String))
60+
end
61+
5762
sig { returns(T::Boolean) }
5863
def self.deterministic_updates?
5964
b = T.cast(environment_variable("UPDATER_DETERMINISTIC", false), T::Boolean)

updater/lib/github_api/dependency_submission.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "dependabot/dependency_graphers"
5+
require "dependabot/environment"
56

67
# This class provides a data object that can be submitted to a repository's dependency submission
78
# REST API.
@@ -69,7 +70,7 @@ def payload
6970
},
7071
detector: {
7172
name: SNAPSHOT_DETECTOR_NAME,
72-
version: Dependabot::VERSION,
73+
version: detector_version,
7374
url: SNAPSHOT_DETECTOR_URL
7475
},
7576
manifests: manifests
@@ -99,6 +100,14 @@ def job_correlator
99100
sanitized_path.empty? ? base : "#{base}-#{sanitized_path}"
100101
end
101102

103+
sig { returns(String) }
104+
def detector_version
105+
[
106+
Dependabot::VERSION,
107+
Dependabot::Environment.updater_sha
108+
].compact.join("-")
109+
end
110+
102111
sig { returns(String) }
103112
def symbolic_ref
104113
return branch.gsub(%r{^/}, "") if branch.start_with?(%r{/?ref})

updater/spec/github_api/dependency_submission_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
expect(payload[:job][:id]).to eq("9999")
113113
end
114114

115+
it "affixes to use the updater sha if available" do
116+
allow(Dependabot::Environment).to receive(:updater_sha).and_return("totally-legit-sha")
117+
118+
payload = dependency_submission.payload
119+
120+
expect(payload[:detector][:version]).to eq("#{Dependabot::VERSION}-totally-legit-sha")
121+
end
122+
115123
it "generates git attributes correctly" do
116124
payload = dependency_submission.payload
117125

0 commit comments

Comments
 (0)