Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 59d2b1f

Browse filesBrowse files
CloudNStoyanNishnha
authored andcommitted
fix incorrect parsing of directory when using dependency-group
1 parent 0d27069 commit 59d2b1f
Copy full SHA for 59d2b1f

File tree

Expand file treeCollapse file tree

3 files changed

+108
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+108
-5
lines changed

‎src/dependabot/update_metadata.test.ts

Copy file name to clipboardExpand all lines: src/dependabot/update_metadata.test.ts
+94Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,100 @@ test('it handles branch names with hyphen separator and multiple dependencies',
398398
expect(updatedDependencies[0].directory).toEqual('/')
399399
})
400400

401+
test('it handles branch names when it has dependency-group and non-root directory', async () => {
402+
const commitMessage = `Bumps the eslint group in /first-package with 1 update: [eslint](https://github.com/eslint/eslint).
403+
404+
405+
Updates \`eslint\` from 9.12.0 to 9.13.0
406+
- [Release notes](https://github.com/eslint/eslint/releases)
407+
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
408+
- [Commits](eslint/eslint@v9.12.0...v9.13.0)
409+
410+
---
411+
updated-dependencies:
412+
- dependency-name: eslint
413+
dependency-type: direct:development
414+
update-type: version-update:semver-minor
415+
dependency-group: eslint
416+
...
417+
418+
Signed-off-by: dependabot[bot] <support@github.com>`
419+
420+
const getAlert = async () => Promise.resolve({ alertState: 'DISMISSED', ghsaId: 'GHSA-III-BBB', cvss: 4.6 })
421+
const getScore = async () => Promise.resolve(43)
422+
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot/npm_and_yarn/first-package/eslint-3c401b8a51', 'main', getAlert, getScore)
423+
424+
expect(updatedDependencies[0].directory).toEqual('/first-package')
425+
})
426+
427+
test('it handles branch names when it has dependency-group and root directory', async () => {
428+
const commitMessage = `Bumps the eslint group in /first-package with 1 update: [eslint](https://github.com/eslint/eslint).
429+
430+
431+
Updates \`eslint\` from 9.12.0 to 9.13.0
432+
- [Release notes](https://github.com/eslint/eslint/releases)
433+
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
434+
- [Commits](eslint/eslint@v9.12.0...v9.13.0)
435+
436+
---
437+
updated-dependencies:
438+
- dependency-name: eslint
439+
dependency-type: direct:development
440+
update-type: version-update:semver-minor
441+
dependency-group: eslint
442+
...
443+
444+
Signed-off-by: dependabot[bot] <support@github.com>`
445+
446+
const getAlert = async () => Promise.resolve({ alertState: 'DISMISSED', ghsaId: 'GHSA-III-BBB', cvss: 4.6 })
447+
const getScore = async () => Promise.resolve(43)
448+
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot/npm_and_yarn/first-package/eslint-3c401b8a51', 'main', getAlert, getScore)
449+
450+
expect(updatedDependencies[0].directory).toEqual('/first-package')
451+
})
452+
453+
test('it handles branch names when it has dependency-group with multiple dependencies and non-root directory', async () => {
454+
const commitMessage = `Bumps the grouped-dependencies group with 3 updates in the /first-package directory: [eslint](https://github.com/eslint/eslint), [rimraf](https://github.com/isaacs/rimraf) and [vitest](https://github.com/vitest-dev/vitest/tree/HEAD/packages/vitest).
455+
456+
457+
Updates \`eslint\` from 9.12.0 to 9.13.0
458+
- [Release notes](https://github.com/eslint/eslint/releases)
459+
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
460+
- [Commits](eslint/eslint@v9.12.0...v9.13.0)
461+
462+
Updates \`rimraf\` from 5.0.10 to 6.0.1
463+
- [Changelog](https://github.com/isaacs/rimraf/blob/main/CHANGELOG.md)
464+
- [Commits](isaacs/rimraf@v5.0.10...v6.0.1)
465+
466+
Updates \`vitest\` from 1.6.0 to 2.1.3
467+
- [Release notes](https://github.com/vitest-dev/vitest/releases)
468+
- [Commits](https://github.com/vitest-dev/vitest/commits/v2.1.3/packages/vitest)
469+
470+
---
471+
updated-dependencies:
472+
- dependency-name: eslint
473+
dependency-type: direct:development
474+
update-type: version-update:semver-minor
475+
dependency-group: grouped-dependencies
476+
- dependency-name: rimraf
477+
dependency-type: direct:development
478+
update-type: version-update:semver-major
479+
dependency-group: grouped-dependencies
480+
- dependency-name: vitest
481+
dependency-type: direct:development
482+
update-type: version-update:semver-major
483+
dependency-group: grouped-dependencies
484+
...
485+
486+
Signed-off-by: dependabot[bot] <support@github.com>`
487+
488+
const getAlert = async () => Promise.resolve({ alertState: 'DISMISSED', ghsaId: 'GHSA-III-BBB', cvss: 4.6 })
489+
const getScore = async () => Promise.resolve(43)
490+
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot/npm_and_yarn/first-package/grouped-dependencies-b23a7a6750', 'main', getAlert, getScore)
491+
492+
expect(updatedDependencies[0].directory).toEqual('/first-package')
493+
})
494+
401495
test('calculateUpdateType should handle all paths', () => {
402496
expect(updateMetadata.calculateUpdateType('', '')).toEqual('')
403497
expect(updateMetadata.calculateUpdateType('', '1')).toEqual('')

‎src/dependabot/update_metadata.ts

Copy file name to clipboardExpand all lines: src/dependabot/update_metadata.ts
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export interface scoreLookup {
2828
(dependencyName: string, previousVersion: string, newVersion: string, ecosystem: string): Promise<number>;
2929
}
3030

31-
function branchNameToDirectoryName (chunks: string[], delimiter: string, updatedDependencies: any): string {
31+
function branchNameToDirectoryName (chunks: string[], delimiter: string, updatedDependencies: any, dependencyGroup: string): string {
3232
// We can always slice after the first 2 pieces, because they will always contain "dependabot" followed by the name
3333
// of the package ecosystem. e.g. "dependabot/npm_and_yarn".
3434
const sliceStart = 2
@@ -39,6 +39,15 @@ function branchNameToDirectoryName (chunks: string[], delimiter: string, updated
3939
sliceEnd -= 1
4040
}
4141

42+
if (dependencyGroup) {
43+
// After replacing "/" in the dependency group with the delimiter, which could also be "/", we count how many pieces
44+
// the dependency group would split into by the delimiter, and slicing that amount off the end of the branch name.
45+
// e.g. "eslint/plugins" and a delimiter of "-" would show up in the branch name as "eslint-plugins".
46+
sliceEnd -= dependencyGroup.replace('/', delimiter).split(delimiter).length
47+
48+
return `/${chunks.slice(sliceStart, sliceEnd).join('/')}`
49+
}
50+
4251
// If there is more than 1 dependency name being updated, we assume 1 piece of the branch name will be "and".
4352
if (updatedDependencies.length > 1) {
4453
sliceEnd -= 1
@@ -74,7 +83,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
7483
const dependencyGroup = groupName?.groups?.name ?? ''
7584

7685
if (data['updated-dependencies']) {
77-
const dirname = branchNameToDirectoryName(chunks, delim, data['updated-dependencies'])
86+
const dirname = branchNameToDirectoryName(chunks, delim, data['updated-dependencies'], dependencyGroup)
7887

7988
return await Promise.all(data['updated-dependencies'].map(async (dependency, index) => {
8089
const lastVersion = index === 0 ? prev : ''

‎src/main.test.ts

Copy file name to clipboardExpand all lines: src/main.test.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ test('it supports returning information about grouped updates', async () => {
270270
dependencyName: 'github.com/docker/cli',
271271
dependencyType: 'direct:production',
272272
updateType: 'version-update:semver-patch',
273-
directory: '/',
273+
directory: '/gh-base-image',
274274
packageEcosystem: 'docker',
275275
targetBranch: 'trunk',
276276
prevVersion: '',
@@ -286,7 +286,7 @@ test('it supports returning information about grouped updates', async () => {
286286
dependencyName: 'github.com/docker/docker',
287287
dependencyType: 'direct:production',
288288
updateType: 'version-update:semver-patch',
289-
directory: '/',
289+
directory: '/gh-base-image',
290290
packageEcosystem: 'docker',
291291
targetBranch: 'trunk',
292292
prevVersion: '',
@@ -302,7 +302,7 @@ test('it supports returning information about grouped updates', async () => {
302302
dependencyName: 'github.com/moby/moby',
303303
dependencyType: 'direct:production',
304304
updateType: 'version-update:semver-patch',
305-
directory: '/',
305+
directory: '/gh-base-image',
306306
packageEcosystem: 'docker',
307307
targetBranch: 'trunk',
308308
prevVersion: '',

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.