mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
refactor: push detect dockerfiles to manager (#1043)
* refactor platform * refactor detect package files * fix * refactor npm detect * refactor meteor detect * refactor: move detect package files completely to manager * update snapshots
This commit is contained in:
parent
ff75a2d9a3
commit
7d06bebe2e
19 changed files with 248 additions and 259 deletions
21
lib/manager/docker/detect.js
Normal file
21
lib/manager/docker/detect.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
module.exports = {
|
||||
detectPackageFiles,
|
||||
};
|
||||
|
||||
async function detectPackageFiles(config, fileList) {
|
||||
const packageFiles = [];
|
||||
if (config.docker.enabled) {
|
||||
for (const file of fileList) {
|
||||
if (file === 'Dockerfile' || file.endsWith('/Dockerfile')) {
|
||||
const content = await config.api.getFileContent(file);
|
||||
const strippedComment = content.replace(/^(#.*?\n)+/, '');
|
||||
// This means we skip ones with ARG for now
|
||||
const fromMatch = strippedComment.startsWith('FROM ');
|
||||
if (fromMatch) {
|
||||
packageFiles.push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return packageFiles;
|
||||
}
|
|
@ -1,10 +1,44 @@
|
|||
const docker = require('./docker/package');
|
||||
const npm = require('./npm/package');
|
||||
|
||||
const dockerDetect = require('./docker/detect');
|
||||
const meteorDetect = require('./meteor/detect');
|
||||
const npmDetect = require('./npm/detect');
|
||||
|
||||
module.exports = {
|
||||
detectPackageFiles,
|
||||
getPackageUpdates,
|
||||
};
|
||||
|
||||
async function detectPackageFiles(input) {
|
||||
const config = { ...input };
|
||||
const { logger } = config;
|
||||
const fileList = (await config.api.getFileList()).filter(
|
||||
file => !config.ignorePaths.some(ignorePath => file.includes(ignorePath))
|
||||
);
|
||||
logger.debug({ config }, 'detectPackageFiles');
|
||||
config.types = {};
|
||||
const packageJsonFiles = await npmDetect.detectPackageFiles(config, fileList);
|
||||
if (packageJsonFiles.length) {
|
||||
logger.info({ packageJsonFiles }, 'Found package.json files');
|
||||
config.packageFiles = config.packageFiles.concat(packageJsonFiles);
|
||||
config.types.npm = true;
|
||||
}
|
||||
const meteorFiles = await meteorDetect.detectPackageFiles(config, fileList);
|
||||
if (meteorFiles.length) {
|
||||
logger.info({ packageJsonFiles }, 'Found meteor files');
|
||||
config.packageFiles = config.packageFiles.concat(meteorFiles);
|
||||
config.types.meteor = true;
|
||||
}
|
||||
const dockerFiles = await dockerDetect.detectPackageFiles(config, fileList);
|
||||
if (dockerFiles.length) {
|
||||
logger.info({ dockerFiles }, 'Found Dockerfiles');
|
||||
config.packageFiles = config.packageFiles.concat(dockerFiles);
|
||||
config.types.docker = true;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
async function getPackageUpdates(config) {
|
||||
if (config.packageFile.endsWith('Dockerfile')) {
|
||||
return docker.getPackageUpdates(config);
|
||||
|
|
18
lib/manager/meteor/detect.js
Normal file
18
lib/manager/meteor/detect.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
module.exports = {
|
||||
detectPackageFiles,
|
||||
};
|
||||
|
||||
async function detectPackageFiles(config, fileList) {
|
||||
const packageFiles = [];
|
||||
if (config.meteor.enabled) {
|
||||
for (const file of fileList) {
|
||||
if (file === 'package.js' || file.endsWith('/package.js')) {
|
||||
const content = await config.api.getFileContent(file);
|
||||
if (content && content.replace(/\s/g, '').includes('Npm.depends({')) {
|
||||
packageFiles.push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return packageFiles;
|
||||
}
|
15
lib/manager/npm/detect.js
Normal file
15
lib/manager/npm/detect.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
module.exports = {
|
||||
detectPackageFiles,
|
||||
};
|
||||
|
||||
async function detectPackageFiles(config, fileList) {
|
||||
const packageFiles = [];
|
||||
if (config.npm.enabled) {
|
||||
for (const file of fileList) {
|
||||
if (file === 'package.json' || file.endsWith('/package.json')) {
|
||||
packageFiles.push(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
return packageFiles;
|
||||
}
|
|
@ -13,7 +13,7 @@ module.exports = {
|
|||
initRepo,
|
||||
setBaseBranch,
|
||||
// Search
|
||||
findFilePaths,
|
||||
getFileList,
|
||||
// Branch
|
||||
branchExists,
|
||||
getAllRenovateBranches,
|
||||
|
@ -236,7 +236,7 @@ async function setBaseBranch(branchName) {
|
|||
// Search
|
||||
|
||||
// Get full file list
|
||||
async function getFileList(branchName) {
|
||||
async function getFileList(branchName = config.baseBranch) {
|
||||
if (config.fileList) {
|
||||
return config.fileList;
|
||||
}
|
||||
|
@ -266,13 +266,6 @@ async function getFileList(branchName) {
|
|||
return config.fileList;
|
||||
}
|
||||
|
||||
// Return all files in the repository matching the filename
|
||||
async function findFilePaths(fileName, branchName = config.baseBranch) {
|
||||
return (await getFileList(branchName)).filter(fullFilePath =>
|
||||
fullFilePath.endsWith(fileName)
|
||||
);
|
||||
}
|
||||
|
||||
// Branch
|
||||
|
||||
// Returns true if branch exists, otherwise false
|
||||
|
|
|
@ -8,7 +8,7 @@ module.exports = {
|
|||
initRepo,
|
||||
setBaseBranch,
|
||||
// Search
|
||||
findFilePaths,
|
||||
getFileList,
|
||||
// Branch
|
||||
branchExists,
|
||||
createBranch,
|
||||
|
@ -117,7 +117,7 @@ async function setBaseBranch(branchName) {
|
|||
// Search
|
||||
|
||||
// Get full file list
|
||||
async function getFileList(branchName) {
|
||||
async function getFileList(branchName = config.baseBranch) {
|
||||
if (config.fileList) {
|
||||
return config.fileList;
|
||||
}
|
||||
|
@ -137,13 +137,6 @@ async function getFileList(branchName) {
|
|||
return config.fileList;
|
||||
}
|
||||
|
||||
// Return all files in the repository matching the filename
|
||||
async function findFilePaths(fileName, branchName = config.baseBranch) {
|
||||
return (await getFileList(branchName)).filter(fullFilePath =>
|
||||
fullFilePath.endsWith(fileName)
|
||||
);
|
||||
}
|
||||
|
||||
// Branch
|
||||
|
||||
// Returns true if branch exists, otherwise false
|
||||
|
|
|
@ -17,7 +17,6 @@ module.exports = {
|
|||
getNpmrc,
|
||||
initApis,
|
||||
mergeRenovateJson,
|
||||
detectPackageFiles,
|
||||
resolvePackageFiles,
|
||||
migrateAndValidate,
|
||||
};
|
||||
|
@ -227,89 +226,6 @@ async function mergeRenovateJson(config, branchName) {
|
|||
return returnConfig;
|
||||
}
|
||||
|
||||
async function detectPackageFiles(input) {
|
||||
const config = { ...input };
|
||||
const { logger } = config;
|
||||
function filterIgnorePaths(packageFiles, ignorePaths) {
|
||||
logger.debug('Checking ignorePaths');
|
||||
return packageFiles.filter(packageFile => {
|
||||
logger.trace(`Checking ${packageFile}`);
|
||||
if (
|
||||
ignorePaths.some(ignorePath => {
|
||||
logger.trace(` ..against ${ignorePath}`);
|
||||
return packageFile.includes(ignorePath);
|
||||
})
|
||||
) {
|
||||
logger.trace('Filtered out');
|
||||
return false;
|
||||
}
|
||||
logger.trace('Included');
|
||||
return true;
|
||||
});
|
||||
}
|
||||
logger.debug({ config }, 'detectPackageFiles');
|
||||
config.types = {};
|
||||
if (config.npm.enabled) {
|
||||
config.packageFiles = filterIgnorePaths(
|
||||
await config.api.findFilePaths('package.json'),
|
||||
config.ignorePaths
|
||||
);
|
||||
logger.debug(
|
||||
{ packageFiles: config.packageFiles },
|
||||
`Found ${config.packageFiles.length} package.json file(s)`
|
||||
);
|
||||
if (config.packageFiles.length) {
|
||||
config.types.npm = true;
|
||||
}
|
||||
}
|
||||
if (config.meteor.enabled) {
|
||||
logger.debug('Detecting meteor package.js files');
|
||||
const allPackageJs = filterIgnorePaths(
|
||||
await config.api.findFilePaths('package.js'),
|
||||
config.ignorePaths
|
||||
);
|
||||
const meteorPackageFiles = [];
|
||||
for (const mFile of allPackageJs) {
|
||||
const packageJsContent = await config.api.getFileContent(mFile);
|
||||
if (
|
||||
packageJsContent &&
|
||||
packageJsContent.replace(/\s/g, '').includes('Npm.depends({')
|
||||
) {
|
||||
meteorPackageFiles.push(mFile);
|
||||
}
|
||||
}
|
||||
if (meteorPackageFiles.length) {
|
||||
logger.info(
|
||||
{ count: meteorPackageFiles.length },
|
||||
`Found meteor package files`
|
||||
);
|
||||
config.types.meteor = true;
|
||||
config.packageFiles = config.packageFiles.concat(meteorPackageFiles);
|
||||
}
|
||||
}
|
||||
if (config.docker.enabled) {
|
||||
logger.debug('Detecting Dockerfiles');
|
||||
const files = filterIgnorePaths(
|
||||
await config.api.findFilePaths('Dockerfile'),
|
||||
config.ignorePaths
|
||||
);
|
||||
for (const file of files) {
|
||||
const content = await config.api.getFileContent(file);
|
||||
const strippedComment = content.replace(/^(#.*?\n)+/, '');
|
||||
// This means we skip ones with ARG for now
|
||||
const fromMatch = strippedComment.startsWith('FROM ');
|
||||
if (fromMatch) {
|
||||
config.packageFiles.push(file);
|
||||
config.types.docker = true;
|
||||
}
|
||||
}
|
||||
if (config.types.docker) {
|
||||
logger.info(`Found Dockerfiles`);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
async function resolvePackageFiles(inputConfig) {
|
||||
const config = { ...inputConfig };
|
||||
const { logger } = config;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
const convertHrTime = require('convert-hrtime');
|
||||
const tmp = require('tmp-promise');
|
||||
const manager = require('../../manager');
|
||||
// Workers
|
||||
const branchWorker = require('../branch');
|
||||
// children
|
||||
|
@ -68,7 +69,7 @@ async function renovateRepository(repoConfig, token) {
|
|||
// Detect package files in default branch if not manually provisioned
|
||||
if (config.packageFiles.length === 0) {
|
||||
logger.debug('Detecting package files');
|
||||
config = await apis.detectPackageFiles(config);
|
||||
config = await manager.detectPackageFiles(config);
|
||||
// If we can't detect any package.json then return
|
||||
if (config.packageFiles.length === 0) {
|
||||
logger.info('Cannot detect package files');
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const apis = require('./apis');
|
||||
const manager = require('../../manager');
|
||||
|
||||
const onboardPrTitle = 'Configure Renovate';
|
||||
|
||||
|
@ -26,7 +27,7 @@ async function createOnboardingBranch(inputConfig) {
|
|||
let config = { ...inputConfig };
|
||||
const { logger } = config;
|
||||
logger.debug('Creating onboarding branch');
|
||||
config = await apis.detectPackageFiles(config);
|
||||
config = await manager.detectPackageFiles(config);
|
||||
if (config.packageFiles.length === 0) {
|
||||
throw new Error('no package files');
|
||||
}
|
||||
|
|
32
test/manager/__snapshots__/index.spec.js.snap
Normal file
32
test/manager/__snapshots__/index.spec.js.snap
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`manager detectPackageFiles(config) adds package files to object 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"backend/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) finds Dockerfiles 1`] = `
|
||||
Array [
|
||||
"Dockerfile",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) finds meteor package files 1`] = `
|
||||
Array [
|
||||
"modules/something/package.js",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 2`] = `undefined`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) ignores node modules 3`] = `Array []`;
|
||||
|
||||
exports[`manager detectPackageFiles(config) skips meteor package files with no json 1`] = `Array []`;
|
75
test/manager/index.spec.js
Normal file
75
test/manager/index.spec.js
Normal file
|
@ -0,0 +1,75 @@
|
|||
const logger = require('../_fixtures/logger');
|
||||
const defaultConfig = require('../../lib/config/defaults').getConfig();
|
||||
const manager = require('../../lib/manager');
|
||||
|
||||
describe('manager', () => {
|
||||
describe('detectPackageFiles(config)', () => {
|
||||
let config;
|
||||
beforeEach(() => {
|
||||
config = {
|
||||
...defaultConfig,
|
||||
api: {
|
||||
getFileList: jest.fn(() => []),
|
||||
getFileContent: jest.fn(),
|
||||
},
|
||||
logger,
|
||||
warnings: [],
|
||||
};
|
||||
});
|
||||
it('adds package files to object', async () => {
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'package.json',
|
||||
'backend/package.json',
|
||||
]);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(2);
|
||||
});
|
||||
it('finds meteor package files', async () => {
|
||||
config.meteor.enabled = true;
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'modules/something/package.js',
|
||||
]); // meteor
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends( {} )');
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
});
|
||||
it('skips meteor package files with no json', async () => {
|
||||
config.meteor.enabled = true;
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'modules/something/package.js',
|
||||
]); // meteor
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends(packages)');
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(0);
|
||||
});
|
||||
it('finds Dockerfiles', async () => {
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'Dockerfile',
|
||||
'other/Dockerfile',
|
||||
]);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'### comment\nFROM something\nRUN something'
|
||||
);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'ARG foo\nFROM something\nRUN something'
|
||||
);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
});
|
||||
it('ignores node modules', async () => {
|
||||
config.api.getFileList.mockReturnValueOnce([
|
||||
'package.json',
|
||||
'node_modules/backend/package.json',
|
||||
]);
|
||||
const res = await manager.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
expect(res.foundIgnoredPaths).toMatchSnapshot();
|
||||
expect(res.warnings).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -465,14 +465,6 @@ content",
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`platform/github findFilePaths(fileName) should return the files matching the fileName 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"src/app/package.json",
|
||||
"src/otherapp/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`platform/github getAllRenovateBranches() should return all renovate branches 1`] = `
|
||||
Array [
|
||||
"renovate/a",
|
||||
|
@ -689,6 +681,15 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`platform/github getFileList should return the files matching the fileName 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"some-dir/package.json.some-thing-else",
|
||||
"src/app/package.json",
|
||||
"src/otherapp/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`platform/github getInstallationRepositories should return an array of repositories 1`] = `
|
||||
Array [
|
||||
Array [
|
||||
|
|
|
@ -193,14 +193,6 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`platform/gitlab findFilePaths(fileName) should return the files matching the fileName 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"src/app/package.json",
|
||||
"src/otherapp/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`platform/gitlab getBranch returns a branch 1`] = `"foo"`;
|
||||
|
||||
exports[`platform/gitlab getBranchLastCommitTime should return a Date 1`] = `2012-09-20T08:50:22.000Z`;
|
||||
|
@ -288,6 +280,15 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`platform/gitlab getFileList should return the files matching the fileName 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"some-dir/package.json.some-thing-else",
|
||||
"src/app/package.json",
|
||||
"src/otherapp/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`platform/gitlab getPr(prNo) returns the PR 1`] = `
|
||||
Object {
|
||||
"body": "a merge request",
|
||||
|
|
|
@ -475,11 +475,9 @@ describe('platform/github', () => {
|
|||
get.mockImplementationOnce(() => {
|
||||
throw new Error('some error');
|
||||
});
|
||||
const files = await github.findFilePaths('someething');
|
||||
const files = await github.getFileList();
|
||||
expect(files).toEqual([]);
|
||||
});
|
||||
});
|
||||
describe('findFilePaths(fileName)', () => {
|
||||
it('warns if truncated result', async () => {
|
||||
await initRepo('some/repo', 'token');
|
||||
get.mockImplementationOnce(() => ({
|
||||
|
@ -488,7 +486,7 @@ describe('platform/github', () => {
|
|||
tree: [],
|
||||
},
|
||||
}));
|
||||
const files = await github.findFilePaths('package.json');
|
||||
const files = await github.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
});
|
||||
it('caches the result', async () => {
|
||||
|
@ -499,9 +497,9 @@ describe('platform/github', () => {
|
|||
tree: [],
|
||||
},
|
||||
}));
|
||||
let files = await github.findFilePaths('package.json');
|
||||
let files = await github.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
files = await github.findFilePaths('package.js');
|
||||
files = await github.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
});
|
||||
it('should return the files matching the fileName', async () => {
|
||||
|
@ -520,7 +518,7 @@ describe('platform/github', () => {
|
|||
],
|
||||
},
|
||||
}));
|
||||
const files = await github.findFilePaths('package.json');
|
||||
const files = await github.getFileList();
|
||||
expect(files).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -171,13 +171,13 @@ describe('platform/gitlab', () => {
|
|||
expect(get.mock.calls).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
describe('findFilePaths(fileName)', () => {
|
||||
describe('getFileList', () => {
|
||||
it('returns empty array if error', async () => {
|
||||
await initRepo('some/repo', 'token');
|
||||
get.mockImplementationOnce(() => {
|
||||
throw new Error('some error');
|
||||
});
|
||||
const files = await gitlab.findFilePaths('someething');
|
||||
const files = await gitlab.getFileList();
|
||||
expect(files).toEqual([]);
|
||||
});
|
||||
it('warns if truncated result', async () => {
|
||||
|
@ -185,7 +185,7 @@ describe('platform/gitlab', () => {
|
|||
get.mockImplementationOnce(() => ({
|
||||
body: [],
|
||||
}));
|
||||
const files = await gitlab.findFilePaths('package.json');
|
||||
const files = await gitlab.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
});
|
||||
it('caches the result', async () => {
|
||||
|
@ -193,9 +193,9 @@ describe('platform/gitlab', () => {
|
|||
get.mockImplementationOnce(() => ({
|
||||
body: [],
|
||||
}));
|
||||
let files = await gitlab.findFilePaths('package.json');
|
||||
let files = await gitlab.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
files = await gitlab.findFilePaths('package.js');
|
||||
files = await gitlab.getFileList();
|
||||
expect(files.length).toBe(0);
|
||||
});
|
||||
it('should return the files matching the fileName', async () => {
|
||||
|
@ -212,7 +212,7 @@ describe('platform/gitlab', () => {
|
|||
{ type: 'blob', path: 'src/otherapp/package.json' },
|
||||
],
|
||||
}));
|
||||
const files = await gitlab.findFilePaths('package.json');
|
||||
const files = await gitlab.getFileList();
|
||||
expect(files).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,37 +30,6 @@ Array [
|
|||
|
||||
exports[`workers/repository/apis checkMonorepos skips if no lerna packages 1`] = `Array []`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) adds package files to object 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
"backend/package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) finds Dockerfiles 1`] = `
|
||||
Array [
|
||||
"Dockerfile",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) finds meteor package files 1`] = `
|
||||
Array [
|
||||
"modules/something/package.js",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 1`] = `
|
||||
Array [
|
||||
"package.json",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 2`] = `undefined`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) ignores node modules 3`] = `Array []`;
|
||||
|
||||
exports[`workers/repository/apis detectPackageFiles(config) skips meteor package files with no json 1`] = `Array []`;
|
||||
|
||||
exports[`workers/repository/apis initApis(config) throws if unknown platform 1`] = `"Unknown platform: foo"`;
|
||||
|
||||
exports[`workers/repository/apis mergeRenovateJson(config) returns error in config if renovate.json cannot be parsed 1`] = `
|
||||
|
|
|
@ -252,84 +252,6 @@ describe('workers/repository/apis', () => {
|
|||
expect(e).toBeDefined();
|
||||
});
|
||||
});
|
||||
describe('detectPackageFiles(config)', () => {
|
||||
let config;
|
||||
beforeEach(() => {
|
||||
config = {
|
||||
...defaultConfig,
|
||||
api: {
|
||||
findFilePaths: jest.fn(),
|
||||
getFileContent: jest.fn(),
|
||||
},
|
||||
logger,
|
||||
warnings: [],
|
||||
};
|
||||
config.api.findFilePaths.mockReturnValue([]);
|
||||
});
|
||||
it('adds package files to object', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'package.json',
|
||||
'backend/package.json',
|
||||
]);
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(2);
|
||||
});
|
||||
it('finds meteor package files', async () => {
|
||||
config.meteor.enabled = true;
|
||||
config.api.findFilePaths.mockReturnValueOnce([]); // package.json
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'modules/something/package.js',
|
||||
]); // meteor
|
||||
config.api.findFilePaths.mockReturnValueOnce([]); // Dockerfile
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends( {} )');
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
});
|
||||
it('skips meteor package files with no json', async () => {
|
||||
config.meteor.enabled = true;
|
||||
config.api.findFilePaths.mockReturnValueOnce([]); // package.json
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'modules/something/package.js',
|
||||
]); // meteor
|
||||
config.api.findFilePaths.mockReturnValueOnce([]); // Dockerfile
|
||||
config.api.getFileContent.mockReturnValueOnce('Npm.depends(packages)');
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(0);
|
||||
});
|
||||
it('finds Dockerfiles', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'Dockerfile',
|
||||
'other/Dockerfile',
|
||||
]);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'### comment\nFROM something\nRUN something'
|
||||
);
|
||||
config.api.getFileContent.mockReturnValueOnce(
|
||||
'ARG foo\nFROM something\nRUN something'
|
||||
);
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
});
|
||||
it('ignores node modules', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce([
|
||||
'package.json',
|
||||
'node_modules/backend/package.json',
|
||||
]);
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
config.api.findFilePaths.mockReturnValueOnce([]);
|
||||
const res = await apis.detectPackageFiles(config);
|
||||
expect(res.packageFiles).toMatchSnapshot();
|
||||
expect(res.packageFiles).toHaveLength(1);
|
||||
expect(res.foundIgnoredPaths).toMatchSnapshot();
|
||||
expect(res.warnings).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
describe('resolvePackageFiles', () => {
|
||||
let config;
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -2,6 +2,7 @@ const repositoryWorker = require('../../../lib/workers/repository/index');
|
|||
const branchWorker = require('../../../lib/workers/branch');
|
||||
|
||||
const apis = require('../../../lib/workers/repository/apis');
|
||||
const manager = require('../../../lib/manager');
|
||||
const onboarding = require('../../../lib/workers/repository/onboarding');
|
||||
const upgrades = require('../../../lib/workers/repository/upgrades');
|
||||
|
||||
|
@ -45,7 +46,7 @@ describe('workers/repository', () => {
|
|||
jest.resetAllMocks();
|
||||
apis.initApis = jest.fn(input => input);
|
||||
apis.mergeRenovateJson = jest.fn(input => input);
|
||||
apis.detectPackageFiles = jest.fn();
|
||||
manager.detectPackageFiles = jest.fn();
|
||||
apis.resolvePackageFiles = jest.fn(input => input);
|
||||
apis.checkMonorepos = jest.fn(input => input);
|
||||
onboarding.getOnboardingStatus = jest.fn(input => input);
|
||||
|
@ -67,18 +68,18 @@ describe('workers/repository', () => {
|
|||
it('skips repository if config is disabled', async () => {
|
||||
config.enabled = false;
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
expect(apis.detectPackageFiles.mock.calls.length).toBe(0);
|
||||
expect(manager.detectPackageFiles.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('skips repository if its unconfigured fork', async () => {
|
||||
config.isFork = true;
|
||||
config.renovateJsonPresent = false;
|
||||
await repositoryWorker.renovateRepository(config);
|
||||
expect(apis.detectPackageFiles.mock.calls.length).toBe(0);
|
||||
expect(manager.detectPackageFiles.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('sets custom base branch', async () => {
|
||||
config.baseBranch = 'some-branch';
|
||||
config.api.branchExists.mockReturnValueOnce(true);
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
|
@ -88,7 +89,7 @@ describe('workers/repository', () => {
|
|||
it('errors when missing custom base branch', async () => {
|
||||
config.baseBranch = 'some-branch';
|
||||
config.api.branchExists.mockReturnValueOnce(false);
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
|
@ -96,7 +97,7 @@ describe('workers/repository', () => {
|
|||
expect(config.api.setBaseBranch.mock.calls).toHaveLength(0);
|
||||
});
|
||||
it('skips repository if no package.json', async () => {
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: [] },
|
||||
}));
|
||||
|
@ -105,7 +106,7 @@ describe('workers/repository', () => {
|
|||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('does not skip repository if package.json', async () => {
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
|
@ -128,7 +129,7 @@ describe('workers/repository', () => {
|
|||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('uses onboarding custom baseBranch', async () => {
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
|
@ -152,7 +153,7 @@ describe('workers/repository', () => {
|
|||
expect(config.logger.error.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('errors onboarding custom baseBranch', async () => {
|
||||
apis.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
manager.detectPackageFiles.mockImplementationOnce(input => ({
|
||||
...input,
|
||||
...{ packageFiles: ['package.json'] },
|
||||
}));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const onboarding = require('../../../lib/workers/repository/onboarding');
|
||||
const apis = require('../../../lib/workers/repository/apis');
|
||||
const manager = require('../../../lib/manager');
|
||||
const logger = require('../../_fixtures/logger');
|
||||
const defaultConfig = require('../../../lib/config/defaults').getConfig();
|
||||
|
||||
|
@ -226,7 +226,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
config.api = {
|
||||
commitFilesToBranch: jest.fn(),
|
||||
createPr: jest.fn(() => ({ displayNumber: 1 })),
|
||||
findFilePaths: jest.fn(() => []),
|
||||
getFileList: jest.fn(() => []),
|
||||
findPr: jest.fn(),
|
||||
getFileContent: jest.fn(),
|
||||
getFileJson: jest.fn(() => ({})),
|
||||
|
@ -267,8 +267,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
expect(config.api.commitFilesToBranch.mock.calls.length).toBe(0);
|
||||
});
|
||||
it('commits files and returns false if no pr', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce(['package.json']);
|
||||
config.api.findFilePaths.mockReturnValue([]);
|
||||
config.api.getFileList.mockReturnValueOnce(['package.json']);
|
||||
const res = await onboarding.getOnboardingStatus(config);
|
||||
expect(res.repoIsOnboarded).toEqual(false);
|
||||
expect(config.api.findPr.mock.calls.length).toBe(1);
|
||||
|
@ -276,8 +275,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
expect(config.api.commitFilesToBranch.mock.calls[0]).toMatchSnapshot();
|
||||
});
|
||||
it('pins private repos', async () => {
|
||||
config.api.findFilePaths.mockReturnValueOnce(['package.json']);
|
||||
config.api.findFilePaths.mockReturnValue([]);
|
||||
config.api.getFileList.mockReturnValueOnce(['package.json']);
|
||||
onboarding.isRepoPrivate.mockReturnValueOnce(true);
|
||||
const res = await onboarding.getOnboardingStatus(config);
|
||||
expect(res.repoIsOnboarded).toEqual(false);
|
||||
|
@ -286,7 +284,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
expect(config.api.commitFilesToBranch.mock.calls[0]).toMatchSnapshot();
|
||||
});
|
||||
it('uses base + docker', async () => {
|
||||
apis.detectPackageFiles = jest.fn(input => ({
|
||||
manager.detectPackageFiles = jest.fn(input => ({
|
||||
...input,
|
||||
packageFiles: [{}, {}],
|
||||
types: {
|
||||
|
@ -300,7 +298,7 @@ describe('lib/workers/repository/onboarding', () => {
|
|||
expect(config.api.commitFilesToBranch.mock.calls[0]).toMatchSnapshot();
|
||||
});
|
||||
it('throws if no packageFiles', async () => {
|
||||
apis.detectPackageFiles = jest.fn(input => ({
|
||||
manager.detectPackageFiles = jest.fn(input => ({
|
||||
...input,
|
||||
}));
|
||||
let e;
|
||||
|
|
Loading…
Reference in a new issue