convert [lgtm liberapay librariesio localizely luarocks] classes to static props (#5587)

* convert [homebrew,hsts,itunes,jenkins,jetbrains] classes to static props

* Run the prettier across the files

* Updated the correct values in logos.spec.js

* revert back the logos.spec.js changes

* Completed refactoring of [lgtm liberapay librariesio localizely luarocks]

* Convert defaultBadgeData to object

Co-authored-by: Jabbar Memon <jabbar@zoop.one>
This commit is contained in:
Jabbar Memon
2020-09-22 08:41:33 +05:30
committed by GitHub
parent 5a3064d0d4
commit 76f13aa686
11 changed files with 244 additions and 314 deletions

View File

@@ -4,31 +4,25 @@ const { metric } = require('../text-formatters')
const LgtmBaseService = require('./lgtm-base') const LgtmBaseService = require('./lgtm-base')
module.exports = class LgtmAlerts extends LgtmBaseService { module.exports = class LgtmAlerts extends LgtmBaseService {
static get route() { static route = {
return { base: 'lgtm/alerts',
base: 'lgtm/alerts', pattern: this.pattern,
pattern: this.pattern,
}
} }
static get examples() { static examples = [
return [ {
{ title: 'LGTM Alerts',
title: 'LGTM Alerts', namedParams: {
namedParams: { host: 'github',
host: 'github', user: 'apache',
user: 'apache', repo: 'cloudstack',
repo: 'cloudstack',
},
staticPreview: this.render({ alerts: 2488 }),
}, },
] staticPreview: this.render({ alerts: 2488 }),
} },
]
static get defaultBadgeData() { static defaultBadgeData = {
return { label: 'lgtm alerts',
label: 'lgtm alerts',
}
} }
static getColor({ alerts }) { static getColor({ alerts }) {

View File

@@ -3,37 +3,33 @@
const LgtmBaseService = require('./lgtm-base') const LgtmBaseService = require('./lgtm-base')
module.exports = class LgtmGrade extends LgtmBaseService { module.exports = class LgtmGrade extends LgtmBaseService {
static get route() { static route = {
return { base: 'lgtm/grade',
base: 'lgtm/grade', pattern: `:language/${this.pattern}`,
pattern: `:language/${this.pattern}`,
}
} }
static get examples() { static examples = [
return [ {
{ title: 'LGTM Grade',
title: 'LGTM Grade', namedParams: {
namedParams: { language: 'java',
language: 'java', host: 'github',
host: 'github', user: 'apache',
user: 'apache', repo: 'cloudstack',
repo: 'cloudstack',
},
staticPreview: this.render({
language: 'java',
data: {
languages: [
{
lang: 'java',
grade: 'C',
},
],
},
}),
}, },
] staticPreview: this.render({
} language: 'java',
data: {
languages: [
{
lang: 'java',
grade: 'C',
},
],
},
}),
},
]
static getLabel({ language }) { static getLabel({ language }) {
const languageLabel = (() => { const languageLabel = (() => {

View File

@@ -4,23 +4,19 @@ const { InvalidResponse } = require('..')
const { renderCurrencyBadge, LiberapayBase } = require('./liberapay-base') const { renderCurrencyBadge, LiberapayBase } = require('./liberapay-base')
module.exports = class LiberapayGives extends LiberapayBase { module.exports = class LiberapayGives extends LiberapayBase {
static get route() { static route = this.buildRoute('gives')
return this.buildRoute('gives')
}
static get examples() { static examples = [
return [ {
{ title: 'Liberapay giving',
title: 'Liberapay giving', namedParams: { entity: 'Changaco' },
namedParams: { entity: 'Changaco' }, staticPreview: renderCurrencyBadge({
staticPreview: renderCurrencyBadge({ label: 'gives',
label: 'gives', amount: '2.58',
amount: '2.58', currency: 'EUR',
currency: 'EUR', }),
}), },
}, ]
]
}
async handle({ entity }) { async handle({ entity }) {
const data = await this.fetch({ entity }) const data = await this.fetch({ entity })

View File

@@ -5,19 +5,15 @@ const { InvalidResponse } = require('..')
const { LiberapayBase } = require('./liberapay-base') const { LiberapayBase } = require('./liberapay-base')
module.exports = class LiberapayGoal extends LiberapayBase { module.exports = class LiberapayGoal extends LiberapayBase {
static get route() { static route = this.buildRoute('goal')
return this.buildRoute('goal')
}
static get examples() { static examples = [
return [ {
{ title: 'Liberapay goal progress',
title: 'Liberapay goal progress', namedParams: { entity: 'Changaco' },
namedParams: { entity: 'Changaco' }, staticPreview: this.render({ percentAchieved: 33 }),
staticPreview: this.render({ percentAchieved: 33 }), },
}, ]
]
}
static render({ percentAchieved }) { static render({ percentAchieved }) {
return { return {

View File

@@ -5,19 +5,15 @@ const { colorScale } = require('../color-formatters')
const { LiberapayBase } = require('./liberapay-base') const { LiberapayBase } = require('./liberapay-base')
module.exports = class LiberapayPatrons extends LiberapayBase { module.exports = class LiberapayPatrons extends LiberapayBase {
static get route() { static route = this.buildRoute('patrons')
return this.buildRoute('patrons')
}
static get examples() { static examples = [
return [ {
{ title: 'Liberapay patrons',
title: 'Liberapay patrons', namedParams: { entity: 'Changaco' },
namedParams: { entity: 'Changaco' }, staticPreview: this.render({ patrons: 10 }),
staticPreview: this.render({ patrons: 10 }), },
}, ]
]
}
static render({ patrons }) { static render({ patrons }) {
return { return {

View File

@@ -4,23 +4,19 @@ const { InvalidResponse } = require('..')
const { renderCurrencyBadge, LiberapayBase } = require('./liberapay-base') const { renderCurrencyBadge, LiberapayBase } = require('./liberapay-base')
module.exports = class LiberapayReceives extends LiberapayBase { module.exports = class LiberapayReceives extends LiberapayBase {
static get route() { static route = this.buildRoute('receives')
return this.buildRoute('receives')
}
static get examples() { static examples = [
return [ {
{ title: 'Liberapay receiving',
title: 'Liberapay receiving', namedParams: { entity: 'Changaco' },
namedParams: { entity: 'Changaco' }, staticPreview: renderCurrencyBadge({
staticPreview: renderCurrencyBadge({ label: 'receives',
label: 'receives', amount: '98.32',
amount: '98.32', currency: 'EUR',
currency: 'EUR', }),
}), },
}, ]
]
}
async handle({ entity }) { async handle({ entity }) {
const data = await this.fetch({ entity }) const data = await this.fetch({ entity })

View File

@@ -19,75 +19,69 @@ const schema = Joi.object({
}).required() }).required()
class LibrariesIoProjectDependencies extends BaseJsonService { class LibrariesIoProjectDependencies extends BaseJsonService {
static get category() { static category = 'dependencies'
return 'dependencies'
static route = {
base: 'librariesio/release',
pattern: ':platform/:scope(@[^/]+)?/:packageName/:version?',
} }
static get route() { static examples = [
return { {
base: 'librariesio/release', title: 'Libraries.io dependency status for latest release',
pattern: ':platform/:scope(@[^/]+)?/:packageName/:version?', pattern: ':platform/:packageName',
} namedParams: {
} platform: 'hex',
packageName: 'phoenix',
static get examples() {
return [
{
title: 'Libraries.io dependency status for latest release',
pattern: ':platform/:packageName',
namedParams: {
platform: 'hex',
packageName: 'phoenix',
},
staticPreview: renderDependenciesBadge({
deprecatedCount: 0,
outdatedCount: 1,
}),
}, },
{ staticPreview: renderDependenciesBadge({
title: 'Libraries.io dependency status for specific release', deprecatedCount: 0,
pattern: ':platform/:packageName/:version', outdatedCount: 1,
namedParams: { }),
platform: 'hex', },
packageName: 'phoenix', {
version: '1.0.3', title: 'Libraries.io dependency status for specific release',
}, pattern: ':platform/:packageName/:version',
staticPreview: renderDependenciesBadge({ namedParams: {
deprecatedCount: 0, platform: 'hex',
outdatedCount: 3, packageName: 'phoenix',
}), version: '1.0.3',
}, },
{ staticPreview: renderDependenciesBadge({
title: deprecatedCount: 0,
'Libraries.io dependency status for latest release, scoped npm package', outdatedCount: 3,
pattern: ':platform/:scope/:packageName', }),
namedParams: { },
platform: 'npm', {
scope: '@babel', title:
packageName: 'core', 'Libraries.io dependency status for latest release, scoped npm package',
}, pattern: ':platform/:scope/:packageName',
staticPreview: renderDependenciesBadge({ namedParams: {
deprecatedCount: 8, platform: 'npm',
outdatedCount: 0, scope: '@babel',
}), packageName: 'core',
}, },
{ staticPreview: renderDependenciesBadge({
title: deprecatedCount: 8,
'Libraries.io dependency status for specific release, scoped npm package', outdatedCount: 0,
pattern: ':platform/:scope/:packageName/:version', }),
namedParams: { },
platform: 'npm', {
scope: '@babel', title:
packageName: 'core', 'Libraries.io dependency status for specific release, scoped npm package',
version: '7.0.0', pattern: ':platform/:scope/:packageName/:version',
}, namedParams: {
staticPreview: renderDependenciesBadge({ platform: 'npm',
deprecatedCount: 12, scope: '@babel',
outdatedCount: 0, packageName: 'core',
}), version: '7.0.0',
}, },
] staticPreview: renderDependenciesBadge({
} deprecatedCount: 12,
outdatedCount: 0,
}),
},
]
async handle({ platform, scope, packageName, version = 'latest' }) { async handle({ platform, scope, packageName, version = 'latest' }) {
const url = `https://libraries.io/api/${encodeURIComponent(platform)}/${ const url = `https://libraries.io/api/${encodeURIComponent(platform)}/${
@@ -106,29 +100,23 @@ class LibrariesIoProjectDependencies extends BaseJsonService {
} }
class LibrariesIoRepoDependencies extends BaseJsonService { class LibrariesIoRepoDependencies extends BaseJsonService {
static get category() { static category = 'dependencies'
return 'dependencies'
static route = {
base: 'librariesio/github',
pattern: ':user/:repo',
} }
static get route() { static examples = [
return { {
base: 'librariesio/github', title: 'Libraries.io dependency status for GitHub repo',
pattern: ':user/:repo', namedParams: {
} user: 'phoenixframework',
} repo: 'phoenix',
static get examples() {
return [
{
title: 'Libraries.io dependency status for GitHub repo',
namedParams: {
user: 'phoenixframework',
repo: 'phoenix',
},
staticPreview: renderDependenciesBadge({ outdatedCount: 325 }),
}, },
] staticPreview: renderDependenciesBadge({ outdatedCount: 325 }),
} },
]
async handle({ user, repo }) { async handle({ user, repo }) {
const url = `https://libraries.io/api/github/${encodeURIComponent( const url = `https://libraries.io/api/github/${encodeURIComponent(

View File

@@ -6,45 +6,37 @@ const { fetchProject } = require('./librariesio-common')
// https://libraries.io/api#project-dependent-repositories // https://libraries.io/api#project-dependent-repositories
module.exports = class LibrariesIoDependentRepos extends BaseJsonService { module.exports = class LibrariesIoDependentRepos extends BaseJsonService {
static get category() { static category = 'other'
return 'other'
static route = {
base: 'librariesio/dependent-repos',
pattern: ':platform/:scope(@[^/]+)?/:packageName',
} }
static get route() { static examples = [
return { {
base: 'librariesio/dependent-repos', title: 'Dependent repos (via libraries.io)',
pattern: ':platform/:scope(@[^/]+)?/:packageName', pattern: ':platform/:packageName',
} namedParams: {
} platform: 'npm',
packageName: 'got',
static get examples() {
return [
{
title: 'Dependent repos (via libraries.io)',
pattern: ':platform/:packageName',
namedParams: {
platform: 'npm',
packageName: 'got',
},
staticPreview: this.render({ dependentReposCount: 84000 }),
}, },
{ staticPreview: this.render({ dependentReposCount: 84000 }),
title: 'Dependent repos (via libraries.io), scoped npm package', },
pattern: ':platform/:scope/:packageName', {
namedParams: { title: 'Dependent repos (via libraries.io), scoped npm package',
platform: 'npm', pattern: ':platform/:scope/:packageName',
scope: '@babel', namedParams: {
packageName: 'core', platform: 'npm',
}, scope: '@babel',
staticPreview: this.render({ dependentReposCount: 50 }), packageName: 'core',
}, },
] staticPreview: this.render({ dependentReposCount: 50 }),
} },
]
static get defaultBadgeData() { static defaultBadgeData = {
return { label: 'dependent repos',
label: 'dependent repos',
}
} }
static render({ dependentReposCount }) { static render({ dependentReposCount }) {

View File

@@ -6,45 +6,37 @@ const { fetchProject } = require('./librariesio-common')
// https://libraries.io/api#project-dependents // https://libraries.io/api#project-dependents
module.exports = class LibrariesIoDependents extends BaseJsonService { module.exports = class LibrariesIoDependents extends BaseJsonService {
static get category() { static category = 'other'
return 'other'
static route = {
base: 'librariesio/dependents',
pattern: ':platform/:scope(@[^/]+)?/:packageName',
} }
static get route() { static examples = [
return { {
base: 'librariesio/dependents', title: 'Dependents (via libraries.io)',
pattern: ':platform/:scope(@[^/]+)?/:packageName', pattern: ':platform/:packageName',
} namedParams: {
} platform: 'npm',
packageName: 'got',
static get examples() {
return [
{
title: 'Dependents (via libraries.io)',
pattern: ':platform/:packageName',
namedParams: {
platform: 'npm',
packageName: 'got',
},
staticPreview: this.render({ dependentCount: 2000 }),
}, },
{ staticPreview: this.render({ dependentCount: 2000 }),
title: 'Dependents (via libraries.io), scoped npm package', },
pattern: ':platform/:scope/:packageName', {
namedParams: { title: 'Dependents (via libraries.io), scoped npm package',
platform: 'npm', pattern: ':platform/:scope/:packageName',
scope: '@babel', namedParams: {
packageName: 'core', platform: 'npm',
}, scope: '@babel',
staticPreview: this.render({ dependentCount: 94 }), packageName: 'core',
}, },
] staticPreview: this.render({ dependentCount: 94 }),
} },
]
static get defaultBadgeData() { static defaultBadgeData = {
return { label: 'dependents',
label: 'dependents',
}
} }
static render({ dependentCount }) { static render({ dependentCount }) {

View File

@@ -7,45 +7,37 @@ const { fetchProject } = require('./librariesio-common')
const sourceRankColor = colorScale([10, 15, 20, 25, 30]) const sourceRankColor = colorScale([10, 15, 20, 25, 30])
module.exports = class LibrariesIoSourcerank extends BaseJsonService { module.exports = class LibrariesIoSourcerank extends BaseJsonService {
static get category() { static category = 'rating'
return 'rating'
static route = {
base: 'librariesio/sourcerank',
pattern: ':platform/:scope(@[^/]+)?/:packageName',
} }
static get route() { static examples = [
return { {
base: 'librariesio/sourcerank', title: 'Libraries.io SourceRank',
pattern: ':platform/:scope(@[^/]+)?/:packageName', pattern: ':platform/:packageName',
} namedParams: {
} platform: 'npm',
packageName: 'got',
static get examples() {
return [
{
title: 'Libraries.io SourceRank',
pattern: ':platform/:packageName',
namedParams: {
platform: 'npm',
packageName: 'got',
},
staticPreview: this.render({ rank: 25 }),
}, },
{ staticPreview: this.render({ rank: 25 }),
title: 'Libraries.io SourceRank, scoped npm package', },
pattern: ':platform/:scope/:packageName', {
namedParams: { title: 'Libraries.io SourceRank, scoped npm package',
platform: 'npm', pattern: ':platform/:scope/:packageName',
scope: '@babel', namedParams: {
packageName: 'core', platform: 'npm',
}, scope: '@babel',
staticPreview: this.render({ rank: 3 }), packageName: 'core',
}, },
] staticPreview: this.render({ rank: 3 }),
} },
]
static get defaultBadgeData() { static defaultBadgeData = {
return { label: 'sourcerank',
label: 'sourcerank',
}
} }
static render({ rank }) { static render({ rank }) {

View File

@@ -15,34 +15,26 @@ const schema = Joi.object({
}).required() }).required()
module.exports = class Luarocks extends BaseJsonService { module.exports = class Luarocks extends BaseJsonService {
static get category() { static category = 'version'
return 'version'
static route = {
base: 'luarocks/v',
pattern: ':user/:moduleName/:version?',
} }
static get route() { static examples = [
return { {
base: 'luarocks/v', title: 'LuaRocks',
pattern: ':user/:moduleName/:version?', namedParams: {
} user: 'mpeterv',
} moduleName: 'luacheck',
static get examples() {
return [
{
title: 'LuaRocks',
namedParams: {
user: 'mpeterv',
moduleName: 'luacheck',
},
staticPreview: this.render({ version: '0.23.0-1' }),
}, },
] staticPreview: this.render({ version: '0.23.0-1' }),
} },
]
static get defaultBadgeData() { static defaultBadgeData = {
return { label: 'luarocks',
label: 'luarocks',
}
} }
static render({ version }) { static render({ version }) {