renovate/lib/manager/droneci/update.ts
2020-02-24 09:26:42 +01:00

34 lines
1.1 KiB
TypeScript

import { logger } from '../../logger';
import { getNewFrom } from '../dockerfile/update';
import { UpdateDependencyConfig } from '../common';
export function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): string | null {
try {
const lines = fileContent.split('\n');
const lineToChange = lines[upgrade.managerData.lineNumber];
if (upgrade.depType === 'docker') {
const newFrom = getNewFrom(upgrade);
logger.debug(`droneci.updateDependency(): ${newFrom}`);
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');
}
logger.error('Unknown DroneCI depType');
return null;
} catch (err) {
logger.debug({ err }, 'Error setting new DroneCI image value');
return null;
}
}