Skip to content

Commit

Permalink
fix invalid semver in release. closes #61
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Jun 21, 2018
1 parent 6c19efa commit d4c005f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ class Updates {

const releases = await res.json()
for (const release of releases) {
if (release.draft || release.prerelease) continue
if (
!semver.valid(release.tag_name) ||
release.draft ||
release.prerelease
) {
continue
}
for (const asset of release.assets) {
const platform = assetPlatform(asset.name)
if (platform && !latest[platform]) {
Expand Down
27 changes: 26 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ nock('https://api.github.com')
]
}
])
.get('/repos/owner/repo-invalid-semver/releases?per_page=100')
.reply(200, [
{
name: 'name',
tag_name: 'invalid-semver',
body: 'notes',
assets: [
{
name: 'win32-ia32.zip',
browser_download_url: 'win32-ia32.zip'
},
{
name: 'win32-x64.zip',
browser_download_url: 'win32-x64.zip'
}
]
}
])
nock('https://github.com')
.get('/owner/repo/releases/download/1.0.0/RELEASES')
.reply(200, 'HASH name.nupkg NUMBER')
Expand Down Expand Up @@ -175,13 +193,20 @@ test('Updates', async t => {
}
})

await t.test('invalid semver', async t => {
await t.test('invalid semver in request', async t => {
const res = await fetch(`${address}/owner/repo/darwin/latest`)
t.equal(res.status, 400)
const body = await res.text()
t.equal(body, 'Invalid SemVer: "latest"')
})

await t.test('invalid semver in release', async t => {
const res = await fetch(
`${address}/owner/repo-invalid-semver/darwin/0.0.0`
)
t.equal(res.status, 404)
})

await t.test('exists but has no releases', async t => {
for (let i = 0; i < 2; i++) {
const res = await fetch(
Expand Down

0 comments on commit d4c005f

Please sign in to comment.