all-badge-examples is a common cause of merge conflicts. It’s difficult to adjust the badge categorization in that file – or to understand the diff – because it requires moving a block from one point to another. It’s much easier to edit a badge’s category in one place. This starts the process of breaking up what’s left of that file, following up on the work from #1931. New-style services can only be in one category, which means legacy service examples have to be split along category lines. I split out separate legacy service classes where I could do so easily, leaving behind the ones which require more work, for one reason or another.
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const LegacyService = require('../legacy-service')
|
|
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
|
|
|
|
module.exports = class Codetally extends LegacyService {
|
|
static get category() {
|
|
return 'funding'
|
|
}
|
|
|
|
static get url() {
|
|
return {
|
|
base: 'codetally',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'Codetally',
|
|
previewUrl: 'triggerman722/colorstrap',
|
|
},
|
|
]
|
|
}
|
|
|
|
static registerLegacyRouteHandler({ camp, cache }) {
|
|
camp.route(
|
|
/^\/codetally\/(.*)\/(.*)\.(svg|png|gif|jpg|json)$/,
|
|
cache((data, match, sendBadge, request) => {
|
|
const owner = match[1] // eg, triggerman722.
|
|
const repo = match[2] // eg, colorstrap
|
|
const format = match[3]
|
|
const apiUrl =
|
|
'http://www.codetally.com/formattedshield/' + owner + '/' + repo
|
|
const badgeData = getBadgeData('codetally', data)
|
|
request(apiUrl, (err, res, buffer) => {
|
|
if (err != null) {
|
|
badgeData.text[1] = 'inaccessible'
|
|
sendBadge(format, badgeData)
|
|
return
|
|
}
|
|
try {
|
|
const data = JSON.parse(buffer)
|
|
badgeData.text[1] =
|
|
' ' + data.currency_sign + data.amount + ' ' + data.multiplier
|
|
badgeData.colorscheme = null
|
|
badgeData.colorB = '#2E8B57'
|
|
sendBadge(format, badgeData)
|
|
} catch (e) {
|
|
badgeData.text[1] = 'invalid'
|
|
sendBadge(format, badgeData)
|
|
}
|
|
})
|
|
})
|
|
)
|
|
}
|
|
}
|