Skip to content

Commit

Permalink
set of names is simpler, performant
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Aug 21, 2023
1 parent 5a6c8c2 commit ee441e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions updater/lib/dependabot/dependency_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ def groups
@dependency_group_engine.dependency_groups
end

def calculate_ungrouped_dependencies(all_grouped_changes)
@ungrouped_dependencies = allowed_dependencies.select do |dep|
all_grouped_changes.none? { |change| change.name == dep.name }
end
def calculate_ungrouped_dependencies(dependencies_handled)
@ungrouped_dependencies = allowed_dependencies.reject { |dep| dependencies_handled.include?(dep.name) }
end

def ungrouped_dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def initialize(service:, job:, dependency_snapshot:, error_handler:)
@job = job
@dependency_snapshot = dependency_snapshot
@error_handler = error_handler
@all_grouped_changes = []
@dependencies_handled = Set.new
end

def perform
Expand Down Expand Up @@ -74,20 +74,20 @@ def run_grouped_dependency_updates
dependency_snapshot.groups.each do |group|
# If this group does not use update-types, then consider all dependencies as grouped.
# This will prevent any failures from creating individual PRs erroneously.
@all_grouped_changes += group.dependencies unless group.rules&.any? { |rule| rule["update-types"] }
@dependencies_handled += group.dependencies.map(&:name) unless group.rules&.key?("update-types")

if pr_exists_for_dependency_group?(group)
Dependabot.logger.info("Detected existing pull request for '#{group.name}'.")
Dependabot.logger.info(
"Deferring creation of a new pull request. The existing pull request will update in a separate job."
)
# add the dependencies in the group so individual updates don't try to update them
@all_grouped_changes += group.dependencies
@dependencies_handled += group.dependencies.map(&:name)
next
end

result = run_update_for(group)
@all_grouped_changes += result&.updated_dependencies || []
@dependencies_handled += result.updated_dependencies.map(&:name) if result
end
end

Expand All @@ -106,7 +106,7 @@ def run_update_for(group)
end

def run_ungrouped_dependency_updates
dependency_snapshot.calculate_ungrouped_dependencies(@all_grouped_changes)
dependency_snapshot.calculate_ungrouped_dependencies(@dependencies_handled)
return if dependency_snapshot.ungrouped_dependencies.empty?

Dependabot::Updater::Operations::UpdateAllVersions.new(
Expand Down

0 comments on commit ee441e4

Please sign in to comment.