Files
shields/services/scoop/scoop-license.service.js
Ambati Mohan Kumar 5e40080099 [Scoop] Added scoop-license badge. (#10627)
* scoop-license service is added.

* refactored scoop badges - added scoop base

* refactor - description changed to base class.

* refactor - description changed to base class.

* Update services/scoop/scoop-license.tester.js

Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>

* refactor - buckets variable is moved to base class, also updated tester with createTestService.

* moved queryParamSchema to base class.

---------

Co-authored-by: jNullj <15849761+jNullj@users.noreply.github.com>
2024-10-25 16:35:16 +00:00

64 lines
1.6 KiB
JavaScript

import Joi from 'joi'
import { pathParam, queryParam } from '../index.js'
import { renderLicenseBadge } from '../licenses.js'
import toArray from '../../core/base-service/to-array.js'
import { queryParamSchema, description, ScoopBase } from './scoop-base.js'
const scoopLicenseSchema = Joi.object({
license: Joi.alternatives()
.try(
Joi.string().required(),
Joi.object({
identifier: Joi.string().required(),
}),
)
.required(),
}).required()
export default class ScoopLicense extends ScoopBase {
static category = 'license'
static route = {
base: 'scoop/l',
pattern: ':app',
queryParamSchema,
}
static openApi = {
'/scoop/l/{app}': {
get: {
summary: 'Scoop License',
description,
parameters: [
pathParam({ name: 'app', example: 'ngrok' }),
queryParam({
name: 'bucket',
description:
"App's containing bucket. Can either be a name (e.g `extras`) or a URL to a GitHub Repo (e.g `https://github.com/jewlexx/personal-scoop`)",
example: 'extras',
}),
],
},
},
}
static defaultBadgeData = { label: 'license' }
static render({ licenses }) {
return renderLicenseBadge({ licenses })
}
async handle({ app }, queryParams) {
const { license } = await this.fetch(
{ app, schema: scoopLicenseSchema },
queryParams,
)
const licenses = toArray(license).map(license =>
typeof license === 'string' ? license : license.identifier,
)
return this.constructor.render({ licenses })
}
}