Skip to content

Commit

Permalink
Merge pull request #7137 from dependabot/brrygrdn/dependency-change-b…
Browse files Browse the repository at this point in the history
…uilds-message-with-group

[Updater] DependencyChange passes any group to the PR message builder
  • Loading branch information
brrygrdn committed Apr 24, 2023
2 parents 570898a + cf79abb commit 3d59941
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
10 changes: 4 additions & 6 deletions updater/lib/dependabot/dependency_change.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# by adapters to create a Pull Request, apply the changes on disk, etc.
module Dependabot
class DependencyChange
attr_reader :job, :updated_dependencies, :updated_dependency_files
attr_reader :job, :updated_dependencies, :updated_dependency_files, :dependency_group

def initialize(job:, updated_dependencies:, updated_dependency_files:, dependency_group: nil)
@job = job
Expand All @@ -28,7 +28,8 @@ def pr_message
dependencies: updated_dependencies,
files: updated_dependency_files,
credentials: job.credentials,
commit_message_options: job.commit_message_options
commit_message_options: job.commit_message_options,
dependency_group: dependency_group
).message
end

Expand All @@ -42,11 +43,8 @@ def updated_dependency_files_hash
updated_dependency_files.map(&:to_h)
end

# FIXME: This is a placeholder for using a concrete DependencyGroup object to create
# as grouped rule hash to pass to the Dependabot API client. For now, we just
# use a flag on whether a rule has been assigned to the change.
def grouped_update?
!!@dependency_group
!!dependency_group
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def dependencies
:error_handler

def register_all_dependencies_group
all_dependencies_group = { "name" => "group-all", "rules" => { "patterns" => ["*"] } }
all_dependencies_group = { "name" => "all-dependencies", "rules" => { "patterns" => ["*"] } }
Dependabot::DependencyGroupEngine.register(all_dependencies_group["name"],
all_dependencies_group["rules"]["patterns"])
end
Expand Down
35 changes: 30 additions & 5 deletions updater/spec/dependabot/dependency_change_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,37 @@
files: updated_dependency_files,
dependencies: updated_dependencies,
credentials: job_credentials,
commit_message_options: commit_message_options
commit_message_options: commit_message_options,
dependency_group: nil
)

expect(dependency_change.pr_message).to eql("Hello World!")
end

context "when a dependency group is assigned" do
it "delegates to the Dependabot::PullRequestCreator::MessageBuilder with the group included" do
group = Dependabot::DependencyGroup.new(name: "foo", rules: anything)

dependency_change = described_class.new(
job: job,
updated_dependencies: updated_dependencies,
updated_dependency_files: updated_dependency_files,
dependency_group: group
)

expect(Dependabot::PullRequestCreator::MessageBuilder).
to receive(:new).with(
source: github_source,
files: updated_dependency_files,
dependencies: updated_dependencies,
credentials: job_credentials,
commit_message_options: commit_message_options,
dependency_group: group
)

expect(dependency_change.pr_message).to eql("Hello World!")
end
end
end

describe "#grouped_update?" do
Expand All @@ -113,15 +139,14 @@

context "when a dependency group is assigned" do
it "is true" do
rule = described_class.new(
dependency_change = described_class.new(
job: job,
updated_dependencies: updated_dependencies,
updated_dependency_files: updated_dependency_files,
# For now the dependency_group parameter is treated permissively as any non-nil value
dependency_group: anything
dependency_group: Dependabot::DependencyGroup.new(name: "foo", rules: anything)
)

expect(rule.grouped_update?).to be true
expect(dependency_change.grouped_update?).to be true
end
end
end
Expand Down

0 comments on commit 3d59941

Please sign in to comment.