diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index b568888c..ad000ff2 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -33,6 +33,10 @@ beforeEach(() => { .get("/repos/robinraju/probable-potato/releases/68092191") .reply(200, readFromFile("1-release-latest.json")) + nock("https://api.github.com") + .get("/repos/robinraju/foo-app/releases/tags/1.0.0") + .reply(200, readFromFile("3-empty-assets.json")) + nock("https://api.github.com", { reqheaders: {accept: "application/octet-stream"} }) @@ -286,3 +290,21 @@ test("Download all archive files from public repo", async () => { fs.existsSync(path.join(downloadSettings.outFilePath, "test-3.txt")) ).toBe(true) }, 10000) + +test("Fail when a release with no assets are obtained", async () => { + const downloadSettings: IReleaseDownloadSettings = { + sourceRepoPath: "robinraju/foo-app", + isLatest: false, + tag: "1.0.0", + id: "", + fileName: "installer.zip", + tarBall: false, + zipBall: false, + extractAssets: false, + outFilePath: outputFilePath + } + const result = downloader.download(downloadSettings) + await expect(result).rejects.toThrow( + "No assets found in release Foo app - v1.0.0" + ) +}, 10000) diff --git a/__tests__/resource/3-empty-assets.json b/__tests__/resource/3-empty-assets.json new file mode 100644 index 00000000..2decc457 --- /dev/null +++ b/__tests__/resource/3-empty-assets.json @@ -0,0 +1,22 @@ +{ + "url": "https://api.github.com/repos/robinraju/foo-app/releases/68092191", + "assets_url": "https://api.github.com/repos/robinraju/foo-app/releases/68092191/assets", + "upload_url": "https://uploads.github.com/repos/robinraju/foo-app/releases/68092191/assets{?name,label}", + "html_url": "https://github.com/robinraju/foo-app/releases/tag/1.0.1", + "id": 68092191, + "author": {}, + "node_id": "RE_kwDOHahpL84EDwEf", + "tag_name": "1.0.0", + "target_commitish": "main", + "name": "Foo app - v1.0.0", + "draft": false, + "prerelease": false, + "created_at": "2022-05-29T12:03:47Z", + "published_at": "2022-05-29T12:04:42Z", + "assets": [ + + ], + "tarball_url": "", + "zipball_url": "", + "body": "" +} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 05f67a77..b7973ea2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -313,6 +313,9 @@ class ReleaseDownloader { } } } + else { + throw new Error(`No assets found in release ${ghRelease.name}`); + } if (downloadSettings.tarBall) { const repoName = downloadSettings.sourceRepoPath.split("/")[1]; downloads.push({ diff --git a/src/release-downloader.ts b/src/release-downloader.ts index 71224af8..7378c64b 100644 --- a/src/release-downloader.ts +++ b/src/release-downloader.ts @@ -203,6 +203,8 @@ export class ReleaseDownloader { ) } } + } else { + throw new Error(`No assets found in release ${ghRelease.name}`) } if (downloadSettings.tarBall) {