Skip to content
Snippets Groups Projects
Commit c711fb4c authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: getArtifacts returns an array

parent 13cc5b5b
No related branches found
No related tags found
No related merge requests found
...@@ -144,12 +144,14 @@ async function getArtifacts( ...@@ -144,12 +144,14 @@ async function getArtifacts(
} }
} }
logger.debug('Returning updated Gemfile.lock'); logger.debug('Returning updated Gemfile.lock');
return { return [
{
file: { file: {
name: lockFileName, name: lockFileName,
contents: await fs.readFile(localLockFileName, 'utf8'), contents: await fs.readFile(localLockFileName, 'utf8'),
}, },
}; },
];
} catch (err) { } catch (err) {
if ( if (
err.stdout && err.stdout &&
......
...@@ -15,11 +15,13 @@ async function getArtifacts(cargoTomlFileName) { ...@@ -15,11 +15,13 @@ async function getArtifacts(cargoTomlFileName) {
{ err, message: err.message }, { err, message: err.message },
'Failed to update Cargo lock file' 'Failed to update Cargo lock file'
); );
return { return [
{
artifactError: { artifactError: {
lockFile: cargoLockFileName, lockFile: cargoLockFileName,
stderr: err.message, stderr: err.message,
}, },
}; },
];
} }
} }
...@@ -151,12 +151,14 @@ async function getArtifacts( ...@@ -151,12 +151,14 @@ async function getArtifacts(
} }
} }
logger.debug('Returning updated composer.lock'); logger.debug('Returning updated composer.lock');
return { return [
{
file: { file: {
name: lockFileName, name: lockFileName,
contents: await fs.readFile(localLockFileName, 'utf8'), contents: await fs.readFile(localLockFileName, 'utf8'),
}, },
}; },
];
} catch (err) { } catch (err) {
if ( if (
err.message && err.message &&
...@@ -171,11 +173,13 @@ async function getArtifacts( ...@@ -171,11 +173,13 @@ async function getArtifacts(
'Failed to generate composer.lock' 'Failed to generate composer.lock'
); );
} }
return { return [
{
artifactError: { artifactError: {
lockFile: lockFileName, lockFile: lockFileName,
stderr: err.message, stderr: err.message,
}, },
}; },
];
} }
} }
...@@ -93,19 +93,23 @@ async function getArtifacts( ...@@ -93,19 +93,23 @@ async function getArtifacts(
} }
} }
logger.debug('Returning updated go.sum'); logger.debug('Returning updated go.sum');
return { return [
{
file: { file: {
name: sumFileName, name: sumFileName,
contents: await fs.readFile(localGoSumFileName, 'utf8'), contents: await fs.readFile(localGoSumFileName, 'utf8'),
}, },
}; },
];
} catch (err) { } catch (err) {
logger.warn({ err, message: err.message }, 'Failed to update go.sum'); logger.warn({ err, message: err.message }, 'Failed to update go.sum');
return { return [
{
artifactError: { artifactError: {
lockFile: sumFileName, lockFile: sumFileName,
stderr: err.message, stderr: err.message,
}, },
}; },
];
} }
} }
...@@ -86,19 +86,23 @@ async function getArtifacts( ...@@ -86,19 +86,23 @@ async function getArtifacts(
} }
} }
logger.debug('Returning updated Pipfile.lock'); logger.debug('Returning updated Pipfile.lock');
return { return [
{
file: { file: {
name: lockFileName, name: lockFileName,
contents: await fs.readFile(localLockFileName, 'utf8'), contents: await fs.readFile(localLockFileName, 'utf8'),
}, },
}; },
];
} catch (err) { } catch (err) {
logger.warn({ err, message: err.message }, 'Failed to update Pipfile.lock'); logger.warn({ err, message: err.message }, 'Failed to update Pipfile.lock');
return { return [
{
artifactError: { artifactError: {
lockFile: lockFileName, lockFile: lockFileName,
stderr: err.message, stderr: err.message,
}, },
}; },
];
} }
} }
const is = require('@sindresorhus/is');
const { get } = require('../../manager'); const { get } = require('../../manager');
module.exports = { module.exports = {
...@@ -63,13 +64,14 @@ async function getUpdatedPackageFiles(config) { ...@@ -63,13 +64,14 @@ async function getUpdatedPackageFiles(config) {
const updatedDeps = packageFileUpdatedDeps[packageFile.name]; const updatedDeps = packageFileUpdatedDeps[packageFile.name];
const getArtifacts = get(manager, 'getArtifacts'); const getArtifacts = get(manager, 'getArtifacts');
if (getArtifacts) { if (getArtifacts) {
const res = await getArtifacts( const results = await getArtifacts(
packageFile.name, packageFile.name,
updatedDeps, updatedDeps,
packageFile.contents, packageFile.contents,
config config
); );
if (res) { if (is.nonEmptyArray(results)) {
for (const res of results) {
const { file, artifactError } = res; const { file, artifactError } = res;
if (file) { if (file) {
updatedArtifacts.push(file); updatedArtifacts.push(file);
...@@ -79,6 +81,7 @@ async function getUpdatedPackageFiles(config) { ...@@ -79,6 +81,7 @@ async function getUpdatedPackageFiles(config) {
} }
} }
} }
}
return { return {
parentBranch: config.parentBranch, // Need to overwrite original config parentBranch: config.parentBranch, // Need to overwrite original config
updatedPackageFiles, updatedPackageFiles,
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`cargo.getArtifacts() catches errors 1`] = ` exports[`cargo.getArtifacts() catches errors 1`] = `
Array [
Object { Object {
"artifactError": Object { "artifactError": Object {
"lockFile": undefined, "lockFile": undefined,
"stderr": "Cannot read property 'replace' of undefined", "stderr": "Cannot read property 'replace' of undefined",
}, },
} },
]
`; `;
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`.getArtifacts() catches errors 1`] = ` exports[`.getArtifacts() catches errors 1`] = `
Array [
Object { Object {
"artifactError": Object { "artifactError": Object {
"lockFile": "composer.lock", "lockFile": "composer.lock",
"stderr": "not found", "stderr": "not found",
}, },
} },
]
`; `;
exports[`.getArtifacts() catches unmet requirements errors 1`] = ` exports[`.getArtifacts() catches unmet requirements errors 1`] = `
Array [
Object { Object {
"artifactError": Object { "artifactError": Object {
"lockFile": "composer.lock", "lockFile": "composer.lock",
"stderr": "fooYour requirements could not be resolved to an installable set of packages.bar", "stderr": "fooYour requirements could not be resolved to an installable set of packages.bar",
}, },
} },
]
`; `;
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`.getArtifacts() catches errors 1`] = ` exports[`.getArtifacts() catches errors 1`] = `
Array [
Object { Object {
"artifactError": Object { "artifactError": Object {
"lockFile": "go.sum", "lockFile": "go.sum",
"stderr": "This update totally doesnt work", "stderr": "This update totally doesnt work",
}, },
} },
]
`; `;
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`.getArtifacts() catches errors 1`] = ` exports[`.getArtifacts() catches errors 1`] = `
Array [
Object { Object {
"artifactError": Object { "artifactError": Object {
"lockFile": "Pipfile.lock", "lockFile": "Pipfile.lock",
"stderr": "not found", "stderr": "not found",
}, },
} },
]
`; `;
...@@ -49,12 +49,14 @@ describe('workers/branch/get-updated', () => { ...@@ -49,12 +49,14 @@ describe('workers/branch/get-updated', () => {
manager: 'composer', manager: 'composer',
}); });
composer.updateDependency.mockReturnValue('some new content'); composer.updateDependency.mockReturnValue('some new content');
composer.getArtifacts.mockReturnValue({ composer.getArtifacts.mockReturnValue([
{
file: { file: {
name: 'composer.json', name: 'composer.json',
contents: 'some contents', contents: 'some contents',
}, },
}); },
]);
const res = await getUpdatedPackageFiles(config); const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
...@@ -64,12 +66,14 @@ describe('workers/branch/get-updated', () => { ...@@ -64,12 +66,14 @@ describe('workers/branch/get-updated', () => {
manager: 'composer', manager: 'composer',
}); });
composer.updateDependency.mockReturnValue('some new content'); composer.updateDependency.mockReturnValue('some new content');
composer.getArtifacts.mockReturnValue({ composer.getArtifacts.mockReturnValue([
{
artifactError: { artifactError: {
name: 'composer.lock', name: 'composer.lock',
stderr: 'some error', stderr: 'some error',
}, },
}); },
]);
const res = await getUpdatedPackageFiles(config); const res = await getUpdatedPackageFiles(config);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment