2017-06-27 11:44:03 +00:00
|
|
|
const npmApi = require('../../api/npm');
|
|
|
|
const versions = require('./versions');
|
2017-06-30 12:04:46 +00:00
|
|
|
const schedule = require('./schedule');
|
2017-07-02 05:50:46 +00:00
|
|
|
const configParser = require('../../config');
|
2017-06-27 11:44:03 +00:00
|
|
|
|
2017-06-29 05:29:41 +00:00
|
|
|
let logger = require('../../logger');
|
2017-06-27 11:44:03 +00:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
findUpgrades,
|
|
|
|
};
|
|
|
|
|
2017-07-04 10:39:28 +00:00
|
|
|
// Returns all results for a given dependency config
|
2017-06-27 11:44:03 +00:00
|
|
|
async function findUpgrades(config) {
|
|
|
|
logger = config.logger || logger;
|
2017-06-30 14:04:23 +00:00
|
|
|
if (config.enabled === false) {
|
|
|
|
logger.debug('package is disabled');
|
|
|
|
return [];
|
|
|
|
}
|
2017-06-30 12:04:46 +00:00
|
|
|
// Check schedule
|
2017-07-03 08:31:36 +00:00
|
|
|
if (
|
|
|
|
config.schedule &&
|
|
|
|
config.schedule.length &&
|
|
|
|
schedule.isScheduledNow(config) === false
|
|
|
|
) {
|
2017-06-30 12:04:46 +00:00
|
|
|
logger.debug('Skipping package as it is not scheduled');
|
|
|
|
return [];
|
|
|
|
}
|
2017-07-04 10:39:28 +00:00
|
|
|
let results = [];
|
2017-06-27 11:44:03 +00:00
|
|
|
const npmDep = await npmApi.getDependency(config.depName, logger);
|
2017-07-04 10:39:28 +00:00
|
|
|
if (npmDep) {
|
|
|
|
results = await versions.determineUpgrades(npmDep, config);
|
|
|
|
if (results.length > 0) {
|
|
|
|
logger.info(
|
|
|
|
{ dependency: config.depName },
|
|
|
|
`${results.length} result(s): ${results.map(
|
|
|
|
upgrade => upgrade.newVersion
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
}
|
2017-06-27 11:44:03 +00:00
|
|
|
} else {
|
2017-07-04 10:39:28 +00:00
|
|
|
// If dependency lookup fails then warn and return
|
|
|
|
const result = {
|
2017-07-05 05:12:25 +00:00
|
|
|
type: 'error',
|
2017-07-04 10:39:28 +00:00
|
|
|
message: 'Failed to look up dependency',
|
|
|
|
};
|
|
|
|
logger.warn(result.message);
|
|
|
|
results = [result];
|
2017-06-27 11:44:03 +00:00
|
|
|
}
|
2017-07-04 10:39:28 +00:00
|
|
|
logger.debug(`${config.depName} results: ${JSON.stringify(results)}`);
|
|
|
|
// Flatten the result on top of config, add repositoryUrl
|
|
|
|
return results.map(result => {
|
|
|
|
const upg = configParser.mergeChildConfig(config, result);
|
|
|
|
upg.repositoryUrl = npmDep ? npmDep.repositoryUrl : '';
|
2017-07-03 08:31:36 +00:00
|
|
|
return configParser.filterConfig(upg, 'branch');
|
|
|
|
});
|
2017-06-27 11:44:03 +00:00
|
|
|
}
|