Skip to content

Commit

Permalink
Warn about empty groups during job boot
Browse files Browse the repository at this point in the history
  • Loading branch information
brrygrdn committed Jul 14, 2023
1 parent a60833a commit fc49e26
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 14 deletions.
18 changes: 18 additions & 0 deletions updater/lib/dependabot/dependency_group_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def assign_to_groups!(dependencies:)
@ungrouped_dependencies = dependencies
end

validate_groups
@groups_calculated = true
end

Expand All @@ -62,5 +63,22 @@ def initialize(dependency_groups:)
@ungrouped_dependencies = []
@groups_calculated = false
end

def validate_groups
empty_groups = dependency_groups.select { |group| group.dependencies.empty? }
warn_misconfigured_groups(empty_groups) if empty_groups.any?
end

def warn_misconfigured_groups(groups)
Dependabot.logger.warn <<~WARN
Please check your configuration as there are groups no dependencies match:
#{groups.map { |g| "- #{g.name}" }.join("\n")}
This can happen if:
- the group's 'pattern' rules are mispelled
- your configuration's 'allow' rules do not permit any of the dependencies that match the group
- your configuration's 'ignore' rules exclude all of the dependencies that match the group
WARN
end
end
end
71 changes: 57 additions & 14 deletions updater/spec/dependabot/dependency_group_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,70 @@
)
end

let(:dependencies) { [dummy_pkg_a, dummy_pkg_b, dummy_pkg_c, ungrouped_pkg] }
context "when all groups have at least one dependency that matches" do
let(:dependencies) { [dummy_pkg_a, dummy_pkg_b, dummy_pkg_c, ungrouped_pkg] }

before do
dependency_group_engine.assign_to_groups!(dependencies: dependencies)
end
before do
dependency_group_engine.assign_to_groups!(dependencies: dependencies)
end

it "adds dependencies to every group they match" do
group_a = dependency_group_engine.find_group(name: "group-a")
expect(group_a.dependencies).to eql([dummy_pkg_a, dummy_pkg_c])
it "adds dependencies to every group they match" do
group_a = dependency_group_engine.find_group(name: "group-a")
expect(group_a.dependencies).to eql([dummy_pkg_a, dummy_pkg_c])

group_b = dependency_group_engine.find_group(name: "group-b")
expect(group_b.dependencies).to eql([dummy_pkg_b, dummy_pkg_c])
group_b = dependency_group_engine.find_group(name: "group-b")
expect(group_b.dependencies).to eql([dummy_pkg_b, dummy_pkg_c])
end

it "keeps a list of any dependencies that do not match any groups" do
expect(dependency_group_engine.ungrouped_dependencies).to eql([ungrouped_pkg])
end

it "raises an exception if it is called a second time" do
expect { dependency_group_engine.assign_to_groups!(dependencies: dependencies) }.
to raise_error(described_class::ConfigurationError, "dependency groups have already been configured!")
end
end

it "keeps a list of any dependencies that do not match any groups" do
expect(dependency_group_engine.ungrouped_dependencies).to eql([ungrouped_pkg])
context "when one group has no matching dependencies" do
let(:dependencies) { [dummy_pkg_a] }

it "warns that the group is misconfigured" do
expect(Dependabot.logger).to receive(:warn).with(
<<~WARN
Please check your configuration as there are groups no dependencies match:
- group-b
This can happen if:
- the group's 'pattern' rules are mispelled
- your configuration's 'allow' rules do not permit any of the dependencies that match the group
- your configuration's 'ignore' rules exclude all of the dependencies that match the group
WARN
)

dependency_group_engine.assign_to_groups!(dependencies: dependencies)
end
end

it "raises an exception if it is called a second time" do
expect { dependency_group_engine.assign_to_groups!(dependencies: dependencies) }.
to raise_error(described_class::ConfigurationError, "dependency groups have already been configured!")
context "when no groups have any matching dependencies" do
let(:dependencies) { [ungrouped_pkg] }

it "warns that the groups are misconfigured" do
expect(Dependabot.logger).to receive(:warn).with(
<<~WARN
Please check your configuration as there are groups no dependencies match:
- group-a
- group-b
This can happen if:
- the group's 'pattern' rules are mispelled
- your configuration's 'allow' rules do not permit any of the dependencies that match the group
- your configuration's 'ignore' rules exclude all of the dependencies that match the group
WARN
)

dependency_group_engine.assign_to_groups!(dependencies: dependencies)
end
end
end

Expand Down

0 comments on commit fc49e26

Please sign in to comment.