Skip to content

Commit

Permalink
Use table summary for large groups
Browse files Browse the repository at this point in the history
When five or more dependencies are being updated in a pull request, render the updates as a table for legibility.
  • Loading branch information
dependabot-ci committed Jun 21, 2023
1 parent fcceb9a commit 86b7340
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 4 deletions.
37 changes: 33 additions & 4 deletions common/lib/dependabot/pull_request_creator/message_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,19 @@ def transitive_removed_dependency_intro
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]}."
msg = "Bumps the #{dependency_group.name} group#{pr_name_directory} " \
"with #{update_count} update#{update_count > 1 ? 's' : ''}:"

msg += if update_count >= 5
header = ["Package", "Update"]
rows = dependencies.map { |dep| [dependency_link(dep), dependency_version_update(dep)] }
"\n\n#{table([header] + rows)}"
elsif update_count > 1
" #{dependency_links[0..-2].join(', ')} and #{dependency_links[-1]}."
else
": #{dependency_links.first}."
" #{dependency_links.first}."
end

msg += "\n"

msg
Expand Down Expand Up @@ -390,6 +397,10 @@ def dependency_link(dependency)
end
end

def dependency_version_update(dependency)
"#{dependency.humanized_previous_version} to #{dependency.humanized_version}"
end

def metadata_links
return metadata_links_for_dep(dependencies.first) if dependencies.count == 1

Expand All @@ -414,6 +425,24 @@ def metadata_links_for_dep(dep)
msg
end

def table(rows)
[
table_header(rows[0]),
rows[1..].map { |r| table_row(r) },
].join("\n")
end

def table_header(row)
[
table_row(row),
table_row(["---"] * row.count),
].join("\n")
end

def table_row(row)
"| #{row.join(' | ')} |"
end

def metadata_cascades
return metadata_cascades_for_dep(dependencies.first) if dependencies.one?

Expand Down
100 changes: 100 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 @@ -2078,6 +2078,106 @@ def commits_details(base:, head:)
end
end

context "with five or more 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(:dependency4) do
Dependabot::Dependency.new(
name: "business4",
version: "2.1.1",
previous_version: "2.1.0",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependency5) do
Dependabot::Dependency.new(
name: "business5",
version: "0.17.0",
previous_version: "0.16.2",
package_manager: "dummy",
requirements: [],
previous_requirements: []
)
end
let(:dependencies) { [dependency, dependency2, dependency3, dependency4, dependency5] }

before do
(2..5).each do |i|
repo_url = "https://api.github.com/repos/gocardless/business#{i}"

stub_request(:get, repo_url).
to_return(status: 200,
body: fixture("github", "business_repo.json"),
headers: json_header)
stub_request(:get, "#{repo_url}/contents/").
to_return(status: 200,
body: fixture("github", "business_files.json"),
headers: json_header)
stub_request(:get, "#{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/" \
"business#{i}/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/business#{i}.json").
to_return(
status: 200,
body: fixture("ruby", "rubygems_response_statesman.json")
)

service_pack_url =
"https://github.com/gocardless/business#{i}.git/info/refs" \
"?service=git-upload-pack"

stub_request(:get, service_pack_url).
to_return(
status: 200,
body: fixture("git", "upload_packs", "no_tags"),
headers: {
"content-type" => "application/x-git-upload-pack-advertisement"
}
)
end
end

it "has the correct message" do
expect(pr_message).to start_with(
"Bumps the all-the-things group with 5 updates:\n\n" \
"| Package | Update |\n" \
"| --- | --- |\n" \
"| [business](https://github.com/gocardless/business) | 1.4.0 to 1.5.0 |\n" \
"| [business2](https://github.com/gocardless/business2) | 1.7.0 to 1.8.0 |\n" \
"| [business3](https://github.com/gocardless/business3) | 1.4.0 to 1.5.0 |\n" \
"| [business4](https://github.com/gocardless/business4) | 2.1.0 to 2.1.1 |\n" \
"| [business5](https://github.com/gocardless/business5) | 0.16.2 to 0.17.0 |"
)
end
end


context "with a directory specified" do
let(:gemfile) do
Dependabot::DependencyFile.new(
Expand Down

0 comments on commit 86b7340

Please sign in to comment.