Skip to content

Commit

Permalink
Merge pull request dependabot#7166 from dependabot/nishnha/pass-depen…
Browse files Browse the repository at this point in the history
…dency-group-id-to-api

Pass the serialized group name when creating a PR for grouped updates
  • Loading branch information
brrygrdn authored Apr 26, 2023
2 parents f2e91ac + 6b45283 commit 4751e24
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 4 additions & 0 deletions common/lib/dependabot/dependency_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ def contains?(dependency)
@dependencies.include?(dependency) if @dependencies.any?
rules.any? { |rule| WildcardMatcher.match?(rule, dependency.name) }
end

def to_h
{ "name" => name }
end
end
end
22 changes: 11 additions & 11 deletions updater/lib/dependabot/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ def http_client
client
end

def dependency_group_hash(dependency_change)
return {} unless dependency_change.grouped_update?

# FIXME: We currently assumpt that _an attempt_ to send a DependencyGroup#id should
# result in the `grouped-update` flag being set, regardless of whether the
# DependencyGroup actually exists.
{ "dependency-group": dependency_change.dependency_group.to_h }.compact
end

def create_pull_request_data(dependency_change, base_commit_sha)
data = {
dependencies: dependency_change.updated_dependencies.map do |dep|
Expand All @@ -181,17 +190,8 @@ def create_pull_request_data(dependency_change, base_commit_sha)
end,
"updated-dependency-files": dependency_change.updated_dependency_files_hash,
"base-commit-sha": base_commit_sha
}.merge({
# TODO: Replace this flag with a dependency-group object
#
# In future this should be something like:
# "dependency-group": dependency_change.dependency_group_hash
#
# This will allow us to pass back the rule id and other parameters
# to allow Dependabot API to augment PR creation and associate it
# with the rule for rebasing, etc.
"grouped-update": dependency_change.grouped_update? ? true : nil
}.compact)
}.merge(dependency_group_hash(dependency_change))

return data unless dependency_change.pr_message

data["commit-message"] = dependency_change.pr_message.commit_message
Expand Down
12 changes: 7 additions & 5 deletions updater/spec/dependabot/api_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,24 @@
end

context "grouped updates" do
it "does not include the grouped_update key by default" do
it "does not include the dependency-group key by default" do
client.create_pull_request(dependency_change, base_commit)

expect(WebMock).
to(have_requested(:post, create_pull_request_url).
with do |req|
expect(req.body).not_to include("grouped-update")
expect(req.body).not_to include("dependency-group")
end)
end

it "flags the PR as a grouped-update if the dependency change has a dependency group assigned" do
it "flags the PR as having dependency-groups if the dependency change has a dependency group assigned" do
group = Dependabot::DependencyGroup.new(name: "dummy-group-name", rules: ["*"])

grouped_dependency_change = Dependabot::DependencyChange.new(
job: job,
updated_dependencies: dependencies,
updated_dependency_files: dependency_files,
dependency_group: anything
dependency_group: group
)

client.create_pull_request(grouped_dependency_change, base_commit)
Expand All @@ -199,7 +201,7 @@
to(have_requested(:post, create_pull_request_url).
with do |req|
data = JSON.parse(req.body)["data"]
expect(data["grouped-update"]).to be true
expect(data["dependency-group"]).to eq({ "name" => "dummy-group-name" })
end)
end
end
Expand Down

0 comments on commit 4751e24

Please sign in to comment.