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
68 lines
1.6 KiB
JavaScript
68 lines
1.6 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const { renderLicenseBadge } = require('../licenses')
|
|
const { GithubAuthService } = require('./github-auth-service')
|
|
const { documentation, errorMessagesFor } = require('./github-helpers')
|
|
|
|
const schema = Joi.object({
|
|
// Some repos do not have a license, in which case GitHub returns `{ license: null }`.
|
|
license: Joi.object({ spdx_id: Joi.string().required() }).allow(null),
|
|
}).required()
|
|
|
|
module.exports = class GithubLicense extends GithubAuthService {
|
|
static get category() {
|
|
return 'license'
|
|
}
|
|
|
|
static get route() {
|
|
return {
|
|
base: 'github/license',
|
|
pattern: ':user/:repo',
|
|
}
|
|
}
|
|
|
|
static get examples() {
|
|
return [
|
|
{
|
|
title: 'GitHub',
|
|
namedParams: { user: 'mashape', repo: 'apistatus' },
|
|
staticPreview: {
|
|
label: 'license',
|
|
message: 'MIT',
|
|
color: 'green',
|
|
},
|
|
keywords: ['license'],
|
|
documentation,
|
|
},
|
|
]
|
|
}
|
|
|
|
static get defaultBadgeData() {
|
|
return {
|
|
label: 'license',
|
|
}
|
|
}
|
|
|
|
static render({ license }) {
|
|
if (license === 'NOASSERTION') {
|
|
return { message: 'not identifiable by github' }
|
|
} else if (license) {
|
|
return renderLicenseBadge({ license })
|
|
} else {
|
|
return { message: 'not specified' }
|
|
}
|
|
}
|
|
|
|
async handle({ user, repo }) {
|
|
const { license: licenseObject } = await this._requestJson({
|
|
schema,
|
|
url: `/repos/${user}/${repo}`,
|
|
errorMessages: errorMessagesFor('repo not found'),
|
|
})
|
|
|
|
const license = licenseObject ? licenseObject.spdx_id : undefined
|
|
return this.constructor.render({ license })
|
|
}
|
|
}
|