Skip to content

Commit 766574c

Browse files
authored
refactor: remove redundant comments, add dedup guard and missing test assertion
1 parent 70452de commit 766574c

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

updater/lib/dependabot/dependency_group_engine.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ def matches_group_by_parent_group?(dependency)
153153
def initialize(dependency_groups:)
154154
@dependency_groups = dependency_groups
155155
@ungrouped_dependencies = T.let([], T::Array[Dependabot::Dependency])
156-
# Track the names of originally-configured group-by-dependency-name parent groups
157-
# so that subgroups created from them are not treated as parents on subsequent calls.
158156
@group_by_name_parent_names = T.let(
159157
dependency_groups.select(&:group_by_dependency_name?).to_set(&:name),
160158
T::Set[String]
@@ -218,8 +216,6 @@ def should_skip_due_to_specificity?(group, dependency, specificity_calculator)
218216

219217
sig { params(dependencies: T::Array[Dependabot::Dependency]).void }
220218
def create_dynamic_subgroups_for_dependency_name_groups(dependencies)
221-
# Only select originally-configured parent groups, not subgroups created by previous calls.
222-
# This prevents infinite recursion when assign_to_groups! is called once per directory.
223219
parent_groups = @dependency_groups.select { |g| @group_by_name_parent_names.include?(g.name) }
224220

225221
parent_groups.each do |parent_group|
@@ -230,10 +226,9 @@ def create_dynamic_subgroups_for_dependency_name_groups(dependencies)
230226
existing_subgroup = @dependency_groups.find { |g| g.name == subgroup_name }
231227

232228
if existing_subgroup
233-
existing_subgroup.dependencies.concat(deps)
229+
new_deps = deps.reject { |d| existing_subgroup.dependencies.include?(d) }
230+
existing_subgroup.dependencies.concat(new_deps)
234231
else
235-
# Preserve "group-by" in subgroup rules so group_by_dependency_name? returns true,
236-
# enabling correct handled-dependency tracking when semver rules reject an update.
237232
subgroup_rules = parent_group.rules.merge("patterns" => [dep_name])
238233
subgroup = Dependabot::DependencyGroup.new(
239234
name: subgroup_name,

updater/lib/dependabot/updater/group_update_creation.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,6 @@ def compile_updates_for(dependency, dependency_files, group) # rubocop:disable M
348348
[] # return an empty set
349349
end
350350

351-
# When grouping by dependency name, mark the dependency as handled to prevent
352-
# per-directory individual PRs from being raised.
353351
sig { params(dependency: Dependabot::Dependency, group: Dependabot::DependencyGroup, reason: String).void }
354352
def mark_handled_for_group_by_name(dependency, group, reason)
355353
return unless group.group_by_dependency_name?

updater/spec/dependabot/dependency_group_engine_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,10 +890,22 @@
890890
end
891891

892892
it "does not treat subgroups as parents on subsequent calls despite having group_by set" do
893-
# Subgroups now retain group-by in their rules, so we need to verify
894-
# the recursion guard prevents them from spawning sub-subgroups.
895-
# Simulate a second directory by calling assign_to_groups! again.
896-
dependency_group_engine.assign_to_groups!(dependencies: [dummy_pkg_a_dir2])
893+
# Simulate a third directory by calling assign_to_groups! again with a new dep.
894+
dummy_pkg_a_dir3 = Dependabot::Dependency.new(
895+
name: "dummy-pkg-a",
896+
package_manager: "bundler",
897+
version: "1.1.0",
898+
requirements: [
899+
{
900+
file: "Gemfile",
901+
requirement: "~> 1.1.0",
902+
groups: ["default"],
903+
source: nil
904+
}
905+
],
906+
directory: "/dir3"
907+
)
908+
dependency_group_engine.assign_to_groups!(dependencies: [dummy_pkg_a_dir3])
897909

898910
# Should reuse the existing subgroup rather than creating a duplicate
899911
subgroups_a = dependency_group_engine.dependency_groups.select do |g|

updater/spec/dependabot/updater/group_update_creation_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def initialize(dependency_snapshot, error_handler, job, group, service)
443443
end
444444
end
445445

446-
describe "compile_updates_for marks handled deps for group-by-name groups" do
446+
describe "#compile_updates_for group-by-name handled deps" do
447447
let(:dependency) { dependencies.first }
448448

449449
before do
@@ -564,6 +564,11 @@ def initialize(dependency_snapshot, error_handler, job, group, service)
564564
test_instance.compile_updates_for(dependency, dependency_files, group)
565565
expect(dependency_snapshot).not_to have_received(:add_handled_dependencies)
566566
end
567+
568+
it "returns an empty array" do
569+
result = test_instance.compile_updates_for(dependency, dependency_files, group)
570+
expect(result).to eq([])
571+
end
567572
end
568573
end
569574

0 commit comments

Comments
 (0)