Skip to content

Commit

Permalink
Merge pull request #5915 from dependabot/mctofu/dedupe-dep-names
Browse files Browse the repository at this point in the history
Don't repeat dependency names in PR title
  • Loading branch information
mctofu authored Oct 24, 2022
2 parents b49c206 + 126dd42 commit 6190c8a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 12 deletions.
18 changes: 14 additions & 4 deletions common/lib/dependabot/pull_request_creator/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,16 @@ def library_pr_name
"#{from_version_msg(old_library_requirement(dependencies.first))}" \
"to #{new_library_requirement(dependencies.first)}"
else
names = dependencies.map(&:name)
"requirements for #{names[0..-2].join(', ')} and #{names[-1]}"
names = dependencies.map(&:name).uniq
if names.count == 1
"requirements for #{names.first}"
else
"requirements for #{names[0..-2].join(', ')} and #{names[-1]}"
end
end
end

# rubocop:disable Metrics/AbcSize
def application_pr_name
pr_name = "bump "
pr_name = pr_name.capitalize if pr_name_prefixer.capitalize_first_word?
Expand All @@ -104,10 +109,15 @@ def application_pr_name
"#{from_version_msg(previous_version(dependency))}" \
"to #{new_version(dependency)}"
else
names = dependencies.map(&:name)
"#{names[0..-2].join(', ')} and #{names[-1]}"
names = dependencies.map(&:name).uniq
if names.count == 1
names.first
else
"#{names[0..-2].join(', ')} and #{names[-1]}"
end
end
end
# rubocop:enable Metrics/AbcSize

def pr_name_prefix
pr_name_prefixer.pr_name_prefix
Expand Down
108 changes: 100 additions & 8 deletions common/spec/dependabot/pull_request_creator/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,19 @@ def commits_details(base:, head:)
end

context "with two dependencies" do
let(:dependencies) { [dependency, dependency] }
it { is_expected.to eq("Bump business and business") }
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2] }

it { is_expected.to eq("Bump business and business2") }

context "for a Maven property update" do
let(:dependency) do
Expand Down Expand Up @@ -297,9 +308,45 @@ def commits_details(base:, head:)
end
end

context "with two dependencies with the same name" do
let(:dependency2) do
Dependabot::Dependency.new(
name: "business",
version: "2.3.0",
previous_version: "2.1.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2] }
it { is_expected.to eq("Bump business") }
end

context "with three dependencies" do
let(:dependencies) { [dependency, dependency, dependency] }
it { is_expected.to eq("Bump business, business and business") }
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency3) do
Dependabot::Dependency.new(
name: "business3",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2, dependency3] }

it { is_expected.to eq("Bump business, business2 and business3") }
end

context "with a directory specified" do
Expand Down Expand Up @@ -643,20 +690,65 @@ def commits_details(base:, head:)
end

context "with two dependencies" do
let(:dependencies) { [dependency, dependency] }
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2] }

it "includes both dependencies" do
expect(pr_name).
to eq("Update requirements for business and business")
to eq("Update requirements for business and business2")
end
end

context "with two dependencies with the same name" do
let(:dependency2) do
Dependabot::Dependency.new(
name: "business",
version: "2.3.0",
previous_version: "2.1.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2] }
it { is_expected.to eq("Update requirements for business") }
end

context "with three dependencies" do
let(:dependencies) { [dependency, dependency, dependency] }
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency3) do
Dependabot::Dependency.new(
name: "business3",
version: "1.5.0",
previous_version: "1.4.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2, dependency3] }

it "includes all three dependencies" do
expect(pr_name).
to eq("Update requirements for business, business and business")
to eq("Update requirements for business, business2 and business3")
end
end

Expand Down

0 comments on commit 6190c8a

Please sign in to comment.