* 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>
22 lines
568 B
JavaScript
22 lines
568 B
JavaScript
import yaml from 'js-yaml'
|
|
import { NotFound, InvalidResponse } from '../index.js'
|
|
import { latest } from '../version.js'
|
|
|
|
export function parseLatestVersionFromConfig(configYaml) {
|
|
let versions
|
|
try {
|
|
const config = yaml.load(configYaml)
|
|
versions = Object.keys(config.versions)
|
|
} catch (err) {
|
|
throw new InvalidResponse({
|
|
prettyMessage: 'invalid config.yml',
|
|
underlyingError: err,
|
|
})
|
|
}
|
|
const version = latest(versions)
|
|
if (version == null) {
|
|
throw new NotFound({ prettyMessage: 'no versions found' })
|
|
}
|
|
return version
|
|
}
|