* Build(deps): bump path-to-regexp from 5.0.0 to 6.2.0 Bumps [path-to-regexp](https://github.com/pillarjs/path-to-regexp) from 5.0.0 to 6.2.0. - [Release notes](https://github.com/pillarjs/path-to-regexp/releases) - [Changelog](https://github.com/pillarjs/path-to-regexp/blob/master/History.md) - [Commits](https://github.com/pillarjs/path-to-regexp/compare/v5.0.0...v6.2.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * deps: apply path-to-regexp breaking changes * fix: path-to-regexp types in frontend Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Caleb Cartwright <caleb.cartwright@outlook.com> Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
94 lines
2.6 KiB
JavaScript
94 lines
2.6 KiB
JavaScript
'use strict'
|
|
|
|
const Joi = require('joi')
|
|
const { renderVersionBadge } = require('../version')
|
|
const { InvalidResponse } = require('..')
|
|
const { ConditionalGithubAuthV3Service } = require('./github-auth-service')
|
|
const { fetchRepoContent } = require('./github-common-fetch')
|
|
const { documentation } = require('./github-helpers')
|
|
|
|
const queryParamSchema = Joi.object({
|
|
filename: Joi.string(),
|
|
}).required()
|
|
|
|
const versionRegExp = /^Version:[\s]*(.+)$/m
|
|
|
|
module.exports = class GithubRPackageVersion extends (
|
|
ConditionalGithubAuthV3Service
|
|
) {
|
|
static category = 'version'
|
|
|
|
static route = {
|
|
base: 'github/r-package/v',
|
|
pattern: ':user/:repo/:branch*',
|
|
queryParamSchema,
|
|
}
|
|
|
|
static examples = [
|
|
{
|
|
title: 'GitHub R package version',
|
|
pattern: ':user/:repo',
|
|
namedParams: { user: 'mixOmicsTeam', repo: 'mixOmics' },
|
|
staticPreview: this.render({ version: '6.10.9' }),
|
|
documentation,
|
|
},
|
|
{
|
|
title: 'GitHub R package version (branch)',
|
|
pattern: ':user/:repo/:branch',
|
|
namedParams: { user: 'mixOmicsTeam', repo: 'mixOmics', branch: 'master' },
|
|
staticPreview: this.render({ version: '6.10.9', branch: 'master' }),
|
|
documentation,
|
|
},
|
|
{
|
|
title: 'GitHub R package version (subdirectory of monorepo)',
|
|
pattern: ':user/:repo',
|
|
namedParams: { user: 'mixOmicsTeam', repo: 'mixOmics' },
|
|
queryParams: { filename: 'subdirectory/DESCRIPTION' },
|
|
staticPreview: this.render({ version: '6.10.9' }),
|
|
documentation,
|
|
},
|
|
{
|
|
title: 'GitHub R package version (branch & subdirectory of monorepo)',
|
|
pattern: ':user/:repo/:branch',
|
|
namedParams: { user: 'mixOmicsTeam', repo: 'mixOmics', branch: 'master' },
|
|
queryParams: { filename: 'subdirectory/DESCRIPTION' },
|
|
staticPreview: this.render({ version: '6.10.9', branch: 'master' }),
|
|
documentation,
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'R' }
|
|
|
|
static render({ version, branch }) {
|
|
return renderVersionBadge({
|
|
version,
|
|
tag: branch,
|
|
defaultLabel: 'R',
|
|
})
|
|
}
|
|
|
|
static transform(content, filename) {
|
|
const match = versionRegExp.exec(content)
|
|
if (!match) {
|
|
throw new InvalidResponse({
|
|
prettyMessage: `Version missing in ${filename}`,
|
|
})
|
|
}
|
|
|
|
return {
|
|
version: match[1],
|
|
}
|
|
}
|
|
|
|
async handle({ user, repo, branch }, { filename = 'DESCRIPTION' }) {
|
|
const content = await fetchRepoContent(this, {
|
|
user,
|
|
repo,
|
|
branch,
|
|
filename,
|
|
})
|
|
const { version } = this.constructor.transform(content, filename)
|
|
return this.constructor.render({ version, branch })
|
|
}
|
|
}
|