Skip to content

Commit cd7eaa3

Browse files
Merge pull request step-security#2571 from vamshi-stepsecurity/refactor/dependabot/vk/support-cool-down
fix updateSubtractiveFields to allow adding ecosystems
2 parents b0b24e6 + 1925d44 commit cd7eaa3

4 files changed

Lines changed: 98 additions & 0 deletions

File tree

remediation/dependabot/dependabotconfig.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ func updateSubtractiveFields(content string, ecosystems []Ecosystem) (string, bo
205205

206206
isChanged := false
207207
for _, eco := range ecosystems {
208+
found := false
208209
for i, update := range cfg.Updates {
209210
if update.PackageEcosystem != eco.PackageEcosystem {
210211
continue
211212
}
212213
if update.Directory != eco.Directory && update.Directory != eco.Directory+"/" {
213214
continue
214215
}
216+
found = true
215217

216218
// Found the matching entry — update only non-empty fields.
217219
if eco.Interval != "" && cfg.Updates[i].Schedule.Interval != eco.Interval {
@@ -293,6 +295,20 @@ func updateSubtractiveFields(content string, ecosystems []Ecosystem) (string, bo
293295
}
294296
break
295297
}
298+
299+
if !found {
300+
// Ecosystem not in config — add it as a new entry.
301+
cfg.Updates = append(cfg.Updates, ExtendedUpdate{
302+
Update: dependabot.Update{
303+
PackageEcosystem: eco.PackageEcosystem,
304+
Directory: eco.Directory,
305+
Schedule: dependabot.Schedule{Interval: eco.Interval},
306+
},
307+
Groups: eco.Groups,
308+
CoolDown: eco.CoolDown,
309+
})
310+
isChanged = true
311+
}
296312
}
297313

298314
if !isChanged {

remediation/dependabot/dependabotconfig_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,49 @@ func TestUpdateSubtractiveFields(t *testing.T) {
317317
},
318318
isChanged: true,
319319
},
320+
{
321+
// Subtractive — request has two ecosystems; github-actions exists and gets updated,
322+
// npm does not exist in the config and is silently skipped.
323+
fileName: "subtractive-multi-skip-missing.yml",
324+
ecosystems: []Ecosystem{
325+
{
326+
PackageEcosystem: "github-actions",
327+
Directory: "/",
328+
Interval: "monthly",
329+
CoolDown: &CoolDown{
330+
DefaultDays: 14,
331+
SemverMajorDays: 60,
332+
},
333+
Groups: map[string]Group{
334+
"actions": {Patterns: []string{"*"}},
335+
},
336+
},
337+
{
338+
PackageEcosystem: "npm",
339+
Directory: "/",
340+
Interval: "weekly",
341+
CoolDown: &CoolDown{
342+
DefaultDays: 7,
343+
SemverMajorDays: 30,
344+
SemverMinorDays: 14,
345+
SemverPatchDays: 5,
346+
},
347+
Groups: map[string]Group{
348+
"production-dependencies": {
349+
AppliesTo: "version-updates",
350+
Patterns: []string{"*"},
351+
DependencyType: "production",
352+
},
353+
"dev-dependencies": {
354+
AppliesTo: "version-updates",
355+
Patterns: []string{"*"},
356+
DependencyType: "development",
357+
},
358+
},
359+
},
360+
},
361+
isChanged: true,
362+
},
320363
}
321364

322365
for _, test := range tests {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: monthly
7+
groups:
8+
actions:
9+
patterns:
10+
- '*'
11+
cooldown:
12+
default-days: 14
13+
semver-major-days: 60
14+
- package-ecosystem: npm
15+
directory: /
16+
schedule:
17+
interval: weekly
18+
groups:
19+
dev-dependencies:
20+
applies-to: version-updates
21+
patterns:
22+
- '*'
23+
dependency-type: development
24+
production-dependencies:
25+
applies-to: version-updates
26+
patterns:
27+
- '*'
28+
dependency-type: production
29+
cooldown:
30+
default-days: 7
31+
semver-major-days: 30
32+
semver-minor-days: 14
33+
semver-patch-days: 5

0 commit comments

Comments
 (0)