fix(GitHubDownloads): type error on latest with pre-downloads (#4030)

This commit is contained in:
Caleb Cartwright
2019-09-15 20:08:39 -05:00
committed by repo-ranger[bot]
parent 9fe4d739b0
commit 76b2e2634a
2 changed files with 10 additions and 0 deletions

View File

@@ -191,6 +191,11 @@ module.exports = class GithubDownloads extends GithubAuthV3Service {
options: { qs: { per_page: 1 } },
errorMessages: errorMessagesFor('repo not found'),
})
// Note that the API will return an empty array if there are no releases
// https://github.com/badges/shields/issues/3786
if (!latestReleaseIncludingPrereleases) {
throw new NotFound({ prettyMessage: 'no releases' })
}
releases = [latestReleaseIncludingPrereleases]
} else if (tag) {
const wantedRelease = await this._requestJson({

View File

@@ -32,6 +32,11 @@ t.create('downloads-pre for latest release')
.get('/downloads-pre/photonstorm/phaser/latest/total.json')
.expectBadge({ label: 'downloads@latest', message: isMetric })
// https://github.com/badges/shields/issues/3786
t.create('downloads-pre for latest release (no-releases)')
.get('/downloads-pre/badges/shields/latest/total.json')
.expectBadge({ label: 'downloads', message: 'no releases' })
t.create('downloads for release without slash')
.get('/downloads/atom/atom/v0.190.0/total.json')
.expectBadge({ label: 'downloads@v0.190.0', message: isMetric })