mirror of
https://github.com/dependabot/fetch-metadata.git
synced 2026-03-12 18:07:12 -04:00
Ensure we fail out cleanly if there is an exception
This commit is contained in:
@@ -144,3 +144,16 @@ test('if there are multiple dependencies, it summarizes them', async () => {
|
||||
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:production')
|
||||
expect(core.setOutput).toBeCalledWith('update-type', 'version-update:semver-major')
|
||||
})
|
||||
|
||||
test("it sets the action to failed if there is an unexpected exception", async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('mock-token')
|
||||
jest.spyOn(dependabotCommits, 'getMessage').mockImplementation(jest.fn(
|
||||
() => Promise.reject( new Error("Something bad happened!") )
|
||||
))
|
||||
|
||||
await run()
|
||||
|
||||
expect(core.setFailed).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Something bad happened!')
|
||||
)
|
||||
})
|
||||
|
||||
28
src/main.ts
28
src/main.ts
@@ -16,24 +16,28 @@ export async function run (): Promise<void> {
|
||||
return
|
||||
}
|
||||
|
||||
const githubClient = github.getOctokit(token)
|
||||
try {
|
||||
const githubClient = github.getOctokit(token)
|
||||
|
||||
// Validate the job
|
||||
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context)
|
||||
// Validate the job
|
||||
const commitMessage = await verifiedCommits.getMessage(githubClient, github.context)
|
||||
|
||||
if (commitMessage) {
|
||||
// Parse metadata
|
||||
core.info('Parsing Dependabot metadata')
|
||||
if (commitMessage) {
|
||||
// Parse metadata
|
||||
core.info('Parsing Dependabot metadata')
|
||||
|
||||
const updatedDependencies = updateMetadata.parse(commitMessage)
|
||||
const updatedDependencies = updateMetadata.parse(commitMessage)
|
||||
|
||||
if (updatedDependencies.length > 0) {
|
||||
output.set(updatedDependencies)
|
||||
if (updatedDependencies.length > 0) {
|
||||
output.set(updatedDependencies)
|
||||
} else {
|
||||
core.setFailed('PR does not contain metadata, nothing to do.')
|
||||
}
|
||||
} else {
|
||||
core.setFailed('PR does not contain metadata, nothing to do.')
|
||||
core.setFailed('PR is not from Dependabot, nothing to do.')
|
||||
}
|
||||
} else {
|
||||
core.setFailed('PR is not from Dependabot, nothing to do.')
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user