fix: use managerConfig correctly (#4864)

Fixes a bug where the manager config was not being passed through correctly.
This commit is contained in:
Rhys Arkins 2019-11-23 20:44:21 +01:00 committed by GitHub
parent 3613ba882d
commit 71b25d5deb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 32 additions and 22 deletions

View file

@ -11,9 +11,16 @@ async function extractAllDependencies(config) {
const extractions = {}; const extractions = {};
let fileCount = 0; let fileCount = 0;
for (const manager of getManagerList()) { for (const manager of getManagerList()) {
if (
config.enabledManagers.length &&
!config.enabledManagers.includes(manager)
) {
logger.debug(`${manager} is not in enabledManagers list - skipping`);
continue; // eslint-disable-line
}
const managerConfig = getManagerConfig(config, manager); const managerConfig = getManagerConfig(config, manager);
managerConfig.manager = manager; managerConfig.manager = manager;
const packageFiles = await getManagerPackageFiles(config, managerConfig); const packageFiles = await getManagerPackageFiles(managerConfig);
if (packageFiles && packageFiles.length) { if (packageFiles && packageFiles.length) {
fileCount += packageFiles.length; fileCount += packageFiles.length;
logger.info(`Found ${manager} package files`); logger.info(`Found ${manager} package files`);

View file

@ -17,30 +17,19 @@ const {
getMatchingFiles, getMatchingFiles,
} = require('./file-match'); } = require('./file-match');
async function getManagerPackageFiles(config, managerConfig) { async function getManagerPackageFiles(config) {
const { manager, enabled, includePaths, ignorePaths } = managerConfig; const { manager, enabled, includePaths, ignorePaths } = config;
logger.trace(`getPackageFiles(${manager})`); logger.trace(`getPackageFiles(${manager})`);
if (!enabled) { if (!enabled) {
logger.debug(`${manager} is disabled`); logger.debug(`${manager} is disabled`);
return []; return [];
} }
if (
config.enabledManagers.length &&
!config.enabledManagers.includes(manager)
) {
logger.debug(`${manager} is not in enabledManagers list`);
return [];
}
let fileList = await platform.getFileList(); let fileList = await platform.getFileList();
fileList = getIncludedFiles(fileList, includePaths); fileList = getIncludedFiles(fileList, includePaths);
fileList = filterIgnoredFiles(fileList, ignorePaths); fileList = filterIgnoredFiles(fileList, ignorePaths);
const matchedFiles = getMatchingFiles( const matchedFiles = getMatchingFiles(fileList, manager, config.fileMatch);
fileList,
manager,
managerConfig.fileMatch
);
// istanbul ignore else // istanbul ignore else
if (matchedFiles.length) { if (matchedFiles && matchedFiles.length) {
logger.debug( logger.debug(
`Matched ${ `Matched ${
matchedFiles.length matchedFiles.length

View file

@ -115,3 +115,11 @@ Object {
], ],
} }
`; `;
exports[`workers/repository/extract/index extractAllDependencies() skips non-enabled maangers 1`] = `
Object {
"npm": Array [
Object {},
],
}
`;

View file

@ -16,7 +16,7 @@ Array [
"packageJsonType": "app", "packageJsonType": "app",
"packageJsonVersion": undefined, "packageJsonVersion": undefined,
"pnpmShrinkwrap": "pnpm-lock.yaml", "pnpmShrinkwrap": "pnpm-lock.yaml",
"skipInstalls": true, "skipInstalls": undefined,
"yarnLock": "yarn.lock", "yarnLock": "yarn.lock",
"yarnWorkspacesPackages": undefined, "yarnWorkspacesPackages": undefined,
"yarnrc": "{}", "yarnrc": "{}",

View file

@ -18,5 +18,11 @@ describe('workers/repository/extract/index', () => {
const res = await extractAllDependencies(config); const res = await extractAllDependencies(config);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('skips non-enabled maangers', async () => {
config.enabledManagers = ['npm'];
managerFiles.getManagerPackageFiles.mockReturnValue([{}]);
const res = await extractAllDependencies(config);
expect(res).toMatchSnapshot();
});
}); });
}); });

View file

@ -22,19 +22,19 @@ describe('workers/repository/extract/manager-files', () => {
}); });
it('returns empty of manager is disabled', async () => { it('returns empty of manager is disabled', async () => {
const managerConfig = { manager: 'travis', enabled: false }; const managerConfig = { manager: 'travis', enabled: false };
const res = await getManagerPackageFiles(config, managerConfig); const res = await getManagerPackageFiles(managerConfig);
expect(res).toHaveLength(0); expect(res).toHaveLength(0);
}); });
it('returns empty of manager is not enabled', async () => { it('returns empty of manager is not enabled', async () => {
config.enabledManagers = ['npm']; config.enabledManagers = ['npm'];
const managerConfig = { manager: 'docker', enabled: true }; const managerConfig = { manager: 'docker', enabled: true };
const res = await getManagerPackageFiles(config, managerConfig); const res = await getManagerPackageFiles(managerConfig);
expect(res).toHaveLength(0); expect(res).toHaveLength(0);
}); });
it('skips files if null content returned', async () => { it('skips files if null content returned', async () => {
const managerConfig = { manager: 'npm', enabled: true }; const managerConfig = { manager: 'npm', enabled: true };
fileMatch.getMatchingFiles.mockReturnValue(['package.json']); fileMatch.getMatchingFiles.mockReturnValue(['package.json']);
const res = await getManagerPackageFiles(config, managerConfig); const res = await getManagerPackageFiles(managerConfig);
expect(res).toHaveLength(0); expect(res).toHaveLength(0);
}); });
it('returns files with extractPackageFile', async () => { it('returns files with extractPackageFile', async () => {
@ -42,7 +42,7 @@ describe('workers/repository/extract/manager-files', () => {
fileMatch.getMatchingFiles.mockReturnValue(['Dockerfile']); fileMatch.getMatchingFiles.mockReturnValue(['Dockerfile']);
platform.getFile.mockReturnValue('some content'); platform.getFile.mockReturnValue('some content');
dockerfile.extractPackageFile = jest.fn(() => ({ some: 'result' })); dockerfile.extractPackageFile = jest.fn(() => ({ some: 'result' }));
const res = await getManagerPackageFiles(config, managerConfig); const res = await getManagerPackageFiles(managerConfig);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('returns files with extractAllPackageFiles', async () => { it('returns files with extractAllPackageFiles', async () => {
@ -50,7 +50,7 @@ describe('workers/repository/extract/manager-files', () => {
fileMatch.getMatchingFiles.mockReturnValue(['package.json']); fileMatch.getMatchingFiles.mockReturnValue(['package.json']);
platform.getFile.mockReturnValue('{}'); platform.getFile.mockReturnValue('{}');
npm.extractPackageFile = jest.fn(() => ({ some: 'result' })); npm.extractPackageFile = jest.fn(() => ({ some: 'result' }));
const res = await getManagerPackageFiles(config, managerConfig); const res = await getManagerPackageFiles(managerConfig);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
}); });