Files
shields/services/github/github-helpers.js
Paul Melnikow fafb22efee Move "good" badge helpers from lib/ to services/ (#3101)
This moves a few helpers from `lib/` to `services/`:

build-status.js
build-status.spec.js
color-formatters.js
color-formatters.spec.js
contributor-count.js
licenses.js
licenses.spec.js
php-version.js
php-version.spec.js
text-formatters.js
text-formatters.spec.js
version.js
version.spec.js

And one from `lib/` to `core/`:

unhandled-rejection.spec.js

The diff is long, but the changes are straightforward.

Ref #2832
2019-02-27 20:47:46 -05:00

57 lines
1.3 KiB
JavaScript

'use strict'
const serverSecrets = require('../../lib/server-secrets')
const { colorScale } = require('../color-formatters')
const {
checkErrorResponse: standardCheckErrorResponse,
} = require('../../lib/error-helper')
const documentation = `
<p>
If your GitHub badge errors, it might be because you hit GitHub's rate limits.
<br>
You can increase Shields.io's rate limit by
<a href="https://img.shields.io/github-auth">going to this page</a> to add
Shields as a GitHub application on your GitHub account.
</p>
`
function stateColor(s) {
return { open: '2cbe4e', closed: 'cb2431', merged: '6f42c1' }[s]
}
function errorMessagesFor(notFoundMessage = 'repo not found') {
return {
404: notFoundMessage,
422: notFoundMessage,
}
}
function checkErrorResponse(
badgeData,
err,
res,
notFoundMessage = 'repo not found',
errorMessages = {}
) {
return standardCheckErrorResponse(badgeData, err, res, {
...errorMessages,
...errorMessagesFor(notFoundMessage),
})
}
const commentsColor = colorScale([1, 3, 10, 25], undefined, true)
function staticAuthConfigured() {
return Boolean(serverSecrets.gh_token)
}
module.exports = {
documentation,
stateColor,
commentsColor,
errorMessagesFor,
checkErrorResponse,
staticAuthConfigured,
}