Skip to content

Commit

Permalink
Merge pull request #7247 from dependabot/bdragon/3981-pr-intro
Browse files Browse the repository at this point in the history
Generate PR intro for grouped update PRs
  • Loading branch information
bdragon committed May 9, 2023
2 parents 4beb8d1 + e9bab4f commit 9ce7eb0
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ jobs:
matrix:
suite:
- { path: bundler, name: bundler, ecosystem: bundler }
- { path: bundler, name: bundler-group-rules, ecosystem: bundler }
# TODO(bdragon): re-enable once smoke test has been updated for new PR intro
# - { path: bundler, name: bundler-group-rules, ecosystem: bundler }
- { path: cargo, name: cargo, ecosystem: cargo }
- { path: composer, name: composer, ecosystem: composer }
- { path: docker, name: docker, ecosystem: docker }
Expand Down
39 changes: 30 additions & 9 deletions common/lib/dependabot/pull_request_creator/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ def requirement_commit_message_intro
msg + "to permit the latest version."
end

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/AbcSize
def version_commit_message_intro
return group_intro if dependency_group

return multidependency_property_intro if dependencies.count > 1 && updating_a_property?

return dependency_set_intro if dependencies.count > 1 && updating_a_dependency_set?
Expand All @@ -251,7 +254,7 @@ def version_commit_message_intro

msg
end

# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/AbcSize

Expand Down Expand Up @@ -309,6 +312,19 @@ def transitive_removed_dependency_intro
msg
end

def group_intro
update_count = dependencies.map(&:name).uniq.count

msg = "Bumps the #{dependency_group.name} group#{pr_name_directory} with #{update_count} update"
msg += if update_count > 1
"s: #{dependency_links[0..-2].join(', ')} and #{dependency_links[-1]}."
else
": #{dependency_links.first}."
end

msg
end

def from_version_msg(previous_version)
return "" unless previous_version

Expand Down Expand Up @@ -357,14 +373,19 @@ def dependency_set
end

def dependency_links
dependencies.map do |dependency|
if source_url(dependency)
"[#{dependency.display_name}](#{source_url(dependency)})"
elsif homepage_url(dependency)
"[#{dependency.display_name}](#{homepage_url(dependency)})"
else
dependency.display_name
end
return @dependency_links if defined?(@dependency_links)

uniq_deps = dependencies.each_with_object({}) { |dep, memo| memo[dep.name] ||= dep }.values
@dependency_links = uniq_deps.map { |dep| dependency_link(dep) }
end

def dependency_link(dependency)
if source_url(dependency)
"[#{dependency.display_name}](#{source_url(dependency)})"
elsif homepage_url(dependency)
"[#{dependency.display_name}](#{homepage_url(dependency)})"
else
dependency.display_name
end
end

Expand Down
221 changes: 221 additions & 0 deletions common/spec/dependabot/pull_request_creator/message_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,227 @@ def commits_details(base:, head:)
)
end
end

context "for a dependency group", :vcr do
let(:dependency_group) do
Dependabot::DependencyGroup.new(name: "all-the-things", rules: anything)
end

it "has the correct message" do
expect(pr_message).to start_with(
"Bumps the all-the-things group with 1 update: " \
"[business](https://github.com/gocardless/business)."
)
end

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

before do
business2_repo_url =
"https://api.github.com/repos/gocardless/business2"
stub_request(:get, business2_repo_url).
to_return(status: 200,
body: fixture("github", "business_repo.json"),
headers: json_header)
stub_request(:get, "#{business2_repo_url}/contents/").
to_return(status: 200,
body: fixture("github", "business_files.json"),
headers: json_header)
stub_request(:get, "#{business2_repo_url}/releases?per_page=100").
to_return(status: 200,
body: fixture("github", "business_releases.json"),
headers: json_header)
stub_request(:get, "https://api.github.com/repos/gocardless/" \
"business2/contents/CHANGELOG.md?ref=master").
to_return(status: 200,
body: fixture("github", "changelog_contents.json"),
headers: json_header)
stub_request(:get, "https://rubygems.org/api/v1/gems/business2.json").
to_return(
status: 200,
body: fixture("ruby", "rubygems_response_statesman.json")
)

