2018-11-09 12:51:23 +00:00
|
|
|
const { dependencyPattern } = require('./extract');
|
|
|
|
|
2018-04-28 18:39:07 +00:00
|
|
|
module.exports = {
|
|
|
|
updateDependency,
|
|
|
|
};
|
|
|
|
|
|
|
|
function updateDependency(fileContent, upgrade) {
|
|
|
|
try {
|
2018-06-04 03:48:20 +00:00
|
|
|
logger.debug(`pip_requirements.updateDependency(): ${upgrade.newValue}`);
|
2018-04-28 18:39:07 +00:00
|
|
|
const lines = fileContent.split('\n');
|
2018-10-23 04:09:33 +00:00
|
|
|
const oldValue = lines[upgrade.lineNumber];
|
|
|
|
const newValue = oldValue.replace(
|
2018-11-09 12:51:23 +00:00
|
|
|
new RegExp(dependencyPattern),
|
|
|
|
`$1$2${upgrade.newValue}`
|
2018-10-23 04:09:33 +00:00
|
|
|
);
|
|
|
|
lines[upgrade.lineNumber] = newValue;
|
2018-04-28 18:39:07 +00:00
|
|
|
return lines.join('\n');
|
|
|
|
} catch (err) {
|
|
|
|
logger.info({ err }, 'Error setting new package version');
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|