Skip to content

Commit 52c0768

Browse files
authored
Throw error when a release with no assets are obtained (#678)
1 parent a3ec587 commit 52c0768

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

__tests__/main.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ beforeEach(() => {
3333
.get("/repos/robinraju/probable-potato/releases/68092191")
3434
.reply(200, readFromFile("1-release-latest.json"))
3535

36+
nock("https://api.github.com")
37+
.get("/repos/robinraju/foo-app/releases/tags/1.0.0")
38+
.reply(200, readFromFile("3-empty-assets.json"))
39+
3640
nock("https://api.github.com", {
3741
reqheaders: {accept: "application/octet-stream"}
3842
})
@@ -286,3 +290,21 @@ test("Download all archive files from public repo", async () => {
286290
fs.existsSync(path.join(downloadSettings.outFilePath, "test-3.txt"))
287291
).toBe(true)
288292
}, 10000)
293+
294+
test("Fail when a release with no assets are obtained", async () => {
295+
const downloadSettings: IReleaseDownloadSettings = {
296+
sourceRepoPath: "robinraju/foo-app",
297+
isLatest: false,
298+
tag: "1.0.0",
299+
id: "",
300+
fileName: "installer.zip",
301+
tarBall: false,
302+
zipBall: false,
303+
extractAssets: false,
304+
outFilePath: outputFilePath
305+
}
306+
const result = downloader.download(downloadSettings)
307+
await expect(result).rejects.toThrow(
308+
"No assets found in release Foo app - v1.0.0"
309+
)
310+
}, 10000)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"url": "https://api.github.com/repos/robinraju/foo-app/releases/68092191",
3+
"assets_url": "https://api.github.com/repos/robinraju/foo-app/releases/68092191/assets",
4+
"upload_url": "https://uploads.github.com/repos/robinraju/foo-app/releases/68092191/assets{?name,label}",
5+
"html_url": "https://github.com/robinraju/foo-app/releases/tag/1.0.1",
6+
"id": 68092191,
7+
"author": {},
8+
"node_id": "RE_kwDOHahpL84EDwEf",
9+
"tag_name": "1.0.0",
10+
"target_commitish": "main",
11+
"name": "Foo app - v1.0.0",
12+
"draft": false,
13+
"prerelease": false,
14+
"created_at": "2022-05-29T12:03:47Z",
15+
"published_at": "2022-05-29T12:04:42Z",
16+
"assets": [
17+
18+
],
19+
"tarball_url": "",
20+
"zipball_url": "",
21+
"body": ""
22+
}

dist/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/release-downloader.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ export class ReleaseDownloader {
203203
)
204204
}
205205
}
206+
} else {
207+
throw new Error(`No assets found in release ${ghRelease.name}`)
206208
}
207209

208210
if (downloadSettings.tarBall) {

0 commit comments

Comments
 (0)