Skip to content

Commit

Permalink
Refactor render and handle to thrown an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Aug 1, 2022
1 parent 57f17cf commit 10d027b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 11 additions & 12 deletions services/pypi/pypi-framework-versions.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { InvalidResponse } from '../index.js'
import PypiBase from './pypi-base.js'
import { sortPypiVersions, parseClassifiers } from './pypi-helpers.js'

Expand Down Expand Up @@ -73,18 +74,10 @@ export default class PypiFrameworkVersion extends PypiBase {
static render({ name, versions }) {
name = name ? name.toLowerCase() : ''
const label = `${name} versions`
if (versions.length > 0) {
return {
label,
message: sortPypiVersions(versions).join(' | '),
color: 'blue',
}
} else {
return {
label,
message: 'missing',
color: 'red',
}
return {
label,
message: sortPypiVersions(versions).join(' | '),
color: 'blue',
}
}

Expand All @@ -99,6 +92,12 @@ export default class PypiFrameworkVersion extends PypiBase {
const packageData = await this.fetch({ egg: packageName })
const versions = parseClassifiers(packageData, regex)

if (versions.length === 0) {
throw new InvalidResponse({
prettyMessage: `${name} versions are missing for ${packageName}`,
})
}

return this.constructor.render({ name, versions })
}
}
5 changes: 4 additions & 1 deletion services/pypi/pypi-framework-versions.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ t.create('supported django versions (valid, no package version specified)')

t.create('supported django versions (no versions specified)')
.get('/django/django/1.11.json')
.expectBadge({ label: 'django versions', message: 'missing' })
.expectBadge({
label: 'versions',
message: 'Django versions are missing for django/1.11',
})

t.create('supported django versions (invalid)')
.get('/django/not-a-package.json')
Expand Down

0 comments on commit 10d027b

Please sign in to comment.