Skip to content

Commit

Permalink
Slim down grouping code into a single iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
brrygrdn committed Jul 14, 2023
1 parent 96b1bf6 commit a60833a
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions updater/lib/dependabot/dependency_group_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def assign_to_groups!(dependencies:)

if dependency_groups.any?
dependencies.each do |dependency|
groups = groups_for(dependency)
matched_groups = @dependency_groups.each_with_object([]) do |group, matches|
next unless group.contains?(dependency)

@ungrouped_dependencies << dependency if groups.empty?

groups.each do |group|
group.dependencies.push(dependency)
matches << group
end

# If we had no matches, collect the dependency as ungrouped
@ungrouped_dependencies << dependency if matched_groups.empty?
end
else
@ungrouped_dependencies = dependencies
Expand All @@ -60,14 +62,5 @@ def initialize(dependency_groups:)
@ungrouped_dependencies = []
@groups_calculated = false
end

def groups_for(dependency)
return [] if dependency.nil?
return [] unless dependency.instance_of?(Dependabot::Dependency)

@dependency_groups.select do |group|
group.contains?(dependency)
end
end
end
end

0 comments on commit a60833a

Please sign in to comment.