From ae54458d5e371ffc9a3c5a187271c095b05c1b52 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Tue, 23 May 2023 18:32:06 +0100 Subject: [PATCH] Dependency order isn't a factor --- .../branch_namer/dependency_group_strategy.rb | 2 +- .../dependency_group_strategy_spec.rb | 32 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/common/lib/dependabot/pull_request_creator/branch_namer/dependency_group_strategy.rb b/common/lib/dependabot/pull_request_creator/branch_namer/dependency_group_strategy.rb index 88d6affdb7b..67e59cd0ee9 100644 --- a/common/lib/dependabot/pull_request_creator/branch_namer/dependency_group_strategy.rb +++ b/common/lib/dependabot/pull_request_creator/branch_namer/dependency_group_strategy.rb @@ -50,7 +50,7 @@ def group_name_with_dependency_digest def dependency_digest @dependency_digest ||= Digest::MD5.hexdigest(dependencies.map do |dependency| "#{dependency.name}-#{dependency.removed? ? 'removed' : dependency.version}" - end.join(",")).slice(0, 10) + end.sort.join(",")).slice(0, 10) end def package_manager diff --git a/common/spec/dependabot/pull_request_creator/branch_namer/dependency_group_strategy_spec.rb b/common/spec/dependabot/pull_request_creator/branch_namer/dependency_group_strategy_spec.rb index 35c96963f99..43b62c410b3 100644 --- a/common/spec/dependabot/pull_request_creator/branch_namer/dependency_group_strategy_spec.rb +++ b/common/spec/dependabot/pull_request_creator/branch_namer/dependency_group_strategy_spec.rb @@ -64,7 +64,7 @@ expect(new_namer.new_branch_name).to eql(branch_name) end - it "generates a different branch name for a diffset set of dependencies for the same group" do + it "generates a different branch name for a different set of dependencies for the same group" do removed_dependency = Dependabot::Dependency.new( name: "old_business", version: "1.4.0", @@ -84,6 +84,36 @@ ) expect(new_namer.new_branch_name).not_to eql(namer.new_branch_name) end + + it "generates the same branch name regardless of the order of dependencies" do + removed_dependency = Dependabot::Dependency.new( + name: "old_business", + version: "1.4.0", + previous_version: "1.4.0", + package_manager: "bundler", + requirements: {}, + previous_requirements: {}, + removed: true + ) + + forward_namer = described_class.new( + dependencies: [dependency, removed_dependency], + files: [gemfile], + target_branch: target_branch, + separator: separator, + dependency_group: dependency_group + ) + + backward_namer = described_class.new( + dependencies: [removed_dependency, dependency], + files: [gemfile], + target_branch: target_branch, + separator: separator, + dependency_group: dependency_group + ) + + expect(forward_namer.new_branch_name).to eql(backward_namer.new_branch_name) + end end context "with a custom separator" do