Skip to content

Commit

Permalink
Improve directory name extraction from branch name.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreid committed Feb 12, 2024
1 parent 924483a commit a1e3f32
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
76 changes: 76 additions & 0 deletions src/dependabot/update_metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,79 @@ test('calculateUpdateType should handle all paths', () => {
expect(updateMetadata.calculateUpdateType('1.1.1', '1.1.2')).toEqual('version-update:semver-patch')
expect(updateMetadata.calculateUpdateType('1.1.1.1', '1.1.1.2')).toEqual('version-update:semver-patch')
})

test("handles - as separator", async () => {

Check failure on line 318 in src/dependabot/update_metadata.test.ts

View workflow job for this annotation

GitHub Actions / CI

Strings must use singlequote
const commitMessage =
'Bumps [stripe](https://github.com/stripe/stripe-python) from 3.5.0 to 8.1.0.\n' +
'- [Release notes](https://github.com/stripe/stripe-python/releases)\n' +
'- [Changelog](https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md)\n' +
'- [Commits](stripe/[email protected])\n' +
'\n' +
'---\n' +
'updated-dependencies:\n' +
'- dependency-name: stripe\n' +
' dependency-type: direct:production\n' +
' update-type: version-update:semver-major\n' +
'...\n' +
'\n' +
'Signed-off-by: dependabot[bot] <[email protected]>\n'

const getAlert = async () => Promise.resolve({ alertState: '', ghsaId: '', cvss: 0 })
const getScore = async () => Promise.resolve(0)
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot-pip-dirname-stripe-8.1.0', 'main', getAlert, getScore)

expect(updatedDependencies).toHaveLength(1)

expect(updatedDependencies[0].dependencyName).toEqual('stripe')
expect(updatedDependencies[0].dependencyType).toEqual('direct:production')
expect(updatedDependencies[0].updateType).toEqual('version-update:semver-major')
expect(updatedDependencies[0].directory).toEqual('/dirname')
expect(updatedDependencies[0].packageEcosystem).toEqual('pip')
expect(updatedDependencies[0].targetBranch).toEqual('main')
expect(updatedDependencies[0].prevVersion).toEqual('3.5.0')
expect(updatedDependencies[0].newVersion).toEqual('8.1.0')
expect(updatedDependencies[0].compatScore).toEqual(0)
expect(updatedDependencies[0].maintainerChanges).toEqual(false)
expect(updatedDependencies[0].alertState).toEqual('')
expect(updatedDependencies[0].ghsaId).toEqual('')
expect(updatedDependencies[0].cvss).toEqual(0)
expect(updatedDependencies[0].dependencyGroup).toEqual('')
});

Check failure on line 354 in src/dependabot/update_metadata.test.ts

View workflow job for this annotation

GitHub Actions / CI

Extra semicolon

test("it handles multi-segment directory with non-standard separator", async () => {

Check failure on line 356 in src/dependabot/update_metadata.test.ts

View workflow job for this annotation

GitHub Actions / CI

Strings must use singlequote
const commitMessage =
'Bumps [stripe](https://github.com/stripe/stripe-python) from 3.5.0 to 8.1.0.\n' +
'- [Release notes](https://github.com/stripe/stripe-python/releases)\n' +
'- [Changelog](https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md)\n' +
'- [Commits](stripe/[email protected])\n' +
'\n' +
'---\n' +
'updated-dependencies:\n' +
'- dependency-name: stripe\n' +
' dependency-type: direct:production\n' +
' update-type: version-update:semver-major\n' +
'...\n' +
'\n' +
'Signed-off-by: dependabot[bot] <[email protected]>\n'

const getAlert = async () => Promise.resolve({ alertState: '', ghsaId: '', cvss: 0 })
const getScore = async () => Promise.resolve(0)
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot|pip|dirname|dirname|stripe-8.1.0', 'main', getAlert, getScore)

expect(updatedDependencies).toHaveLength(1)

expect(updatedDependencies[0].dependencyName).toEqual('stripe')
expect(updatedDependencies[0].dependencyType).toEqual('direct:production')
expect(updatedDependencies[0].updateType).toEqual('version-update:semver-major')
expect(updatedDependencies[0].directory).toEqual('/dirname/dirname')
expect(updatedDependencies[0].packageEcosystem).toEqual('pip')
expect(updatedDependencies[0].targetBranch).toEqual('main')
expect(updatedDependencies[0].prevVersion).toEqual('3.5.0')
expect(updatedDependencies[0].newVersion).toEqual('8.1.0')
expect(updatedDependencies[0].compatScore).toEqual(0)
expect(updatedDependencies[0].maintainerChanges).toEqual(false)
expect(updatedDependencies[0].alertState).toEqual('')
expect(updatedDependencies[0].ghsaId).toEqual('')
expect(updatedDependencies[0].cvss).toEqual(0)
expect(updatedDependencies[0].dependencyGroup).toEqual('')
});

Check failure on line 392 in src/dependabot/update_metadata.test.ts

View workflow job for this annotation

GitHub Actions / CI

Extra semicolon
3 changes: 2 additions & 1 deletion src/dependabot/update_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ export async function parse (commitMessage: string, body: string, branchName: st
const prev = bumpFragment?.groups?.from ?? (updateFragment?.groups?.from ?? '')
const next = bumpFragment?.groups?.to ?? (updateFragment?.groups?.to ?? '')
const dependencyGroup = groupName?.groups?.name ?? ''
const delimIsDash = delim === '-'

if (data['updated-dependencies']) {
return await Promise.all(data['updated-dependencies'].map(async (dependency, index) => {
const dirname = `/${chunks.slice(2, -1 * (1 + (dependency['dependency-name'].match(/\//g) || []).length)).join(delim) || ''}`
const dirname = `/${chunks.slice(2, -1 * (delimIsDash ? 2 : 1 + (dependency['dependency-name'].match(/\//g) || []).length)).join('/') || ''}`
const lastVersion = index === 0 ? prev : ''
const nextVersion = index === 0 ? next : ''
const updateType = dependency['update-type'] || calculateUpdateType(lastVersion, nextVersion)
Expand Down

0 comments on commit a1e3f32

Please sign in to comment.