Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improve directory name extraction from branch name. #495

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 () => {
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/stripe-python@v3.5.0...v8.1.0)\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] <support@github.com>\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('')
})

test('it handles multi-segment directory with non-standard separator', async () => {
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/stripe-python@v3.5.0...v8.1.0)\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] <support@github.com>\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('')
})
5 changes: 3 additions & 2 deletions 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('/') || ''}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi I'm trying to wrap my head around this change. Would you mind explaining how it works and what featch-metadata was doing before?

Also, I'm surprised that we didn't have to update any existing tests! I guess we didn't have any test cases for separators?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I just saw your examples in #493 and #494 !

So I'm guessing this change makes fetch-metadata not include the extra word after the separator. That makes sense!

const lastVersion = index === 0 ? prev : ''
const nextVersion = index === 0 ? next : ''
const updateType = dependency['update-type'] || calculateUpdateType(lastVersion, nextVersion)
Expand All @@ -64,7 +65,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
newVersion: nextVersion,
compatScore: await scoreFn(dependency['dependency-name'], lastVersion, nextVersion, chunks[1]),
maintainerChanges: newMaintainer,
dependencyGroup: dependencyGroup,
dependencyGroup,
...await lookupFn(dependency['dependency-name'], lastVersion, dirname)
}
}))
Expand Down
Loading