Skip to content

Commit 9e8fb5b

Browse files
committed
Add tests for grouped updates
1 parent b3648a3 commit 9e8fb5b

File tree

4 files changed

+165
-1
lines changed

4 files changed

+165
-1
lines changed

src/dependabot/output.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const baseDependency = {
2020
newVersion: '',
2121
compatScore: 0,
2222
maintainerChanges: false,
23+
dependencyGroup: '',
2324
alertState: '',
2425
ghsaId: '',
2526
cvss: 0
@@ -38,6 +39,7 @@ test('when given a single dependency it sets its values', async () => {
3839
newVersion: '1.1.3-beta',
3940
compatScore: 43,
4041
maintainerChanges: true,
42+
dependencyGroup: '',
4143
alertState: 'FIXED',
4244
ghsaId: 'VERY_LONG_ID',
4345
cvss: 4.6

src/dependabot/update_metadata.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ test('it returns the updated dependency information when there is a yaml fragmen
6161
expect(updatedDependencies[0].alertState).toEqual('DISMISSED')
6262
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB')
6363
expect(updatedDependencies[0].cvss).toEqual(4.6)
64+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
6465
})
6566

6667
test('it supports multiple dependencies within a single fragment', async () => {
@@ -122,6 +123,8 @@ test('it supports multiple dependencies within a single fragment', async () => {
122123
expect(updatedDependencies[0].alertState).toEqual('DISMISSED')
123124
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB')
124125
expect(updatedDependencies[0].cvss).toEqual(4.6)
126+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
127+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
125128

126129
expect(updatedDependencies[1].dependencyName).toEqual('coffeescript')
127130
expect(updatedDependencies[1].dependencyType).toEqual('indirect')
@@ -135,6 +138,7 @@ test('it supports multiple dependencies within a single fragment', async () => {
135138
expect(updatedDependencies[1].alertState).toEqual('')
136139
expect(updatedDependencies[1].ghsaId).toEqual('')
137140
expect(updatedDependencies[1].cvss).toEqual(0)
141+
expect(updatedDependencies[1].dependencyGroup).toEqual('')
138142
})
139143

140144
test('it returns the updated dependency information when there is a leading v in the commit message versions', async () => {
@@ -170,6 +174,47 @@ test('it returns the updated dependency information when there is a leading v in
170174
expect(updatedDependencies[0].alertState).toEqual('DISMISSED')
171175
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB')
172176
expect(updatedDependencies[0].cvss).toEqual(4.6)
177+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
178+
})
179+
180+
test('it supports returning information about grouped updates', async () => {
181+
const commitMessage =
182+
'Bumps the docker group with 3 updates: [github.com/docker/cli](https://github.com/docker/cli), [github.com/docker/docker](https://github.com/docker/docker) and [github.com/moby/moby](https://github.com/moby/moby).\n' +
183+
'\n' +
184+
'Updates `github.com/docker/cli` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
185+
'- [Commits](docker/[email protected])\n' +
186+
'\n' +
187+
'Updates `github.com/docker/docker` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
188+
'- [Release notes](https://github.com/docker/docker/releases)\n' +
189+
'- [Commits](moby/[email protected])\n' +
190+
'\n' +
191+
'Updates `github.com/moby/moby` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
192+
'- [Release notes](https://github.com/moby/moby/releases)\n' +
193+
'- [Commits](moby/[email protected])\n' +
194+
'\n' +
195+
'---\n' +
196+
'updated-dependencies:\n' +
197+
'- dependency-name: github.com/docker/cli\n' +
198+
' dependency-type: direct:production\n' +
199+
' update-type: version-update:semver-patch\n' +
200+
'- dependency-name: github.com/docker/docker\n' +
201+
' dependency-type: direct:production\n' +
202+
' update-type: version-update:semver-patch\n' +
203+
'- dependency-name: github.com/moby/moby\n' +
204+
' dependency-type: direct:production\n' +
205+
' update-type: version-update:semver-patch\n' +
206+
'...\n' +
207+
'\n' +
208+
'Signed-off-by: dependabot[bot] <[email protected]>\n'
209+
210+
const getAlert = async () => Promise.resolve({ alertState: 'DISMISSED', ghsaId: 'GHSA-III-BBB', cvss: 4.6 })
211+
const getScore = async () => Promise.resolve(43)
212+
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot/docker/gh-base-image/docker-1234566789', 'main', getAlert, getScore)
213+
214+
expect(updatedDependencies).toHaveLength(3)
215+
216+
expect(updatedDependencies[0].dependencyName).toEqual('github.com/docker/cli')
217+
expect(updatedDependencies[0].dependencyGroup).toEqual('docker')
173218
})
174219

175220
test('it only returns information within the first fragment if there are multiple yaml documents', async () => {
@@ -211,6 +256,7 @@ test('it only returns information within the first fragment if there are multipl
211256
expect(updatedDependencies[0].alertState).toEqual('')
212257
expect(updatedDependencies[0].ghsaId).toEqual('')
213258
expect(updatedDependencies[0].cvss).toEqual(0)
259+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
214260
})
215261

216262
test('it properly handles dependencies which contain slashes', async () => {
@@ -247,6 +293,7 @@ test('it properly handles dependencies which contain slashes', async () => {
247293
expect(updatedDependencies[0].alertState).toEqual('')
248294
expect(updatedDependencies[0].ghsaId).toEqual('')
249295
expect(updatedDependencies[0].cvss).toEqual(0)
296+
expect(updatedDependencies[0].dependencyGroup).toEqual('')
250297
})
251298

252299
test('calculateUpdateType should handle all paths', () => {

src/dependabot/update_metadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
4545
const chunks = branchName.split(delim)
4646
const prev = bumpFragment?.groups?.from ?? (updateFragment?.groups?.from ?? '')
4747
const next = bumpFragment?.groups?.to ?? (updateFragment?.groups?.to ?? '')
48-
const dependencyGroup = groupName?.groups?.name ?? ''
48+
const dependencyGroup = groupName?.groups?.name ?? ''
4949

5050
if (data['updated-dependencies']) {
5151
return await Promise.all(data['updated-dependencies'].map(async (dependency, index) => {

src/main.test.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi
112112
newVersion: '4.2.2',
113113
compatScore: 0,
114114
maintainerChanges: false,
115+
dependencyGroup: '',
115116
alertState: '',
116117
ghsaId: '',
117118
cvss: 0
@@ -129,6 +130,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi
129130
expect(core.setOutput).toBeCalledWith('new-version', '4.2.2')
130131
expect(core.setOutput).toBeCalledWith('compatibility-score', 0)
131132
expect(core.setOutput).toBeCalledWith('maintainer-changes', false)
133+
expect(core.setOutput).toBeCalledWith('dependency-group', '')
132134
expect(core.setOutput).toBeCalledWith('alert-state', '')
133135
expect(core.setOutput).toBeCalledWith('ghsa-id', '')
134136
expect(core.setOutput).toBeCalledWith('cvss', 0)
@@ -179,6 +181,7 @@ test('it sets the updated dependency as an output for subsequent actions when th
179181
directory: '/',
180182
packageEcosystem: 'nuget',
181183
maintainerChanges: false,
184+
dependencyGroup: '',
182185
targetBranch: 'main',
183186
prevVersion: 'v4.0.1',
184187
newVersion: 'v4.2.2',
@@ -200,11 +203,118 @@ test('it sets the updated dependency as an output for subsequent actions when th
200203
expect(core.setOutput).toBeCalledWith('new-version', 'v4.2.2')
201204
expect(core.setOutput).toBeCalledWith('compatibility-score', 0)
202205
expect(core.setOutput).toBeCalledWith('maintainer-changes', false)
206+
expect(core.setOutput).toBeCalledWith('dependency-group', '')
203207
expect(core.setOutput).toBeCalledWith('alert-state', '')
204208
expect(core.setOutput).toBeCalledWith('ghsa-id', '')
205209
expect(core.setOutput).toBeCalledWith('cvss', 0)
206210
})
207211

212+
test('it supports returning information about grouped updates', async () => {
213+
const mockCommitMessage =
214+
'Bumps the docker group with 3 updates: [github.com/docker/cli](https://github.com/docker/cli), [github.com/docker/docker](https://github.com/docker/docker) and [github.com/moby/moby](https://github.com/moby/moby).\n' +
215+
'\n' +
216+
'Updates `github.com/docker/cli` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
217+
'- [Commits](docker/[email protected])\n' +
218+
'\n' +
219+
'Updates `github.com/docker/docker` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
220+
'- [Release notes](https://github.com/docker/docker/releases)\n' +
221+
'- [Commits](moby/[email protected])\n' +
222+
'\n' +
223+
'Updates `github.com/moby/moby` from 24.0.1+incompatible to 24.0.2+incompatible\n' +
224+
'- [Release notes](https://github.com/moby/moby/releases)\n' +
225+
'- [Commits](moby/[email protected])\n' +
226+
'\n' +
227+
'---\n' +
228+
'updated-dependencies:\n' +
229+
'- dependency-name: github.com/docker/cli\n' +
230+
' dependency-type: direct:production\n' +
231+
' update-type: version-update:semver-patch\n' +
232+
'- dependency-name: github.com/docker/docker\n' +
233+
' dependency-type: direct:production\n' +
234+
' update-type: version-update:semver-patch\n' +
235+
'- dependency-name: github.com/moby/moby\n' +
236+
' dependency-type: direct:production\n' +
237+
' update-type: version-update:semver-patch\n' +
238+
'...\n' +
239+
'\n' +
240+
'Signed-off-by: dependabot[bot] <[email protected]>\n'
241+
242+
const mockAlert = { alertState: '', ghsaId: '', cvss: 0 }
243+
244+
jest.spyOn(core, 'getInput').mockReturnValue('mock-token')
245+
jest.spyOn(util, 'getBranchNames').mockReturnValue({ headName: 'dependabot/docker/gh-base-image/docker-1234566789', baseName: 'trunk' })
246+
jest.spyOn(dependabotCommits, 'getMessage').mockImplementation(jest.fn(
247+
() => Promise.resolve(mockCommitMessage)
248+
))
249+
jest.spyOn(dependabotCommits, 'getAlert').mockImplementation(jest.fn(
250+
() => Promise.resolve(mockAlert)
251+
))
252+
jest.spyOn(dependabotCommits, 'getCompatibility').mockImplementation(jest.fn(
253+
() => Promise.resolve(34)
254+
))
255+
jest.spyOn(core, 'setOutput').mockImplementation(jest.fn())
256+
257+
await run()
258+
259+
expect(core.startGroup).toHaveBeenCalledWith(
260+
expect.stringContaining('Outputting metadata for 3 updated dependencies')
261+
)
262+
263+
expect(core.setOutput).toHaveBeenCalledWith(
264+
'updated-dependencies-json',
265+
[
266+
{
267+
dependencyName: 'github.com/docker/cli',
268+
dependencyType: 'direct:production',
269+
updateType: 'version-update:semver-patch',
270+
directory: '/',
271+
packageEcosystem: 'docker',
272+
targetBranch: 'trunk',
273+
prevVersion: '24.0.1',
274+
newVersion: '24.0.2',
275+
compatScore: 34,
276+
maintainerChanges: false,
277+
dependencyGroup: 'docker',
278+
alertState: '',
279+
ghsaId: '',
280+
cvss: 0
281+
},
282+
{
283+
dependencyName: 'github.com/docker/docker',
284+
dependencyType: 'direct:production',
285+
updateType: 'version-update:semver-patch',
286+
directory: '/',
287+
packageEcosystem: 'docker',
288+
targetBranch: 'trunk',
289+
prevVersion: '24.0.1',
290+
newVersion: '24.0.2',
291+
compatScore: 34,
292+
maintainerChanges: false,
293+
dependencyGroup: 'docker',
294+
alertState: '',
295+
ghsaId: '',
296+
cvss: 0
297+
},
298+
{
299+
dependencyName: 'github.com/moby/moby',
300+
dependencyType: 'direct:production',
301+
updateType: 'version-update:semver-patch',
302+
directory: '/',
303+
packageEcosystem: 'docker',
304+
targetBranch: 'trunk',
305+
prevVersion: '24.0.1',
306+
newVersion: '24.0.2',
307+
compatScore: 34,
308+
maintainerChanges: false,
309+
dependencyGroup: 'docker',
310+
alertState: '',
311+
ghsaId: '',
312+
cvss: 0
313+
}
314+
]
315+
)
316+
})
317+
208318
test('it sets the updated dependency as an output for subsequent actions when given a commit message for library', async () => {
209319
const mockCommitMessage =
210320
'Update rubocop requirement from ~> 1.30.1 to ~> 1.31.0\n' +
@@ -253,6 +363,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi
253363
packageEcosystem: 'bundler',
254364
targetBranch: 'main',
255365
maintainerChanges: false,
366+
dependencyGroup: '',
256367
prevVersion: '1.30.1',
257368
newVersion: '1.31.0',
258369
compatScore: 0,
@@ -273,6 +384,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi
273384
expect(core.setOutput).toBeCalledWith('new-version', '1.31.0')
274385
expect(core.setOutput).toBeCalledWith('compatibility-score', 0)
275386
expect(core.setOutput).toBeCalledWith('maintainer-changes', false)
387+
expect(core.setOutput).toBeCalledWith('dependency-group', '')
276388
expect(core.setOutput).toBeCalledWith('alert-state', '')
277389
expect(core.setOutput).toBeCalledWith('ghsa-id', '')
278390
expect(core.setOutput).toBeCalledWith('cvss', 0)
@@ -332,6 +444,7 @@ test('if there are multiple dependencies, it summarizes them', async () => {
332444
newVersion: '4.2.2',
333445
compatScore: 34,
334446
maintainerChanges: false,
447+
dependencyGroup: '',
335448
alertState: '',
336449
ghsaId: '',
337450
cvss: 0
@@ -347,6 +460,7 @@ test('if there are multiple dependencies, it summarizes them', async () => {
347460
newVersion: '',
348461
compatScore: 34,
349462
maintainerChanges: false,
463+
dependencyGroup: '',
350464
alertState: '',
351465
ghsaId: '',
352466
cvss: 0
@@ -364,6 +478,7 @@ test('if there are multiple dependencies, it summarizes them', async () => {
364478
expect(core.setOutput).toBeCalledWith('new-version', '4.2.2')
365479
expect(core.setOutput).toBeCalledWith('compatibility-score', 34)
366480
expect(core.setOutput).toBeCalledWith('maintainer-changes', false)
481+
expect(core.setOutput).toBeCalledWith('dependency-group', '')
367482
expect(core.setOutput).toBeCalledWith('alert-state', '')
368483
expect(core.setOutput).toBeCalledWith('ghsa-id', '')
369484
expect(core.setOutput).toBeCalledWith('cvss', 0)

0 commit comments

Comments
 (0)