mirror of
https://github.com/badges/shields.git
synced 2025-04-18 19:44:04 +03:00
* [PyPI] Fix license for packages following PEP 639 PEP 639 states that the preferred way of documenting a Python project's license is an SPDX expression in a `License-Expression` metadata field. PyPI exposes this information in `info.license_expression` in its JSON data. Fixes: #11000 * add license_expression to pypi response schema * move comments inline into the relevant blocks * assign both license and license_expression to intermediate variables * always pass a license_expression in test input objects --------- Co-authored-by: chris48s <git@chris-shaw.dev>
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
import Joi from 'joi'
|
|
import config from 'config'
|
|
import { optionalUrl } from '../validators.js'
|
|
import { BaseJsonService, queryParam, pathParam } from '../index.js'
|
|
|
|
const schema = Joi.object({
|
|
info: Joi.object({
|
|
version: Joi.string().required(),
|
|
// https://github.com/badges/shields/issues/2022
|
|
// https://github.com/badges/shields/issues/7728
|
|
license: Joi.string().allow('').allow(null),
|
|
license_expression: Joi.string().allow('').allow(null),
|
|
classifiers: Joi.array().items(Joi.string()).required(),
|
|
}).required(),
|
|
urls: Joi.array()
|
|
.items(
|
|
Joi.object({
|
|
packagetype: Joi.string().required(),
|
|
}),
|
|
)
|
|
.required(),
|
|
}).required()
|
|
|
|
export const queryParamSchema = Joi.object({
|
|
pypiBaseUrl: optionalUrl,
|
|
}).required()
|
|
|
|
export const pypiPackageParam = pathParam({
|
|
name: 'packageName',
|
|
example: 'Django',
|
|
})
|
|
|
|
export const pypiBaseUrlParam = queryParam({
|
|
name: 'pypiBaseUrl',
|
|
example: 'https://pypi.org',
|
|
})
|
|
|
|
export const pypiGeneralParams = [pypiPackageParam, pypiBaseUrlParam]
|
|
|
|
export default class PypiBase extends BaseJsonService {
|
|
static buildRoute(base) {
|
|
return {
|
|
base,
|
|
pattern: ':egg+',
|
|
queryParamSchema,
|
|
}
|
|
}
|
|
|
|
async fetch({ egg, pypiBaseUrl = null }) {
|
|
const defaultpypiBaseUrl =
|
|
config.util.toObject().public.services.pypi.baseUri
|
|
pypiBaseUrl = pypiBaseUrl || defaultpypiBaseUrl
|
|
return this._requestJson({
|
|
schema,
|
|
url: `${pypiBaseUrl}/pypi/${egg}/json`,
|
|
httpErrors: { 404: 'package or version not found' },
|
|
})
|
|
}
|
|
}
|