Refactor nuget nycrc opencollective opm services (#5598)

This commit is contained in:
Thakur Karthik
2020-09-26 05:36:10 +05:30
committed by GitHub
parent 1b91b03b2b
commit bc2832e566
9 changed files with 136 additions and 208 deletions

View File

@@ -123,20 +123,14 @@ function createServiceFamily({
}
class NugetVersionService extends Base {
static get name() {
return `${name}Version`
}
static name = `${name}Version`
static get category() {
return 'version'
}
static category = 'version'
static get route() {
return {
base: `${serviceBaseUrl}/v`,
pattern: ':packageName',
queryParamSchema,
}
static route = {
base: `${serviceBaseUrl}/v`,
pattern: ':packageName',
queryParamSchema,
}
static get examples() {
@@ -157,10 +151,8 @@ function createServiceFamily({
]
}
static get defaultBadgeData() {
return {
label: defaultLabel,
}
static defaultBadgeData = {
label: defaultLabel,
}
static render(props) {
@@ -193,19 +185,13 @@ function createServiceFamily({
})
class NugetDownloadService extends Base {
static get name() {
return `${name}Downloads`
}
static name = `${name}Downloads`
static get category() {
return 'downloads'
}
static category = 'downloads'
static get route() {
return {
base: serviceBaseUrl,
pattern: 'dt/:packageName',
}
static route = {
base: serviceBaseUrl,
pattern: 'dt/:packageName',
}
static get examples() {

View File

@@ -159,25 +159,17 @@ function createServiceFamily({
withFeed = true,
}) {
class NugetVersionService extends BaseJsonService {
static get category() {
return 'version'
}
static category = 'version'
static get route() {
return buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('(v|vpre)', 'which')
.push('(.+?)', 'packageName')
.toObject()
}
static route = buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('(v|vpre)', 'which')
.push('(.+?)', 'packageName')
.toObject()
static get examples() {
return []
}
static examples = []
static get defaultBadgeData() {
return {
label: defaultLabel,
}
static defaultBadgeData = {
label: defaultLabel,
}
static render(props) {
@@ -216,20 +208,14 @@ function createServiceFamily({
}
class NugetDownloadService extends BaseJsonService {
static get category() {
return 'downloads'
}
static category = 'downloads'
static get route() {
return buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('dt')
.push('(.+?)', 'packageName')
.toObject()
}
static route = buildRoute({ serviceBaseUrl, withTenant, withFeed })
.push('dt')
.push('(.+?)', 'packageName')
.toObject()
static get examples() {
return []
}
static examples = []
static render(props) {
return renderDownloadBadge(props)

View File

@@ -14,35 +14,31 @@ const {
})
class NugetVersionService extends Version {
static get examples() {
return [
{
title: 'Nuget',
pattern: 'v/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ version: '5.2.4' }),
},
{
title: 'Nuget (with prereleases)',
pattern: 'vpre/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ version: '5.2.5-preview1' }),
},
]
}
static examples = [
{
title: 'Nuget',
pattern: 'v/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ version: '5.2.4' }),
},
{
title: 'Nuget (with prereleases)',
pattern: 'vpre/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ version: '5.2.5-preview1' }),
},
]
}
class NugetDownloadService extends Downloads {
static get examples() {
return [
{
title: 'Nuget',
pattern: 'dt/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ downloads: 49e6 }),
},
]
}
static examples = [
{
title: 'Nuget',
pattern: 'dt/:packageName',
namedParams: { packageName: 'Microsoft.AspNet.Mvc' },
staticPreview: this.render({ downloads: 49e6 }),
},
]
}
module.exports = { NugetVersionService, NugetDownloadService }

View File

@@ -36,43 +36,35 @@ const documentation = `<p>
const validThresholds = ['branches', 'lines', 'functions']
module.exports = class Nycrc extends ConditionalGithubAuthV3Service {
static get category() {
return 'coverage'
static category = 'coverage'
static route = {
base: 'nycrc',
// TODO: eventually add support for .yml and .yaml:
pattern: ':user/:repo',
queryParamSchema: Joi.object({
config: Joi.string()
.regex(/(.*\.nycrc)|(.*\.json$)/)
.default('.nycrc'),
// Allow the default threshold detection logic to be overridden, .e.g.,
// favoring lines over branches:
preferredThreshold: Joi.string()
.optional()
.allow(...validThresholds),
}).required(),
}
static get route() {
return {
base: 'nycrc',
// TODO: eventually add support for .yml and .yaml:
pattern: ':user/:repo',
queryParamSchema: Joi.object({
config: Joi.string()
.regex(/(.*\.nycrc)|(.*\.json$)/)
.default('.nycrc'),
// Allow the default threshold detection logic to be overridden, .e.g.,
// favoring lines over branches:
preferredThreshold: Joi.string()
.optional()
.allow(...validThresholds),
}).required(),
}
}
static examples = [
{
title: 'nycrc config on GitHub',
namedParams: { user: 'yargs', repo: 'yargs' },
queryParams: { config: '.nycrc', preferredThreshold: 'lines' },
staticPreview: this.render({ coverage: 92 }),
documentation,
},
]
static get examples() {
return [
{
title: 'nycrc config on GitHub',
namedParams: { user: 'yargs', repo: 'yargs' },
queryParams: { config: '.nycrc', preferredThreshold: 'lines' },
staticPreview: this.render({ coverage: 92 }),
documentation,
},
]
}
static get defaultBadgeData() {
return { label: 'min coverage' }
}
static defaultBadgeData = { label: 'min coverage' }
static render({ coverage }) {
return {

View File

@@ -3,25 +3,19 @@
const OpencollectiveBase = require('./opencollective-base')
module.exports = class OpencollectiveAll extends OpencollectiveBase {
static get route() {
return this.buildRoute('all')
}
static route = this.buildRoute('all')
static get examples() {
return [
{
title: 'Open Collective backers and sponsors',
namedParams: { collective: 'shields' },
staticPreview: this.render(35),
keywords: ['opencollective'],
},
]
}
static examples = [
{
title: 'Open Collective backers and sponsors',
namedParams: { collective: 'shields' },
staticPreview: this.render(35),
keywords: ['opencollective'],
},
]
static get defaultBadgeData() {
return {
label: 'backers and sponsors',
}
static defaultBadgeData = {
label: 'backers and sponsors',
}
async handle({ collective }) {

View File

@@ -3,25 +3,19 @@
const OpencollectiveBase = require('./opencollective-base')
module.exports = class OpencollectiveBackers extends OpencollectiveBase {
static get route() {
return this.buildRoute('backers')
}
static route = this.buildRoute('backers')
static get examples() {
return [
{
title: 'Open Collective backers',
namedParams: { collective: 'shields' },
staticPreview: this.render(25),
keywords: ['opencollective'],
},
]
}
static examples = [
{
title: 'Open Collective backers',
namedParams: { collective: 'shields' },
staticPreview: this.render(25),
keywords: ['opencollective'],
},
]
static get defaultBadgeData() {
return {
label: 'backers',
}
static defaultBadgeData = {
label: 'backers',
}
async handle({ collective }) {

View File

@@ -6,26 +6,20 @@ const documentation = `<h3>How to get the tierId</h3>
<p>According to <a target="_blank" href="https://developer.opencollective.com/#/api/collectives?id=get-members-per-tier">open collectives documentation</a>, you can find the tierId by looking at the URL after clicking on a Tier Card on the collective page. (e.g. tierId for https://opencollective.com/shields/order/2988 is 2988)</p>`
module.exports = class OpencollectiveByTier extends OpencollectiveBase {
static get route() {
return this.buildRoute('tier', true)
}
static route = this.buildRoute('tier', true)
static get examples() {
return [
{
title: 'Open Collective members by tier',
namedParams: { collective: 'shields', tierId: '2988' },
staticPreview: this.render(8, 'monthly backers'),
keywords: ['opencollective'],
documentation,
},
]
}
static examples = [
{
title: 'Open Collective members by tier',
namedParams: { collective: 'shields', tierId: '2988' },
staticPreview: this.render(8, 'monthly backers'),
keywords: ['opencollective'],
documentation,
},
]
static get defaultBadgeData() {
return {
label: 'open collective',
}
static defaultBadgeData = {
label: 'open collective',
}
async handle({ collective, tierId }) {

View File

@@ -3,25 +3,19 @@
const OpencollectiveBase = require('./opencollective-base')
module.exports = class OpencollectiveSponsors extends OpencollectiveBase {
static get route() {
return this.buildRoute('sponsors')
}
static route = this.buildRoute('sponsors')
static get examples() {
return [
{
title: 'Open Collective sponsors',
namedParams: { collective: 'shields' },
staticPreview: this.render(10),
keywords: ['opencollective'],
},
]
}
static examples = [
{
title: 'Open Collective sponsors',
namedParams: { collective: 'shields' },
staticPreview: this.render(10),
keywords: ['opencollective'],
},
]
static get defaultBadgeData() {
return {
label: 'sponsors',
}
static defaultBadgeData = {
label: 'sponsors',
}
async handle({ collective }) {

View File

@@ -4,34 +4,26 @@ const { renderVersionBadge } = require('../version')
const { BaseService, NotFound, InvalidResponse } = require('..')
module.exports = class OpmVersion extends BaseService {
static get category() {
return 'version'
static category = 'version'
static route = {
base: 'opm/v',
pattern: ':user/:moduleName',
}
static get route() {
return {
base: 'opm/v',
pattern: ':user/:moduleName',
}
}
static get examples() {
return [
{
title: 'OPM',
namedParams: {
user: 'openresty',
moduleName: 'lua-resty-lrucache',
},
staticPreview: renderVersionBadge({ version: 'v0.08' }),
static examples = [
{
title: 'OPM',
namedParams: {
user: 'openresty',
moduleName: 'lua-resty-lrucache',
},
]
}
staticPreview: renderVersionBadge({ version: 'v0.08' }),
},
]
static get defaultBadgeData() {
return {
label: 'opm',
}
static defaultBadgeData = {
label: 'opm',
}
async fetch({ user, moduleName }) {