fix: try/catch dockerfile replace (#1022)

This commit is contained in:
Rhys Arkins 2017-10-23 11:28:46 +02:00 committed by GitHub
parent 826753e329
commit a65a149b8d
2 changed files with 26 additions and 7 deletions

View file

@ -9,11 +9,16 @@ function setNewValue(
newVersion,
logger
) {
logger.debug(`setNewValue: ${depName} = ${newVersion}`);
const regexReplace = new RegExp(`(^|\n)FROM ${currentVersion}\n`);
const newFileContent = currentFileContent.replace(
regexReplace,
`$1FROM ${newVersion}\n`
);
return newFileContent;
try {
logger.debug(`setNewValue: ${depName} = ${newVersion}`);
const regexReplace = new RegExp(`(^|\n)FROM ${currentVersion}\n`);
const newFileContent = currentFileContent.replace(
regexReplace,
`$1FROM ${newVersion}\n`
);
return newFileContent;
} catch (err) {
logger.info({ err }, 'Error setting new Dockerfile value');
return null;
}
}

View file

@ -18,5 +18,19 @@ describe('workers/branch/dockerfile', () => {
);
expect(res).toMatchSnapshot();
});
it('returns null on error', () => {
const currentFileContent = null;
const depName = 'node';
const currentVersion = 'node:8';
const newVersion = 'node:8@sha256:abcdefghijklmnop';
const res = dockerfile.setNewValue(
currentFileContent,
depName,
currentVersion,
newVersion,
logger
);
expect(res).toBe(null);
});
});
});