Deprecate [issuestats] service (#2038)

This commit is contained in:
Pyves
2018-09-01 20:53:52 +01:00
committed by GitHub
parent b6ba720fae
commit 7153ed0bd1
4 changed files with 29 additions and 90 deletions

View File

@@ -966,22 +966,6 @@ const allBadgeExamples = [
previewUrl:
'/waffle/label/evancohen/smart-mirror/status%3A%20in%20progress.svg',
},
{
title: 'Issue Stats',
previewUrl: '/issuestats/i/github/expressjs/express.svg',
},
{
title: 'Issue Stats (long form)',
previewUrl: '/issuestats/i/long/github/expressjs/express.svg',
},
{
title: 'Pull Request Stats',
previewUrl: '/issuestats/p/github/expressjs/express.svg',
},
{
title: 'Pull Request Stats (long form)',
previewUrl: '/issuestats/p/long/github/expressjs/express.svg',
},
],
},
{

View File

@@ -11,6 +11,7 @@ const deprecatedServices = {
magnumci: new Date('2018-07-08'),
bithound: new Date('2018-07-08'),
versioneye: new Date('2018-08-20'),
issuestats: new Date('2018-09-01'),
}
module.exports = {

View File

@@ -1,77 +1,11 @@
'use strict'
const LegacyService = require('../legacy-service')
const {
makeBadgeData: getBadgeData,
makeLabel: getLabel,
} = require('../../lib/badge-data')
const deprecatedService = require('../deprecated-service')
module.exports = class IssueStats extends LegacyService {
static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/issuestats\/([^/]+)(\/long)?\/([^/]+)\/(.+)\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const type = match[1] // e.g. `i` for Issue or `p` for PR
const longForm = !!match[2]
const host = match[3] // e.g. `github`
const userRepo = match[4] // e.g. `ruby/rails`
const format = match[5]
const badgeData = getBadgeData('Issue Stats', data)
// Maps type name from URL to JSON property name prefix for badge data
const typeToPropPrefix = {
i: 'issue',
p: 'pr',
}
const typePropPrefix = typeToPropPrefix[type]
if (typePropPrefix === undefined) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
return
}
const url = 'http://issuestats.com/' + host + '/' + userRepo
const qs = { format: 'json' }
if (!longForm) {
qs.concise = true
}
const options = {
method: 'GET',
url: url,
qs: qs,
gzip: true,
json: true,
}
request(options, (err, res, json) => {
if (err != null || res.statusCode >= 500) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
return
}
if (res.statusCode >= 400 || !json || typeof json !== 'object') {
badgeData.text[1] = 'not found'
sendBadge(format, badgeData)
return
}
try {
const label = json[typePropPrefix + '_badge_preamble']
const value = json[typePropPrefix + '_badge_words']
const color = json[typePropPrefix + '_badge_color']
if (label != null) badgeData.text[0] = getLabel(label, data)
badgeData.text[1] = value || 'invalid'
if (color != null) badgeData.colorscheme = color
sendBadge(format, badgeData)
} catch (e) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
}
})
})
)
}
}
module.exports = deprecatedService({
url: {
base: 'issuestats',
format: '(?:[^/]+)(?:/long)?/(?:[^/]+)/(?:.+)',
},
label: 'issue stats',
})

View File

@@ -0,0 +1,20 @@
'use strict'
const ServiceTester = require('../service-tester')
const t = new ServiceTester({ id: 'issuestats', title: 'Issue Stats' })
module.exports = t
t.create('no longer available (previously issue analysis)')
.get('/i/github/expressjs/express.json')
.expectJSON({
name: 'issue stats',
value: 'no longer available',
})
t.create('no longer available (previously pull request analysis, long form)')
.get('/p/long/github/expressjs/express.json')
.expectJSON({
name: 'issue stats',
value: 'no longer available',
})