Skip to content

Commit

Permalink
Merge branch 'master' into libsio-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
repo-ranger[bot] authored Mar 7, 2022
2 parents 9e35f59 + 9186f0d commit dce1b15
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@fontsource/lato": "^4.5.2",
"@fontsource/lekton": "^4.5.3",
"@renovate/pep440": "^1.0.0",
"@sentry/node": "^6.18.1",
"@shields_io/camp": "^18.1.1",
"badge-maker": "file:badge-maker",
Expand Down
13 changes: 13 additions & 0 deletions services/color-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* including colours based off download count, version number, etc.
*/
import moment from 'moment'
import pep440 from '@renovate/pep440'

function version(version) {
if (typeof version !== 'string' && typeof version !== 'number') {
Expand All @@ -20,6 +21,17 @@ function version(version) {
}
}

function pep440VersionColor(version) {
if (!pep440.valid(version)) {
return 'lightgrey'
}
const parsedVersion = pep440.explain(version)
if (parsedVersion.is_prerelease || parsedVersion.public.startsWith('0.')) {
return 'orange'
}
return 'blue'
}

function floorCount(value, yellow, yellowgreen, green) {
if (value <= 0) {
return 'red'
Expand Down Expand Up @@ -106,6 +118,7 @@ function age(date) {

export {
version,
pep440VersionColor,
downloadCount,
coveragePercentage,
floorCount,
Expand Down
42 changes: 42 additions & 0 deletions services/color-formatters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
letterScore,
age,
version,
pep440VersionColor,
} from './color-formatters.js'

describe('Color formatters', function () {
Expand Down Expand Up @@ -106,4 +107,45 @@ describe('Color formatters', function () {
"Can't generate a version color for [object Object]"
)
})

test(pep440VersionColor, () => {
forCases([
given('1.0.1'),
given('v2.1.6'),
given('1.0.1+abcd'),
given('1.0'),
given('v1'),
given(9),
given(1.0),
]).expect('blue')

forCases([
given('1.0.1-rc1'),
given('1.0.1rc1'),
given('1.0.0-Beta'),
given('1.0.0Beta'),
given('1.1.0-alpha'),
given('1.1.0alpha'),
given('1.0.1-dev'),
given('1.0.1dev'),
given('2.1.6-b1'),
given('2.1.6b1'),
given('0.1.0'),
given('v0.1.0'),
given('v2.1.6-b1'),
given('0.1.0+abcd'),
given('2.1.6-b1+abcd'),
given('0.0.0'),
given(0.1),
given('0.9'),
]).expect('orange')

forCases([
given('6.0.0-SNAPSHOT'),
given('2.1.6-prerelease'),
given(true),
given(null),
given('cheese'),
]).expect('lightgrey')
})
})
4 changes: 3 additions & 1 deletion services/github/github-pipenv.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pep440VersionColor } from '../color-formatters.js'
import { renderVersionBadge } from '../version.js'
import { isLockfile, getDependencyVersion } from '../pipenv-helpers.js'
import { addv } from '../text-formatters.js'
Expand Down Expand Up @@ -80,6 +81,7 @@ class GithubPipenvLockedPythonVersion extends ConditionalGithubAuthV3Service {
version,
tag: branch,
defaultLabel: 'python',
versionFormatter: pep440VersionColor,
})
}

Expand Down Expand Up @@ -147,7 +149,7 @@ class GithubPipenvLockedDependencyVersion extends ConditionalGithubAuthV3Service
return {
label: dependency,
message: version ? addv(version) : ref,
color: 'blue',
color: version ? pep440VersionColor(version) : 'blue',
}
}

Expand Down
3 changes: 2 additions & 1 deletion services/piwheels/piwheels-version.service.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Joi from 'joi'
import { BaseJsonService, InvalidResponse } from '../index.js'
import { renderVersionBadge } from '../version.js'
import { pep440VersionColor } from '../color-formatters.js'

const schema = Joi.object({
releases: Joi.object()
Expand Down Expand Up @@ -46,7 +47,7 @@ export default class PiWheelsVersion extends BaseJsonService {
static defaultBadgeData = { label: 'piwheels' }

static render({ version }) {
return renderVersionBadge({ version })
return renderVersionBadge({ version, versionFormatter: pep440VersionColor })
}

async fetch({ wheel }) {
Expand Down
3 changes: 2 additions & 1 deletion services/pypi/pypi-version.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pep440VersionColor } from '../color-formatters.js'
import { renderVersionBadge } from '../version.js'
import PypiBase from './pypi-base.js'

Expand All @@ -19,7 +20,7 @@ export default class PypiVersion extends PypiBase {
static defaultBadgeData = { label: 'pypi' }

static render({ version }) {
return renderVersionBadge({ version })
return renderVersionBadge({ version, versionFormatter: pep440VersionColor })
}

async handle({ egg }) {
Expand Down
9 changes: 7 additions & 2 deletions services/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,16 @@ function rangeStart(v) {
return range.set[0][0].semver.version
}

function renderVersionBadge({ version, tag, defaultLabel }) {
function renderVersionBadge({
version,
tag,
defaultLabel,
versionFormatter = versionColor,
}) {
return {
label: tag ? `${defaultLabel}@${tag}` : undefined,
message: addv(version),
color: versionColor(version),
color: versionFormatter(version),
}
}

Expand Down

0 comments on commit dce1b15

Please sign in to comment.