Skip to content

Commit

Permalink
Throw explicit error if list releases reponse doesn't have data
Browse files Browse the repository at this point in the history
  • Loading branch information
ncipollo committed Jan 12, 2025
1 parent e774b3e commit 033b82b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
28 changes: 27 additions & 1 deletion __tests__/Action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,32 @@ describe("Action", () => {

})

it('throws error when list has no data', async () => {

const action = createAction(true, true)
getMock.mockRejectedValue({status: 404})
const error = {
errors: [
{
code: 'already_exists'
}
]
}

createMock.mockRejectedValue(error)
listMock.mockResolvedValue({})
expect.hasAssertions()
try {
await action.perform()
} catch (error) {
expect(error).toEqual(Error("No releases found. Response: {}"))
}

expect(listMock).toBeCalled()
expect(createMock).not.toBeCalled()
expect(updateMock).not.toBeCalled()
})

it('throws error when update fails', async () => {
const action = createAction(true, true)

Expand Down Expand Up @@ -428,7 +454,7 @@ describe("Action", () => {
destroyArtifacts: artifactDestroyMock
}
})

const MockActionSkipper = jest.fn<ActionSkipper, any>(() => {
return {
shouldSkip: shouldSkipMock
Expand Down
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class Action {
const tag = this.inputs.tag;
const response = await this.releases.listReleases();
const releases = response.data;
if (!releases) {
throw new Error(`No releases found. Response: ${JSON.stringify(response)}`);
}
const draftRelease = releases.find(release => release.draft && release.tag_name == tag);
return draftRelease?.id;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class Action {
const tag = this.inputs.tag
const response = await this.releases.listReleases()
const releases = response.data
if(!releases) {
throw new Error(`No releases found. Response: ${JSON.stringify(response)}`)
}

const draftRelease = releases.find(release => release.draft && release.tag_name == tag)

return draftRelease?.id
Expand Down

0 comments on commit 033b82b

Please sign in to comment.