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