Skip to content
Snippets Groups Projects
Unverified Commit f04adc50 authored by Yura Beznos's avatar Yura Beznos Committed by GitHub
Browse files

refactor: extract and update now decoupled (#5835)

parent 22ed9b7b
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ import { ...@@ -13,6 +13,7 @@ import {
} from '../config'; } from '../config';
import { File, PlatformPrOptions } from '../platform'; import { File, PlatformPrOptions } from '../platform';
import { Release } from '../datasource'; import { Release } from '../datasource';
import { ChangeLogResult } from './pr/changelog/common';
export interface BranchUpgradeConfig export interface BranchUpgradeConfig
extends Merge<RenovateConfig, PackageDependency>, extends Merge<RenovateConfig, PackageDependency>,
...@@ -47,8 +48,11 @@ export interface BranchUpgradeConfig ...@@ -47,8 +48,11 @@ export interface BranchUpgradeConfig
releaseTimestamp?: string; releaseTimestamp?: string;
sourceDirectory?: string; sourceDirectory?: string;
updatedPackageFiles?: File[]; updatedPackageFiles?: File[];
updatedArtifacts?: File[]; updatedArtifacts?: File[];
logJSON?: ChangeLogResult;
} }
export enum PrResult { export enum PrResult {
......
...@@ -6,6 +6,7 @@ import { mocked } from '../../../test/util'; ...@@ -6,6 +6,7 @@ import { mocked } from '../../../test/util';
import { BranchStatus } from '../../types'; import { BranchStatus } from '../../types';
import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms'; import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms';
import { PrResult } from '../common'; import { PrResult } from '../common';
import { extractChangeLogJSON } from '../repository/extract';
const changelogHelper = mocked(_changelogHelper); const changelogHelper = mocked(_changelogHelper);
const platform = mocked(_platform); const platform = mocked(_platform);
...@@ -180,6 +181,7 @@ describe('workers/pr', () => { ...@@ -180,6 +181,7 @@ describe('workers/pr', () => {
}); });
it('should create PR if success', async () => { it('should create PR if success', async () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
await extractChangeLogJSON([config]);
config.prCreation = 'status-success'; config.prCreation = 'status-success';
config.automerge = true; config.automerge = true;
config.schedule = 'before 5am'; config.schedule = 'before 5am';
...@@ -217,6 +219,9 @@ describe('workers/pr', () => { ...@@ -217,6 +219,9 @@ describe('workers/pr', () => {
config.updateType = 'lockFileMaintenance'; config.updateType = 'lockFileMaintenance';
config.recreateClosed = true; config.recreateClosed = true;
config.rebaseWhen = 'never'; config.rebaseWhen = 'never';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created); expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
...@@ -230,6 +235,7 @@ describe('workers/pr', () => { ...@@ -230,6 +235,7 @@ describe('workers/pr', () => {
config.schedule = 'before 5am'; config.schedule = 'before 5am';
config.timezone = 'some timezone'; config.timezone = 'some timezone';
config.rebaseWhen = 'behind-base-branch'; config.rebaseWhen = 'behind-base-branch';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created); expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
...@@ -369,6 +375,7 @@ describe('workers/pr', () => { ...@@ -369,6 +375,7 @@ describe('workers/pr', () => {
config.semanticCommitScope = null; config.semanticCommitScope = null;
config.automerge = true; config.automerge = true;
config.schedule = 'before 5am'; config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated); expect(prResult).toEqual(PrResult.NotUpdated);
expect(platform.updatePr.mock.calls).toMatchSnapshot(); expect(platform.updatePr.mock.calls).toMatchSnapshot();
...@@ -383,6 +390,7 @@ describe('workers/pr', () => { ...@@ -383,6 +390,7 @@ describe('workers/pr', () => {
config.semanticCommitScope = null; config.semanticCommitScope = null;
config.automerge = true; config.automerge = true;
config.schedule = 'before 5am'; config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated); expect(prResult).toEqual(PrResult.NotUpdated);
expect(platform.updatePr).toHaveBeenCalledTimes(0); expect(platform.updatePr).toHaveBeenCalledTimes(0);
...@@ -392,6 +400,7 @@ describe('workers/pr', () => { ...@@ -392,6 +400,7 @@ describe('workers/pr', () => {
config.newValue = '1.2.0'; config.newValue = '1.2.0';
config.automerge = true; config.automerge = true;
config.schedule = 'before 5am'; config.schedule = 'before 5am';
await extractChangeLogJSON([config]);
platform.getBranchPr.mockResolvedValueOnce(existingPr); platform.getBranchPr.mockResolvedValueOnce(existingPr);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.NotUpdated); expect(prResult).toEqual(PrResult.NotUpdated);
...@@ -455,6 +464,7 @@ describe('workers/pr', () => { ...@@ -455,6 +464,7 @@ describe('workers/pr', () => {
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green); platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
config.prCreation = 'status-success'; config.prCreation = 'status-success';
config.privateRepo = false; config.privateRepo = false;
await extractChangeLogJSON([config]);
const { prResult, pr } = await prWorker.ensurePr(config); const { prResult, pr } = await prWorker.ensurePr(config);
expect(prResult).toEqual(PrResult.Created); expect(prResult).toEqual(PrResult.Created);
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' }); expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
......
import sampleSize from 'lodash/sampleSize'; import sampleSize from 'lodash/sampleSize';
import uniq from 'lodash/uniq'; import uniq from 'lodash/uniq';
import { logger } from '../../logger'; import { logger } from '../../logger';
import { ChangeLogError, getChangeLogJSON } from './changelog'; import { ChangeLogError } from './changelog';
import { getPrBody } from './body'; import { getPrBody } from './body';
import { platform, Pr, PlatformPrOptions } from '../../platform'; import { platform, Pr, PlatformPrOptions } from '../../platform';
import { BranchConfig, PrResult } from '../common'; import { BranchConfig, PrResult } from '../common';
...@@ -193,7 +193,7 @@ export async function ensurePr( ...@@ -193,7 +193,7 @@ export async function ensurePr(
} }
processedUpgrades.push(upgradeKey); processedUpgrades.push(upgradeKey);
const logJSON = await getChangeLogJSON(upgrade); const logJSON = upgrade.logJSON;
if (logJSON) { if (logJSON) {
if (typeof logJSON.error === 'undefined') { if (typeof logJSON.error === 'undefined') {
......
...@@ -7,6 +7,8 @@ import { ...@@ -7,6 +7,8 @@ import {
} from '../../../config'; } from '../../../config';
import { getManagerPackageFiles } from './manager-files'; import { getManagerPackageFiles } from './manager-files';
import { PackageFile } from '../../../manager/common'; import { PackageFile } from '../../../manager/common';
import { BranchConfig } from '../../common';
import { getChangeLogJSON } from '../../pr/changelog';
export async function extractAllDependencies( export async function extractAllDependencies(
config: RenovateConfig config: RenovateConfig
...@@ -49,3 +51,13 @@ export async function extractAllDependencies( ...@@ -49,3 +51,13 @@ export async function extractAllDependencies(
logger.debug(`Found ${fileCount} package file(s)`); logger.debug(`Found ${fileCount} package file(s)`);
return extractions; 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);
}
}
}
...@@ -3,7 +3,7 @@ import { mock } from 'jest-mock-extended'; ...@@ -3,7 +3,7 @@ import { mock } from 'jest-mock-extended';
import { renovateRepository } from '.'; import { renovateRepository } from '.';
import * as _process from './process'; import * as _process from './process';
import { mocked, RenovateConfig, getConfig } from '../../../test/util'; import { mocked, RenovateConfig, getConfig } from '../../../test/util';
import { ExtractAndUpdateResult } from './process/extract-update'; import { ExtractResult } from './process/extract-update';
const process = mocked(_process); const process = mocked(_process);
...@@ -19,7 +19,7 @@ describe('workers/repository', () => { ...@@ -19,7 +19,7 @@ describe('workers/repository', () => {
config = getConfig(); config = getConfig();
}); });
it('runs', async () => { it('runs', async () => {
process.processRepo.mockResolvedValue(mock<ExtractAndUpdateResult>()); process.processRepo.mockResolvedValue(mock<ExtractResult>());
const res = await renovateRepository(config); const res = await renovateRepository(config);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
......
...@@ -6,10 +6,11 @@ import { logger, setMeta } from '../../logger'; ...@@ -6,10 +6,11 @@ import { logger, setMeta } from '../../logger';
import { initRepo } from './init'; import { initRepo } from './init';
import { ensureOnboardingPr } from './onboarding/pr'; import { ensureOnboardingPr } from './onboarding/pr';
import { processResult, ProcessResult } from './result'; import { processResult, ProcessResult } from './result';
import { processRepo } from './process'; import { processRepo, updateRepo } from './process';
import { finaliseRepo } from './finalise'; import { finaliseRepo } from './finalise';
import { ensureMasterIssue } from './master-issue'; import { ensureMasterIssue } from './master-issue';
import { RenovateConfig } from '../../config'; import { RenovateConfig } from '../../config';
import { extractChangeLogJSON } from './extract';
let renovateVersion = 'unknown'; let renovateVersion = 'unknown';
try { try {
...@@ -31,10 +32,15 @@ export async function renovateRepository( ...@@ -31,10 +32,15 @@ export async function renovateRepository(
await fs.ensureDir(config.localDir); await fs.ensureDir(config.localDir);
logger.debug('Using localDir: ' + config.localDir); logger.debug('Using localDir: ' + config.localDir);
config = await initRepo(config); config = await initRepo(config);
const { res, branches, branchList, packageFiles } = await processRepo( const { branches, branchList, packageFiles } = await processRepo(config);
config await extractChangeLogJSON(branches);
);
await ensureOnboardingPr(config, packageFiles, branches); await ensureOnboardingPr(config, packageFiles, branches);
const { res } = await updateRepo(
config,
branches,
branchList,
packageFiles
);
if (res !== 'automerged') { if (res !== 'automerged') {
await ensureMasterIssue(config, branches); await ensureMasterIssue(config, branches);
} }
......
...@@ -10,7 +10,6 @@ Object { ...@@ -10,7 +10,6 @@ Object {
undefined, undefined,
undefined, undefined,
], ],
"res": undefined,
} }
`; `;
......
import { extractAndUpdate } from './extract-update'; import { extract, update } from './extract-update';
import * as _branchify from '../updates/branchify'; import * as _branchify from '../updates/branchify';
import { mocked } from '../../../../test/util'; import { mocked } from '../../../../test/util';
...@@ -16,13 +16,14 @@ branchify.branchifyUpgrades.mockResolvedValueOnce({ ...@@ -16,13 +16,14 @@ branchify.branchifyUpgrades.mockResolvedValueOnce({
}); });
describe('workers/repository/process/extract-update', () => { describe('workers/repository/process/extract-update', () => {
describe('extractAndUpdate()', () => { describe('extract()', () => {
it('runs', async () => { it('runs', async () => {
const config = { const config = {
repoIsOnboarded: true, repoIsOnboarded: true,
suppressNotifications: ['deprecationWarningIssues'], suppressNotifications: ['deprecationWarningIssues'],
}; };
await extractAndUpdate(config); const res = await extract(config);
await update(config, res.branches, res.branchList, res.packageFiles);
}); });
}); });
}); });
...@@ -9,16 +9,17 @@ import { PackageFile } from '../../../manager/common'; ...@@ -9,16 +9,17 @@ import { PackageFile } from '../../../manager/common';
import { RenovateConfig } from '../../../config'; import { RenovateConfig } from '../../../config';
import { BranchConfig } from '../../common'; import { BranchConfig } from '../../common';
export type ExtractAndUpdateResult = { export type ExtractResult = {
res: WriteUpdateResult | undefined;
branches: BranchConfig[]; branches: BranchConfig[];
branchList: string[]; branchList: string[];
packageFiles?: Record<string, PackageFile[]>; packageFiles?: Record<string, PackageFile[]>;
}; };
export async function extractAndUpdate( export type UpdateResult = {
config: RenovateConfig res: WriteUpdateResult | undefined;
): Promise<ExtractAndUpdateResult> { };
export async function extract(config: RenovateConfig): Promise<ExtractResult> {
logger.debug('extractAndUpdate()'); logger.debug('extractAndUpdate()');
const packageFiles = await extractAllDependencies(config); const packageFiles = await extractAllDependencies(config);
logger.trace({ config: packageFiles }, 'packageFiles'); logger.trace({ config: packageFiles }, 'packageFiles');
...@@ -30,10 +31,20 @@ export async function extractAndUpdate( ...@@ -30,10 +31,20 @@ export async function extractAndUpdate(
packageFiles packageFiles
); );
sortBranches(branches); 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; let res: WriteUpdateResult | undefined;
// istanbul ignore else // istanbul ignore else
if (config.repoIsOnboarded) { if (config.repoIsOnboarded) {
res = await writeUpdates(config, packageFiles, branches); res = await writeUpdates(config, packageFiles, branches);
} }
return { res, branches, branchList, packageFiles };
return { res };
} }
import { processRepo } from './index'; import { processRepo, updateRepo } from './index';
import * as _extractUpdate from './extract-update'; import * as _extractUpdate from './extract-update';
import { getConfig, mocked, RenovateConfig } from '../../../../test/util'; import { getConfig, mocked, RenovateConfig } from '../../../../test/util';
jest.mock('./extract-update'); jest.mock('./extract-update');
const extractAndUpdate = mocked(_extractUpdate).extractAndUpdate; const extract = mocked(_extractUpdate).extract;
let config: RenovateConfig; let config: RenovateConfig;
beforeEach(() => { beforeEach(() => {
...@@ -19,9 +19,10 @@ describe('workers/repository/process/index', () => { ...@@ -19,9 +19,10 @@ describe('workers/repository/process/index', () => {
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
it('processes baseBranches', async () => { it('processes baseBranches', async () => {
extractAndUpdate.mockResolvedValue({} as never); extract.mockResolvedValue({} as never);
config.baseBranches = ['branch1', 'branch2']; config.baseBranches = ['branch1', 'branch2'];
const res = await processRepo(config); const res = await processRepo(config);
await updateRepo(config, res.branches, res.branchList, res.packageFiles);
expect(res).toMatchSnapshot(); expect(res).toMatchSnapshot();
}); });
}); });
......
import { logger } from '../../../logger'; import { logger } from '../../../logger';
import { mergeChildConfig, RenovateConfig } from '../../../config'; import { mergeChildConfig, RenovateConfig } from '../../../config';
import { extractAndUpdate, ExtractAndUpdateResult } from './extract-update'; import { extract, ExtractResult, update, UpdateResult } from './extract-update';
import { platform } from '../../../platform'; import { platform } from '../../../platform';
import { WriteUpdateResult } from './write';
import { BranchConfig } from '../../common'; import { BranchConfig } from '../../common';
import { PackageFile } from '../../../manager/common';
export async function processRepo( export async function processRepo(
config: RenovateConfig config: RenovateConfig
): Promise<ExtractAndUpdateResult> { ): Promise<ExtractResult> {
logger.debug('processRepo()'); logger.debug('processRepo()');
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
config.masterIssueChecks = {}; config.masterIssueChecks = {};
...@@ -45,7 +45,6 @@ export async function processRepo( ...@@ -45,7 +45,6 @@ export async function processRepo(
} }
if (config.baseBranches && config.baseBranches.length) { if (config.baseBranches && config.baseBranches.length) {
logger.debug({ baseBranches: config.baseBranches }, 'baseBranches'); logger.debug({ baseBranches: config.baseBranches }, 'baseBranches');
let res: WriteUpdateResult | undefined;
let branches: BranchConfig[] = []; let branches: BranchConfig[] = [];
let branchList: string[] = []; let branchList: string[] = [];
for (const baseBranch of config.baseBranches) { for (const baseBranch of config.baseBranches) {
...@@ -56,13 +55,23 @@ export async function processRepo( ...@@ -56,13 +55,23 @@ export async function processRepo(
baseBranchConfig.hasBaseBranches = true; baseBranchConfig.hasBaseBranches = true;
} }
await platform.setBaseBranch(baseBranch); await platform.setBaseBranch(baseBranch);
const baseBranchRes = await extractAndUpdate(baseBranchConfig); const baseBranchRes = await extract(baseBranchConfig);
({ res } = baseBranchRes);
branches = branches.concat(baseBranchRes.branches); branches = branches.concat(baseBranchRes.branches);
branchList = branchList.concat(baseBranchRes.branchList); branchList = branchList.concat(baseBranchRes.branchList);
} }
return { res, branches, branchList }; return { branches, branchList };
} }
logger.debug('No baseBranches'); logger.debug('No baseBranches');
return extractAndUpdate(config); 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);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment