-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
165 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ test('it returns the updated dependency information when there is a yaml fragmen | |
expect(updatedDependencies[0].alertState).toEqual('DISMISSED') | ||
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB') | ||
expect(updatedDependencies[0].cvss).toEqual(4.6) | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
}) | ||
|
||
test('it supports multiple dependencies within a single fragment', async () => { | ||
|
@@ -122,6 +123,8 @@ test('it supports multiple dependencies within a single fragment', async () => { | |
expect(updatedDependencies[0].alertState).toEqual('DISMISSED') | ||
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB') | ||
expect(updatedDependencies[0].cvss).toEqual(4.6) | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
|
||
expect(updatedDependencies[1].dependencyName).toEqual('coffeescript') | ||
expect(updatedDependencies[1].dependencyType).toEqual('indirect') | ||
|
@@ -135,6 +138,7 @@ test('it supports multiple dependencies within a single fragment', async () => { | |
expect(updatedDependencies[1].alertState).toEqual('') | ||
expect(updatedDependencies[1].ghsaId).toEqual('') | ||
expect(updatedDependencies[1].cvss).toEqual(0) | ||
expect(updatedDependencies[1].dependencyGroup).toEqual('') | ||
}) | ||
|
||
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 | |
expect(updatedDependencies[0].alertState).toEqual('DISMISSED') | ||
expect(updatedDependencies[0].ghsaId).toEqual('GHSA-III-BBB') | ||
expect(updatedDependencies[0].cvss).toEqual(4.6) | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
}) | ||
|
||
test('it supports returning information about grouped updates', async () => { | ||
const commitMessage = | ||
'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' + | ||
'\n' + | ||
'Updates `github.com/docker/cli` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Commits](docker/[email protected])\n' + | ||
'\n' + | ||
'Updates `github.com/docker/docker` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Release notes](https://github.com/docker/docker/releases)\n' + | ||
'- [Commits](moby/[email protected])\n' + | ||
'\n' + | ||
'Updates `github.com/moby/moby` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Release notes](https://github.com/moby/moby/releases)\n' + | ||
'- [Commits](moby/[email protected])\n' + | ||
'\n' + | ||
'---\n' + | ||
'updated-dependencies:\n' + | ||
'- dependency-name: github.com/docker/cli\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'- dependency-name: github.com/docker/docker\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'- dependency-name: github.com/moby/moby\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'...\n' + | ||
'\n' + | ||
'Signed-off-by: dependabot[bot] <[email protected]>\n' | ||
|
||
const getAlert = async () => Promise.resolve({ alertState: 'DISMISSED', ghsaId: 'GHSA-III-BBB', cvss: 4.6 }) | ||
const getScore = async () => Promise.resolve(43) | ||
const updatedDependencies = await updateMetadata.parse(commitMessage, '', 'dependabot/docker/gh-base-image/docker-1234566789', 'main', getAlert, getScore) | ||
|
||
expect(updatedDependencies).toHaveLength(3) | ||
|
||
expect(updatedDependencies[0].dependencyName).toEqual('github.com/docker/cli') | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('docker') | ||
}) | ||
|
||
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 | |
expect(updatedDependencies[0].alertState).toEqual('') | ||
expect(updatedDependencies[0].ghsaId).toEqual('') | ||
expect(updatedDependencies[0].cvss).toEqual(0) | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
}) | ||
|
||
test('it properly handles dependencies which contain slashes', async () => { | ||
|
@@ -247,6 +293,7 @@ test('it properly handles dependencies which contain slashes', async () => { | |
expect(updatedDependencies[0].alertState).toEqual('') | ||
expect(updatedDependencies[0].ghsaId).toEqual('') | ||
expect(updatedDependencies[0].cvss).toEqual(0) | ||
expect(updatedDependencies[0].dependencyGroup).toEqual('') | ||
}) | ||
|
||
test('calculateUpdateType should handle all paths', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi | |
newVersion: '4.2.2', | ||
compatScore: 0, | ||
maintainerChanges: false, | ||
dependencyGroup: '', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
|
@@ -129,6 +130,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi | |
expect(core.setOutput).toBeCalledWith('new-version', '4.2.2') | ||
expect(core.setOutput).toBeCalledWith('compatibility-score', 0) | ||
expect(core.setOutput).toBeCalledWith('maintainer-changes', false) | ||
expect(core.setOutput).toBeCalledWith('dependency-group', '') | ||
expect(core.setOutput).toBeCalledWith('alert-state', '') | ||
expect(core.setOutput).toBeCalledWith('ghsa-id', '') | ||
expect(core.setOutput).toBeCalledWith('cvss', 0) | ||
|
@@ -179,6 +181,7 @@ test('it sets the updated dependency as an output for subsequent actions when th | |
directory: '/', | ||
packageEcosystem: 'nuget', | ||
maintainerChanges: false, | ||
dependencyGroup: '', | ||
targetBranch: 'main', | ||
prevVersion: 'v4.0.1', | ||
newVersion: 'v4.2.2', | ||
|
@@ -200,11 +203,118 @@ test('it sets the updated dependency as an output for subsequent actions when th | |
expect(core.setOutput).toBeCalledWith('new-version', 'v4.2.2') | ||
expect(core.setOutput).toBeCalledWith('compatibility-score', 0) | ||
expect(core.setOutput).toBeCalledWith('maintainer-changes', false) | ||
expect(core.setOutput).toBeCalledWith('dependency-group', '') | ||
expect(core.setOutput).toBeCalledWith('alert-state', '') | ||
expect(core.setOutput).toBeCalledWith('ghsa-id', '') | ||
expect(core.setOutput).toBeCalledWith('cvss', 0) | ||
}) | ||
|
||
test('it supports returning information about grouped updates', async () => { | ||
const mockCommitMessage = | ||
'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' + | ||
'\n' + | ||
'Updates `github.com/docker/cli` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Commits](docker/[email protected])\n' + | ||
'\n' + | ||
'Updates `github.com/docker/docker` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Release notes](https://github.com/docker/docker/releases)\n' + | ||
'- [Commits](moby/[email protected])\n' + | ||
'\n' + | ||
'Updates `github.com/moby/moby` from 24.0.1+incompatible to 24.0.2+incompatible\n' + | ||
'- [Release notes](https://github.com/moby/moby/releases)\n' + | ||
'- [Commits](moby/[email protected])\n' + | ||
'\n' + | ||
'---\n' + | ||
'updated-dependencies:\n' + | ||
'- dependency-name: github.com/docker/cli\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'- dependency-name: github.com/docker/docker\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'- dependency-name: github.com/moby/moby\n' + | ||
' dependency-type: direct:production\n' + | ||
' update-type: version-update:semver-patch\n' + | ||
'...\n' + | ||
'\n' + | ||
'Signed-off-by: dependabot[bot] <[email protected]>\n' | ||
|
||
const mockAlert = { alertState: '', ghsaId: '', cvss: 0 } | ||
|
||
jest.spyOn(core, 'getInput').mockReturnValue('mock-token') | ||
jest.spyOn(util, 'getBranchNames').mockReturnValue({ headName: 'dependabot/docker/gh-base-image/docker-1234566789', baseName: 'trunk' }) | ||
jest.spyOn(dependabotCommits, 'getMessage').mockImplementation(jest.fn( | ||
() => Promise.resolve(mockCommitMessage) | ||
)) | ||
jest.spyOn(dependabotCommits, 'getAlert').mockImplementation(jest.fn( | ||
() => Promise.resolve(mockAlert) | ||
)) | ||
jest.spyOn(dependabotCommits, 'getCompatibility').mockImplementation(jest.fn( | ||
() => Promise.resolve(34) | ||
)) | ||
jest.spyOn(core, 'setOutput').mockImplementation(jest.fn()) | ||
|
||
await run() | ||
|
||
expect(core.startGroup).toHaveBeenCalledWith( | ||
expect.stringContaining('Outputting metadata for 3 updated dependencies') | ||
) | ||
|
||
expect(core.setOutput).toHaveBeenCalledWith( | ||
'updated-dependencies-json', | ||
[ | ||
{ | ||
dependencyName: 'github.com/docker/cli', | ||
dependencyType: 'direct:production', | ||
updateType: 'version-update:semver-patch', | ||
directory: '/', | ||
packageEcosystem: 'docker', | ||
targetBranch: 'trunk', | ||
prevVersion: '24.0.1', | ||
newVersion: '24.0.2', | ||
compatScore: 34, | ||
maintainerChanges: false, | ||
dependencyGroup: 'docker', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
}, | ||
{ | ||
dependencyName: 'github.com/docker/docker', | ||
dependencyType: 'direct:production', | ||
updateType: 'version-update:semver-patch', | ||
directory: '/', | ||
packageEcosystem: 'docker', | ||
targetBranch: 'trunk', | ||
prevVersion: '24.0.1', | ||
newVersion: '24.0.2', | ||
compatScore: 34, | ||
maintainerChanges: false, | ||
dependencyGroup: 'docker', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
}, | ||
{ | ||
dependencyName: 'github.com/moby/moby', | ||
dependencyType: 'direct:production', | ||
updateType: 'version-update:semver-patch', | ||
directory: '/', | ||
packageEcosystem: 'docker', | ||
targetBranch: 'trunk', | ||
prevVersion: '24.0.1', | ||
newVersion: '24.0.2', | ||
compatScore: 34, | ||
maintainerChanges: false, | ||
dependencyGroup: 'docker', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
} | ||
] | ||
) | ||
}) | ||
|
||
test('it sets the updated dependency as an output for subsequent actions when given a commit message for library', async () => { | ||
const mockCommitMessage = | ||
'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 | |
packageEcosystem: 'bundler', | ||
targetBranch: 'main', | ||
maintainerChanges: false, | ||
dependencyGroup: '', | ||
prevVersion: '1.30.1', | ||
newVersion: '1.31.0', | ||
compatScore: 0, | ||
|
@@ -273,6 +384,7 @@ test('it sets the updated dependency as an output for subsequent actions when gi | |
expect(core.setOutput).toBeCalledWith('new-version', '1.31.0') | ||
expect(core.setOutput).toBeCalledWith('compatibility-score', 0) | ||
expect(core.setOutput).toBeCalledWith('maintainer-changes', false) | ||
expect(core.setOutput).toBeCalledWith('dependency-group', '') | ||
expect(core.setOutput).toBeCalledWith('alert-state', '') | ||
expect(core.setOutput).toBeCalledWith('ghsa-id', '') | ||
expect(core.setOutput).toBeCalledWith('cvss', 0) | ||
|
@@ -332,6 +444,7 @@ test('if there are multiple dependencies, it summarizes them', async () => { | |
newVersion: '4.2.2', | ||
compatScore: 34, | ||
maintainerChanges: false, | ||
dependencyGroup: '', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
|
@@ -347,6 +460,7 @@ test('if there are multiple dependencies, it summarizes them', async () => { | |
newVersion: '', | ||
compatScore: 34, | ||
maintainerChanges: false, | ||
dependencyGroup: '', | ||
alertState: '', | ||
ghsaId: '', | ||
cvss: 0 | ||
|
@@ -364,6 +478,7 @@ test('if there are multiple dependencies, it summarizes them', async () => { | |
expect(core.setOutput).toBeCalledWith('new-version', '4.2.2') | ||
expect(core.setOutput).toBeCalledWith('compatibility-score', 34) | ||
expect(core.setOutput).toBeCalledWith('maintainer-changes', false) | ||
expect(core.setOutput).toBeCalledWith('dependency-group', '') | ||
expect(core.setOutput).toBeCalledWith('alert-state', '') | ||
expect(core.setOutput).toBeCalledWith('ghsa-id', '') | ||
expect(core.setOutput).toBeCalledWith('cvss', 0) | ||
|