-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
update.ts
30 lines (29 loc) · 973 Bytes
/
update.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { logger } from '../../logger';
import { UpdateDependencyConfig } from '../common';
import { regEx } from '../../util/regex';
export function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): string | null {
try {
const lineIdx = upgrade.managerData.lineNumber - 1;
logger.debug(`buildkite.updateDependency: ${upgrade.newValue}`);
const lines = fileContent.split('\n');
const lineToChange = lines[lineIdx];
const depLine = regEx(`^(\\s+[^#]+#)[^:]+(.*)$`);
if (!depLine.test(lineToChange)) {
logger.debug('No image line found');
return null;
}
const newLine = lineToChange.replace(depLine, `$1${upgrade.newValue}$2`);
if (newLine === lineToChange) {
logger.debug('No changes necessary');
return fileContent;
}
lines[lineIdx] = newLine;
return lines.join('\n');
} catch (err) {
logger.debug({ err }, 'Error setting new buildkite version');
return null;
}
}