From 4325ce3b72e11b54753444752df255a890a5e048 Mon Sep 17 00:00:00 2001 From: Justus Date: Thu, 30 Jan 2025 21:01:11 -0600 Subject: [PATCH] put behind feature flag --- .../refresh_group_update_pull_request.rb | 18 +++++++++++------- .../refresh_group_update_pull_request_spec.rb | 3 +++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/updater/lib/dependabot/updater/operations/refresh_group_update_pull_request.rb b/updater/lib/dependabot/updater/operations/refresh_group_update_pull_request.rb index 825363b080..f3282a7422 100644 --- a/updater/lib/dependabot/updater/operations/refresh_group_update_pull_request.rb +++ b/updater/lib/dependabot/updater/operations/refresh_group_update_pull_request.rb @@ -112,16 +112,20 @@ def process_group_dependencies(job_group) existing_pr_dependencies = {} + enable = Dependabot::Experiments.enabled?(:allow_refresh_for_existing_pr_dependencies) + # Preprocess to discover existing group PRs and add their dependencies to the handled list before processing # the refresh. This prevents multiple PRs from being created for the same dependency during the refresh. dependency_snapshot.groups.each do |group| - # Gather all dependencies in existing PRs so other groups will not consider them as handled when they - # are not also in the PR of the group being checked, preventing erroneous PR closures - group_pr_deps = dependency_snapshot.dependencies_in_existing_pr_for_group(group) - group_pr_deps.each do |dep| - dep_dir = dep["directory"] || "/" - existing_pr_dependencies[dep_dir] ||= Set.new - existing_pr_dependencies[dep_dir].add(dep["dependency-name"]) + if enable + # Gather all dependencies in existing PRs so other groups will not consider them as handled when they + # are not also in the PR of the group being checked, preventing erroneous PR closures + group_pr_deps = dependency_snapshot.dependencies_in_existing_pr_for_group(group) + group_pr_deps.each do |dep| + dep_dir = dep["directory"] || "/" + existing_pr_dependencies[dep_dir] ||= Set.new + existing_pr_dependencies[dep_dir].add(dep["dependency-name"]) + end end next unless group.name != job_group.name && pr_exists_for_dependency_group?(group) diff --git a/updater/spec/dependabot/updater/operations/refresh_group_update_pull_request_spec.rb b/updater/spec/dependabot/updater/operations/refresh_group_update_pull_request_spec.rb index 17e83fac4e..9e744b21b0 100644 --- a/updater/spec/dependabot/updater/operations/refresh_group_update_pull_request_spec.rb +++ b/updater/spec/dependabot/updater/operations/refresh_group_update_pull_request_spec.rb @@ -280,6 +280,9 @@ before do stub_rubygems_calls + allow(Dependabot::Experiments).to receive(:enabled?) + .with(:allow_refresh_for_existing_pr_dependencies) + .and_return(allow_refresh_for_existing_pr_dependencies) end it "updates the existing pull request without errors" do