* Add [Conan] version service * Rework to use conan-center-index GitHub repo * Conditional mock based on presence of github token * Refactor yaml parsing into a helper function, move tests to .spec.js * remove custom version parsing * improve test data * updates from review Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import { renderVersionBadge } from '../version.js'
|
|
import { ConditionalGithubAuthV3Service } from '../github/github-auth-service.js'
|
|
import { fetchRepoContent } from '../github/github-common-fetch.js'
|
|
import { parseLatestVersionFromConfig } from './conan-version-helpers.js'
|
|
|
|
export default class ConanVersion extends ConditionalGithubAuthV3Service {
|
|
static category = 'version'
|
|
|
|
static route = { base: 'conan/v', pattern: ':packageName' }
|
|
|
|
static examples = [
|
|
{
|
|
title: 'Conan Center',
|
|
namedParams: { packageName: 'boost' },
|
|
staticPreview: renderVersionBadge({ version: '1.78.0' }),
|
|
keywords: ['c++'],
|
|
},
|
|
]
|
|
|
|
static defaultBadgeData = { label: 'conan' }
|
|
|
|
async handle({ packageName }) {
|
|
const configContent = await fetchRepoContent(this, {
|
|
user: 'conan-io',
|
|
repo: 'conan-center-index',
|
|
branch: 'master',
|
|
filename: `recipes/${packageName}/config.yml`,
|
|
})
|
|
|
|
const version = parseLatestVersionFromConfig(configContent)
|
|
|
|
return renderVersionBadge({ version })
|
|
}
|
|
}
|