Skip to content

Commit

Permalink
refactor: Reorder extractions and lookups (#6578)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
zharinov and rarkins committed Jun 25, 2020
1 parent 9478d6b commit b93e072
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
5 changes: 3 additions & 2 deletions lib/workers/repository/process/extract-update.spec.ts
@@ -1,6 +1,6 @@
import { mocked } from '../../../../test/util';
import * as _branchify from '../updates/branchify';
import { extract, update } from './extract-update';
import { extract, lookup, update } from './extract-update';

jest.mock('./write');
jest.mock('./sort');
Expand All @@ -22,7 +22,8 @@ describe('workers/repository/process/extract-update', () => {
repoIsOnboarded: true,
suppressNotifications: ['deprecationWarningIssues'],
};
const res = await extract(config);
const packageFiles = await extract(config);
const res = await lookup(config, packageFiles);
expect(res).toMatchSnapshot();
await expect(update(config, res.branches)).resolves.not.toThrow();
});
Expand Down
20 changes: 11 additions & 9 deletions lib/workers/repository/process/extract-update.ts
@@ -1,7 +1,6 @@
import { RenovateConfig } from '../../../config';
import { logger } from '../../../logger';
import { PackageFile } from '../../../manager/common';
import { addSplit } from '../../../util/split';
import { BranchConfig } from '../../common';
import { extractAllDependencies } from '../extract';
import { branchifyUpgrades } from '../updates/branchify';
Expand Down Expand Up @@ -44,18 +43,24 @@ function extractStats(packageFiles: Record<string, PackageFile[]>): any {
return stats;
}

export async function extract(config: RenovateConfig): Promise<ExtractResult> {
logger.debug('extractAndUpdate()');
export async function extract(
config: RenovateConfig
): Promise<Record<string, PackageFile[]>> {
logger.debug('extract()');
const packageFiles = await extractAllDependencies(config);
const stats = extractStats(packageFiles);
logger.info(
{ baseBranch: config.baseBranch, stats },
`Dependency extraction complete`
);
addSplit(
config.baseBranches?.length ? `extract:${config.baseBranch}` : 'extract'
);
logger.trace({ config: packageFiles }, 'packageFiles');
return packageFiles;
}

export async function lookup(
config: RenovateConfig,
packageFiles: Record<string, PackageFile[]>
): Promise<ExtractResult> {
await fetchUpdates(config, packageFiles);
logger.debug({ config: packageFiles }, 'packageFiles with updates');
await raiseDeprecationWarnings(config, packageFiles);
Expand All @@ -64,9 +69,6 @@ export async function extract(config: RenovateConfig): Promise<ExtractResult> {
packageFiles
);
sortBranches(branches);
addSplit(
config.baseBranches?.length ? `lookup:${config.baseBranch}` : 'lookup'
);
return { branches, branchList, packageFiles };
}

Expand Down
46 changes: 33 additions & 13 deletions lib/workers/repository/process/index.ts
@@ -1,10 +1,26 @@
import { RenovateConfig, mergeChildConfig } from '../../../config';
import { logger } from '../../../logger';
import { PackageFile } from '../../../manager/common';
import { platform } from '../../../platform';
import { addSplit } from '../../../util/split';
import { BranchConfig } from '../../common';
import { ExtractResult, extract, update } from './extract-update';
import { ExtractResult, extract, lookup, update } from './extract-update';
import { WriteUpdateResult } from './write';

async function setBaseBranch(
baseBranch: string,
config: RenovateConfig
): Promise<RenovateConfig> {
logger.debug(`baseBranch: ${baseBranch}`);
const baseBranchConfig = mergeChildConfig(config, { baseBranch });
if (config.baseBranches.length > 1) {
baseBranchConfig.branchPrefix += `${baseBranch}-`;
baseBranchConfig.hasBaseBranches = true;
}
baseBranchConfig.baseBranchSha = await platform.setBaseBranch(baseBranch);
return baseBranchConfig;
}

export async function extractDependencies(
config: RenovateConfig
): Promise<ExtractResult> {
Expand Down Expand Up @@ -50,23 +66,27 @@ export async function extractDependencies(
};
if (config.baseBranches && config.baseBranches.length) {
logger.debug({ baseBranches: config.baseBranches }, 'baseBranches');
const extracted: Record<string, Record<string, PackageFile[]>> = {};
for (const baseBranch of config.baseBranches) {
logger.debug(`baseBranch: ${baseBranch}`);
const baseBranchConfig = mergeChildConfig(config, { baseBranch });
if (config.baseBranches.length > 1) {
baseBranchConfig.branchPrefix += `${baseBranch}-`;
baseBranchConfig.hasBaseBranches = true;
}
baseBranchConfig.baseBranchSha = await platform.setBaseBranch(baseBranch);
const baseBranchRes = await extract(baseBranchConfig);
res.branches = res.branches.concat(baseBranchRes.branches);
res.branchList = res.branchList.concat(baseBranchRes.branchList);
res.packageFiles = res.packageFiles || baseBranchRes.packageFiles; // Use the first branch
const baseBranchConfig = await setBaseBranch(baseBranch, config);
extracted[baseBranch] = await extract(baseBranchConfig);
}
addSplit('extract');
for (const baseBranch of config.baseBranches) {
const baseBranchConfig = await setBaseBranch(baseBranch, config);
const packageFiles = extracted[baseBranch];
const baseBranchRes = await lookup(baseBranchConfig, packageFiles);
res.branches = res.branches.concat(baseBranchRes?.branches);
res.branchList = res.branchList.concat(baseBranchRes?.branchList);
res.packageFiles = res.packageFiles || baseBranchRes?.packageFiles; // Use the first branch
}
} else {
logger.debug('No baseBranches');
res = await extract(config);
const packageFiles = await extract(config);
addSplit('extract');
res = await lookup(config, packageFiles);
}
addSplit('lookup');
return res;
}

Expand Down

0 comments on commit b93e072

Please sign in to comment.