Skip to content

Commit

Permalink
support group configs specifically for security updates or version up…
Browse files Browse the repository at this point in the history
…dates (#9040)
  • Loading branch information
jakecoffman authored Feb 13, 2024
1 parent d63dd7e commit 9fc744e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
10 changes: 8 additions & 2 deletions common/lib/dependabot/dependency_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ class DependencyGroup
sig { returns(T::Array[Dependabot::Dependency]) }
attr_reader :dependencies

sig { returns(String) }
attr_reader :applies_to

sig do
params(
name: String,
rules: T::Hash[String, T.untyped]
rules: T::Hash[String, T.untyped],
applies_to: T.nilable(String)
)
.void
end
def initialize(name:, rules:)
def initialize(name:, rules:, applies_to: "version-updates")
@name = name
# For backwards compatibility, if no applies_to is provided, default to "version-updates"
@applies_to = T.let(applies_to || "version-updates", String)
@rules = rules
@dependencies = T.let([], T::Array[Dependabot::Dependency])
end
Expand Down
1 change: 1 addition & 0 deletions silent/tests/testdata/su-group-pattern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ job:
security-updates-only: true
dependency-groups:
- name: related
applies-to: "security-updates"
rules:
patterns:
- "related-*"
1 change: 1 addition & 0 deletions silent/tests/testdata/su-group-semver.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ job:
security-updates-only: true
dependency-groups:
- name: dev
applies-to: security-updates
rules:
update-types:
- minor
Expand Down
2 changes: 2 additions & 0 deletions silent/tests/testdata/su-group-type.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ job:
grouped-update: true
dependency-groups:
- name: dev
applies-to: security-updates
rules:
dependency-type: development
- name: prod
applies-to: security-updates
rules:
dependency-type: production
12 changes: 10 additions & 2 deletions updater/lib/dependabot/dependency_group_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def self.from_job_config(job:)
# Since there are no groups, the default behavior is to group all dependencies, so create a fake group.
job.dependency_groups << {
"name" => "#{job.package_manager} group",
"rules" => { "patterns" => ["*"] }
"rules" => { "patterns" => ["*"] },
"applies-to" => "security-updates"
}

# This ensures refreshes work for these dynamic groups.
Expand All @@ -41,9 +42,16 @@ def self.from_job_config(job:)
end

groups = job.dependency_groups.map do |group|
Dependabot::DependencyGroup.new(name: group["name"], rules: group["rules"])
Dependabot::DependencyGroup.new(name: group["name"], rules: group["rules"], applies_to: group["applies-to"])
end

# Filter out version updates when doing security updates and visa versa
groups = if job.security_updates_only?
groups.select { |group| group.applies_to == "security-updates" }
else
groups.select { |group| group.applies_to == "version-updates" }
end

new(dependency_groups: groups)
end

Expand Down
52 changes: 50 additions & 2 deletions updater/spec/dependabot/dependency_group_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@
include DependencyFileHelpers

let(:dependency_group_engine) { described_class.from_job_config(job: job) }

let(:source) do
Dependabot::Source.new(
provider: "github",
repo: "gocardless/bump",
directory: "/",
branch: "master"
)
end
let(:security_updates_only) { false }
let(:job) do
instance_double(Dependabot::Job,
dependency_groups: dependency_groups_config,
security_updates_only?: false)
source: source,
security_updates_only?: security_updates_only)
end

let(:dummy_pkg_a) do
Expand Down Expand Up @@ -108,6 +117,45 @@
end
end

context "when a job has grouped configured, and it's a version update" do
let(:dependency_groups_config) do
[
{
"name" => "group-a",
"rules" => {
"patterns" => ["dummy-pkg-*"],
"exclude-patterns" => ["dummy-pkg-b"]
}
},
{
"name" => "group-b",
"applies-to" => "security-updates",
"rules" => {
"patterns" => %w(dummy-pkg-b dummy-pkg-c)
}
}
]
end

describe "::from_job_config" do
it "filters out the security update" do
expect(dependency_group_engine.dependency_groups.length).to eql(1)
expect(dependency_group_engine.dependency_groups.map(&:name)).to eql(%w(group-a))
end
end

context "when it's a security update" do
let(:security_updates_only) { true }

describe "::from_job_config" do
it "filters out the version update" do
expect(dependency_group_engine.dependency_groups.length).to eql(1)
expect(dependency_group_engine.dependency_groups.map(&:name)).to eql(%w(group-b))
end
end
end
end

context "when a job has groups configured" do
let(:dependency_groups_config) do
[
Expand Down

0 comments on commit 9fc744e

Please sign in to comment.