Skip to content

Commit

Permalink
Throw error when a release with no assets are obtained (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
robinraju authored Jan 27, 2024
1 parent a3ec587 commit 52c0768
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
})
Expand Down Expand Up @@ -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)
22 changes: 22 additions & 0 deletions __tests__/resource/3-empty-assets.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
3 changes: 3 additions & 0 deletions dist/index.js

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

2 changes: 2 additions & 0 deletions src/release-downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ export class ReleaseDownloader {
)
}
}
} else {
throw new Error(`No assets found in release ${ghRelease.name}`)
}

if (downloadSettings.tarBall) {
Expand Down

0 comments on commit 52c0768

Please sign in to comment.