renovate/lib/manager/docker-compose/update.ts

30 lines
1,005 B
TypeScript

import { logger } from '../../logger';
import { getNewFrom } from '../dockerfile/update';
import { UpdateDependencyConfig } from '../common';
export function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): string {
try {
const newFrom = getNewFrom(upgrade);
logger.debug(`docker-compose.updateDependency(): ${newFrom}`);
const lines = fileContent.split('\n');
const lineToChange = lines[upgrade.managerData.lineNumber];
const imageLine = /^(\s*image:\s*'?"?)[^\s'"]+('?"?\s*)/;
if (!imageLine.test(lineToChange)) {
logger.debug('No image line found');
return null;
}
const newLine = lineToChange.replace(imageLine, `$1${newFrom}$2`);
if (newLine === lineToChange) {
logger.debug('No changes necessary');
return fileContent;
}
lines[upgrade.managerData.lineNumber] = newLine;
return lines.join('\n');
} catch (err) {
logger.info({ err }, 'Error setting new Dockerfile value');
return null;
}
}