Skip to content

Commit

Permalink
fix: Revert "refactor: extract and update now decoupled (#5835)"
Browse files Browse the repository at this point in the history
This reverts commit f04adc5.
  • Loading branch information
rarkins committed Apr 14, 2020
1 parent 5e742fe commit c9071a7
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 82 deletions.
4 changes: 0 additions & 4 deletions lib/workers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '../config';
import { File, PlatformPrOptions } from '../platform';
import { Release } from '../datasource';
import { ChangeLogResult } from './pr/changelog/common';

export interface BranchUpgradeConfig
extends Merge<RenovateConfig, PackageDependency>,
Expand Down Expand Up @@ -48,11 +47,8 @@ export interface BranchUpgradeConfig
releaseTimestamp?: string;

sourceDirectory?: string;

updatedPackageFiles?: File[];
updatedArtifacts?: File[];

logJSON?: ChangeLogResult;
}

export enum PrResult {
Expand Down
10 changes: 0 additions & 10 deletions lib/workers/pr/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { mocked } from '../../../test/util';
import { BranchStatus } from '../../types';
import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms';
import { PrResult } from '../common';
import { extractChangeLogJSON } from '../repository/extract';

const changelogHelper = mocked(_changelogHelper);
const platform = mocked(_platform);
Expand Down Expand Up @@ -181,7 +180,6 @@ describe('workers/pr', () => {
});
it('should create PR if success', async () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
await extractChangeLogJSON([config]);
config.prCreation = 'status-success';
config.automerge = true;
config.schedule = 'before 5am';
Expand Down Expand Up @@ -219,9 +217,6 @@ describe('workers/pr', () => {
config.updateType = 'lockFileMaintenance';
config.recreateClosed = true;
config.rebaseWhen = 'never';

await extractChangeLogJSON([config]);

const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
Expand All @@ -235,7 +230,6 @@ describe('workers/pr', () => {
config.schedule = 'before 5am';
config.timezone = 'some timezone';
config.rebaseWhen = 'behind-base-branch';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
Expand Down Expand Up @@ -375,7 +369,6 @@ describe('workers/pr', () => {
config.semanticCommitScope = null;
config.automerge = true;
config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated);
expect(platform.updatePr.mock.calls).toMatchSnapshot();
Expand All @@ -390,7 +383,6 @@ describe('workers/pr', () => {
config.semanticCommitScope = null;
config.automerge = true;
config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated);
expect(platform.updatePr).toHaveBeenCalledTimes(0);
Expand All @@ -400,7 +392,6 @@ describe('workers/pr', () => {
config.newValue = '1.2.0';
config.automerge = true;
config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
platform.getBranchPr.mockResolvedValueOnce(existingPr);
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated);
Expand Down Expand Up @@ -464,7 +455,6 @@ describe('workers/pr', () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
config.prCreation = 'status-success';
config.privateRepo = false;
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/pr/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sampleSize from 'lodash/sampleSize';
import uniq from 'lodash/uniq';
import { logger } from '../../logger';
import { ChangeLogError } from './changelog';
import { ChangeLogError, getChangeLogJSON } from './changelog';
import { getPrBody } from './body';
import { platform, Pr, PlatformPrOptions } from '../../platform';
import { BranchConfig, PrResult } from '../common';
Expand Down Expand Up @@ -193,7 +193,7 @@ export async function ensurePr(
}
processedUpgrades.push(upgradeKey);

const logJSON = upgrade.logJSON;
const logJSON = await getChangeLogJSON(upgrade);

if (logJSON) {
if (typeof logJSON.error === 'undefined') {
Expand Down
12 changes: 0 additions & 12 deletions lib/workers/repository/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
} from '../../../config';
import { getManagerPackageFiles } from './manager-files';
import { PackageFile } from '../../../manager/common';
import { BranchConfig } from '../../common';
import { getChangeLogJSON } from '../../pr/changelog';

export async function extractAllDependencies(
config: RenovateConfig
Expand Down Expand Up @@ -51,13 +49,3 @@ export async function extractAllDependencies(
logger.debug(`Found ${fileCount} package file(s)`);
return extractions;
}

export async function extractChangeLogJSON(
branches: BranchConfig[]
): Promise<void> {
for (const branch of branches) {
for (const upgrade of branch.upgrades) {
upgrade.logJSON = await getChangeLogJSON(upgrade);
}
}
}
4 changes: 2 additions & 2 deletions lib/workers/repository/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { mock } from 'jest-mock-extended';
import { renovateRepository } from '.';
import * as _process from './process';
import { mocked, RenovateConfig, getConfig } from '../../../test/util';
import { ExtractResult } from './process/extract-update';
import { ExtractAndUpdateResult } from './process/extract-update';

const process = mocked(_process);

Expand All @@ -19,7 +19,7 @@ describe('workers/repository', () => {
config = getConfig();
});
it('runs', async () => {
process.processRepo.mockResolvedValue(mock<ExtractResult>());
process.processRepo.mockResolvedValue(mock<ExtractAndUpdateResult>());
const res = await renovateRepository(config);
expect(res).toMatchSnapshot();
});
Expand Down
14 changes: 4 additions & 10 deletions lib/workers/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { logger, setMeta } from '../../logger';
import { initRepo } from './init';
import { ensureOnboardingPr } from './onboarding/pr';
import { processResult, ProcessResult } from './result';
import { processRepo, updateRepo } from './process';
import { processRepo } from './process';
import { finaliseRepo } from './finalise';
import { ensureMasterIssue } from './master-issue';
import { RenovateConfig } from '../../config';
import { extractChangeLogJSON } from './extract';

let renovateVersion = 'unknown';
try {
Expand All @@ -32,15 +31,10 @@ export async function renovateRepository(
await fs.ensureDir(config.localDir);
logger.debug('Using localDir: ' + config.localDir);
config = await initRepo(config);
const { branches, branchList, packageFiles } = await processRepo(config);
await extractChangeLogJSON(branches);
await ensureOnboardingPr(config, packageFiles, branches);
const { res } = await updateRepo(
config,
branches,
branchList,
packageFiles
const { res, branches, branchList, packageFiles } = await processRepo(
config
);
await ensureOnboardingPr(config, packageFiles, branches);
if (res !== 'automerged') {
await ensureMasterIssue(config, branches);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Object {
undefined,
undefined,
],
"res": undefined,
}
`;

Expand Down
7 changes: 3 additions & 4 deletions lib/workers/repository/process/extract-update.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extract, update } from './extract-update';
import { extractAndUpdate } from './extract-update';
import * as _branchify from '../updates/branchify';
import { mocked } from '../../../../test/util';

Expand All @@ -16,14 +16,13 @@ branchify.branchifyUpgrades.mockResolvedValueOnce({
});

describe('workers/repository/process/extract-update', () => {
describe('extract()', () => {
describe('extractAndUpdate()', () => {
it('runs', async () => {
const config = {
repoIsOnboarded: true,
suppressNotifications: ['deprecationWarningIssues'],
};
const res = await extract(config);
await update(config, res.branches, res.branchList, res.packageFiles);
await extractAndUpdate(config);
});
});
});
23 changes: 6 additions & 17 deletions lib/workers/repository/process/extract-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import { PackageFile } from '../../../manager/common';
import { RenovateConfig } from '../../../config';
import { BranchConfig } from '../../common';

export type ExtractResult = {
export type ExtractAndUpdateResult = {
res: WriteUpdateResult | undefined;
branches: BranchConfig[];
branchList: string[];
packageFiles?: Record<string, PackageFile[]>;
};

export type UpdateResult = {
res: WriteUpdateResult | undefined;
};

export async function extract(config: RenovateConfig): Promise<ExtractResult> {
export async function extractAndUpdate(
config: RenovateConfig
): Promise<ExtractAndUpdateResult> {
logger.debug('extractAndUpdate()');
const packageFiles = await extractAllDependencies(config);
logger.trace({ config: packageFiles }, 'packageFiles');
Expand All @@ -31,20 +30,10 @@ export async function extract(config: RenovateConfig): Promise<ExtractResult> {
packageFiles
);
sortBranches(branches);
return { branches, branchList, packageFiles };
}

export async function update(
config: RenovateConfig,
branches: BranchConfig[],
branchList: string[],
packageFiles?: Record<string, PackageFile[]>
): Promise<UpdateResult> {
let res: WriteUpdateResult | undefined;
// istanbul ignore else
if (config.repoIsOnboarded) {
res = await writeUpdates(config, packageFiles, branches);
}

return { res };
return { res, branches, branchList, packageFiles };
}
7 changes: 3 additions & 4 deletions lib/workers/repository/process/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { processRepo, updateRepo } from './index';
import { processRepo } from './index';
import * as _extractUpdate from './extract-update';
import { getConfig, mocked, RenovateConfig } from '../../../../test/util';

jest.mock('./extract-update');

const extract = mocked(_extractUpdate).extract;
const extractAndUpdate = mocked(_extractUpdate).extractAndUpdate;

let config: RenovateConfig;
beforeEach(() => {
Expand All @@ -19,10 +19,9 @@ describe('workers/repository/process/index', () => {
expect(res).toMatchSnapshot();
});
it('processes baseBranches', async () => {
extract.mockResolvedValue({} as never);
extractAndUpdate.mockResolvedValue({} as never);
config.baseBranches = ['branch1', 'branch2'];
const res = await processRepo(config);
await updateRepo(config, res.branches, res.branchList, res.packageFiles);
expect(res).toMatchSnapshot();
});
});
Expand Down
25 changes: 8 additions & 17 deletions lib/workers/repository/process/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { logger } from '../../../logger';
import { mergeChildConfig, RenovateConfig } from '../../../config';
import { extract, ExtractResult, update, UpdateResult } from './extract-update';
import { extractAndUpdate, ExtractAndUpdateResult } from './extract-update';
import { platform } from '../../../platform';
import { WriteUpdateResult } from './write';
import { BranchConfig } from '../../common';
import { PackageFile } from '../../../manager/common';

export async function processRepo(
config: RenovateConfig
): Promise<ExtractResult> {
): Promise<ExtractAndUpdateResult> {
logger.debug('processRepo()');
/* eslint-disable no-param-reassign */
config.masterIssueChecks = {};
Expand Down Expand Up @@ -45,6 +45,7 @@ export async function processRepo(
}
if (config.baseBranches && config.baseBranches.length) {
logger.debug({ baseBranches: config.baseBranches }, 'baseBranches');
let res: WriteUpdateResult | undefined;
let branches: BranchConfig[] = [];
let branchList: string[] = [];
for (const baseBranch of config.baseBranches) {
Expand All @@ -55,23 +56,13 @@ export async function processRepo(
baseBranchConfig.hasBaseBranches = true;
}
await platform.setBaseBranch(baseBranch);
const baseBranchRes = await extract(baseBranchConfig);
const baseBranchRes = await extractAndUpdate(baseBranchConfig);
({ res } = baseBranchRes);
branches = branches.concat(baseBranchRes.branches);
branchList = branchList.concat(baseBranchRes.branchList);
}
return { branches, branchList };
return { res, branches, branchList };
}
logger.debug('No baseBranches');
return extract(config);
}

export async function updateRepo(
config: RenovateConfig,
branches: BranchConfig[],
branchList: string[],
packageFiles?: Record<string, PackageFile[]>
): Promise<UpdateResult> {
logger.debug('processRepo()');

return update(config, branches, branchList, packageFiles);
return extractAndUpdate(config);
}

0 comments on commit c9071a7

Please sign in to comment.