Skip to content

A platform for community discussion. Free, open, simple.

DEV: Use GHSA IDs for stage_security_fixes rake task (#38987)

David Taylor878281a365c7
diff --git a/lib/tasks/release.rake b/lib/tasks/release.rake
index ef2db1b1f85..f123bbf83bb 100644
--- a/lib/tasks/release.rake
+++ b/lib/tasks/release.rake
@@ -206,16 +206,30 @@ namespace :release do
prs = JSON.parse(json_output)
raise "No open PRs found targeting #{base} on private-mirror" if prs.empty?
- choices = prs.map { |pr| pr.slice("number", "title", "body", "headRefName") }
+ extract_ghsa_id = ->(body) do
+ return nil if body.nil?
+ match = body.match(%r{github\.com/discourse/discourse/security/advisories/(GHSA-[\w-]+)})
+ match&.[](1)
+ end
+
+ choices =
+ prs.map do |pr|
+ pr.slice("number", "title", "body", "headRefName").merge(
+ "ghsa_id" => extract_ghsa_id.call(pr["body"]),
+ )
+ end
selected =
- if (pr_numbers = ENV["SECURITY_FIX_PR_NUMBERS"])
- requested = pr_numbers.split(",").map(&:to_i)
- choices.select { |pr| requested.include?(pr["number"]) }
+ if (ghsa_ids = ENV["SECURITY_FIX_GHSA_IDS"])
+ requested = ghsa_ids.split(",").map(&:strip)
+ choices.select { |pr| pr["ghsa_id"] && requested.include?(pr["ghsa_id"]) }
else
prompt = TTY::Prompt.new
prompt_choices =
- choices.map { |pr| { name: "##{pr["number"]}: #{pr["title"]}", value: pr } }
+ choices.map do |pr|
+ ghsa_label = pr["ghsa_id"] || "GHSA MISSING"
+ { name: "##{pr["number"]} [#{ghsa_label}]: #{pr["title"]}", value: pr }
+ end
prompt.multi_select(
"Select security fix PRs to include (space to toggle, enter to finish):",
prompt_choices,
diff --git a/spec/tasks/release_spec.rb b/spec/tasks/release_spec.rb
index 54afffcf286..8a739e94e8c 100644
--- a/spec/tasks/release_spec.rb
+++ b/spec/tasks/release_spec.rb
@@ -476,13 +476,15 @@ RSpec.describe "tasks/release" do
{
"number" => 1,
"title" => "Security fix one",
- "body" => "Description for fix one",
+ "body" =>
+ "Description for fix one\nhttps://github.com/discourse/discourse/security/advisories/GHSA-1111-2222-3333",
"headRefName" => "security-fix-one",
},
{
"number" => 2,
"title" => "Security fix two",
- "body" => "",
+ "body" =>
+ "https://github.com/discourse/discourse/security/advisories/GHSA-aaaa-bbbb-cccc",
"headRefName" => "security-fix-two",
},
].to_json
@@ -510,7 +512,7 @@ RSpec.describe "tasks/release" do
capture: true,
).and_return(pr_list_json)
- ENV["SECURITY_FIX_PR_NUMBERS"] = "1,2"
+ ENV["SECURITY_FIX_GHSA_IDS"] = "GHSA-1111-2222-3333,GHSA-aaaa-bbbb-cccc"
Dir.chdir(origin_path) do
git "checkout", "-b", "security-fix-one"
@@ -531,7 +533,7 @@ RSpec.describe "tasks/release" do
Dir.chdir(local_path) { git "remote", "add", "privatemirror", origin_path }
end
- after { ENV.delete("SECURITY_FIX_PR_NUMBERS") }
+ after { ENV.delete("SECURITY_FIX_GHSA_IDS") }
context "when accepting the version bump" do
before { run_task }
@@ -582,13 +584,16 @@ RSpec.describe "tasks/release" do
{
"number" => 1,
"title" => "Security fix for release branch",
- "body" => "",
+ "body" =>
+ "https://github.com/discourse/discourse/security/advisories/GHSA-release-test-1234",
"headRefName" => "security-fix-for-release-branch",
},
].to_json
end
before do
+ ENV["SECURITY_FIX_GHSA_IDS"] = "GHSA-release-test-1234"
+
Dir.chdir(origin_path) do
git "checkout", "-b", base_branch
File.write("lib/version.rb", fake_version_rb("2025.6.0"))