mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-13 07:26:26 +00:00
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
const URL = require('url');
|
|
const got = require('got');
|
|
const parse = require('github-url-from-git');
|
|
const { isVersion, sortVersions } = require('../versioning')('semverComposer');
|
|
|
|
module.exports = {
|
|
getDependency,
|
|
};
|
|
|
|
async function getDependency(purl) {
|
|
const { fullname: name } = purl;
|
|
logger.trace(`getDependency(${name})`);
|
|
|
|
const regUrl = 'https://packagist.org';
|
|
|
|
const pkgUrl = URL.resolve(regUrl, `/packages/${name}.json`);
|
|
|
|
try {
|
|
const res = (await got(pkgUrl, {
|
|
json: true,
|
|
retries: 5,
|
|
})).body.package;
|
|
|
|
// Simplify response before caching and returning
|
|
const dep = {
|
|
name: res.name,
|
|
versions: {},
|
|
};
|
|
|
|
if (res.repository) {
|
|
dep.repositoryUrl = parse(res.repository);
|
|
}
|
|
const versions = Object.keys(res.versions)
|
|
.filter(isVersion)
|
|
.sort(sortVersions);
|
|
|
|
dep.releases = versions.map(version => {
|
|
const release = res.versions[version];
|
|
dep.homepage = dep.homepage || release.homepage;
|
|
return {
|
|
version: version.replace(/^v/, ''),
|
|
gitRef: version,
|
|
releaseTimestamp: release.time,
|
|
};
|
|
});
|
|
dep.homepage = dep.homepage || res.repository;
|
|
logger.trace({ dep }, 'dep');
|
|
return dep;
|
|
} catch (err) {
|
|
if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
|
|
logger.info({ name }, `Dependency lookup failure: not found`);
|
|
logger.debug({
|
|
err,
|
|
});
|
|
return null;
|
|
}
|
|
logger.warn({ err, name }, 'packagist registry failure: Unknown error');
|
|
return null;
|
|
}
|
|
}
|