business2_service_pack_url =
"https://github.com/gocardless/business2.git/info/refs" \
"?service=git-upload-pack"
stub_request(:get, business2_service_pack_url).
to_return(
status: 200,
body: fixture("git", "upload_packs", "no_tags"),
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}
)
end

it "has the correct message" do
expect(pr_message).to start_with(
"Bumps the all-the-things group with 2 updates: " \
"[business](https://github.com/gocardless/business) and " \
"[business2](https://github.com/gocardless/business2)."
)
end
end

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

it "has the correct message" do
expect(pr_message).to start_with(
"Bumps the all-the-things group with 1 update: " \
"[business](https://github.com/gocardless/business)."
)
end
end

context "with three dependencies", :vcr do
let(:dependency2) do
Dependabot::Dependency.new(
name: "business2",
version: "1.8.0",
previous_version: "1.7.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] }

before do
business2_repo_url =
"https://api.github.com/repos/gocardless/business2"
stub_request(:get, business2_repo_url).
to_return(status: 200,
body: fixture("github", "business_repo.json"),
headers: json_header)
stub_request(:get, "#{business2_repo_url}/contents/").
to_return(status: 200,
body: fixture("github", "business_files.json"),
headers: json_header)
stub_request(:get, "#{business2_repo_url}/releases?per_page=100").
to_return(status: 200,
body: fixture("github", "business_releases.json"),
headers: json_header)
stub_request(:get, "https://api.github.com/repos/gocardless/" \
"business2/contents/CHANGELOG.md?ref=master").
to_return(status: 200,
body: fixture("github", "changelog_contents.json"),
headers: json_header)
stub_request(:get, "https://rubygems.org/api/v1/gems/business2.json").
to_return(
status: 200,
body: fixture("ruby", "rubygems_response_statesman.json")
)

business2_service_pack_url =
"https://github.com/gocardless/business2.git/info/refs" \
"?service=git-upload-pack"
stub_request(:get, business2_service_pack_url).
to_return(
status: 200,
body: fixture("git", "upload_packs", "no_tags"),
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}
)

business3_repo_url =
"https://api.github.com/repos/gocardless/business3"
stub_request(:get, business3_repo_url).
to_return(status: 200,
body: fixture("github", "business_repo.json"),
headers: json_header)
stub_request(:get, "#{business3_repo_url}/contents/").
to_return(status: 200,
body: fixture("github", "business_files.json"),
headers: json_header)
stub_request(:get, "#{business3_repo_url}/releases?per_page=100").
to_return(status: 200,
body: fixture("github", "business_releases.json"),
headers: json_header)
stub_request(:get, "https://api.github.com/repos/gocardless/" \
"business3/contents/CHANGELOG.md?ref=master").
to_return(status: 200,
body: fixture("github", "changelog_contents.json"),
headers: json_header)
stub_request(:get, "https://rubygems.org/api/v1/gems/business3.json").
to_return(
status: 200,
body: fixture("ruby", "rubygems_response.json")
)

business3_service_pack_url =
"https://github.com/gocardless/business3.git/info/refs" \
"?service=git-upload-pack"
stub_request(:get, business3_service_pack_url).
to_return(
status: 200,
body: fixture("git", "upload_packs", "no_tags"),
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}
)
end

it "has the correct message" do
expect(pr_message).to start_with(
"Bumps the all-the-things group with 3 updates: " \
"[business](https://github.com/gocardless/business), " \
"[business2](https://github.com/gocardless/business2) and " \
"[business3](https://github.com/gocardless/business3)."
)
end
end

context "with a directory specified" do
let(:gemfile) do
Dependabot::DependencyFile.new(
name: "Gemfile",
content: fixture("ruby", "gemfiles", "Gemfile"),
directory: "directory"
)
end

it "includes the directory" do
expect(pr_message).to start_with(
"Bumps the all-the-things group in /directory with 1 update: " \
"[business](https://github.com/gocardless/business)."
)
end
end
end
end

context "for a library" do
Expand Down

0 comments on commit 9ce7eb0

Please sign in to comment.