mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 22:46:27 +00:00
feat(internal): perform changelog retrieval before branch creat… (#5966)
This commit is contained in:
parent
f9db9b06fd
commit
0a2dc73bf7
11 changed files with 68 additions and 30 deletions
|
@ -13,6 +13,7 @@ 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>,
|
||||
|
@ -47,8 +48,11 @@ export interface BranchUpgradeConfig
|
|||
releaseTimestamp?: string;
|
||||
|
||||
sourceDirectory?: string;
|
||||
|
||||
updatedPackageFiles?: File[];
|
||||
updatedArtifacts?: File[];
|
||||
|
||||
logJSON?: ChangeLogResult;
|
||||
}
|
||||
|
||||
export enum PrResult {
|
||||
|
|
|
@ -6,6 +6,7 @@ import { mocked } from '../../../test/util';
|
|||
import { BranchStatus } from '../../types';
|
||||
import { PLATFORM_TYPE_GITLAB } from '../../constants/platforms';
|
||||
import { PrResult } from '../common';
|
||||
import { getChangeLogJSON } from './changelog';
|
||||
|
||||
const changelogHelper = mocked(_changelogHelper);
|
||||
const platform = mocked(_platform);
|
||||
|
@ -180,6 +181,7 @@ describe('workers/pr', () => {
|
|||
});
|
||||
it('should create PR if success', async () => {
|
||||
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
config.prCreation = 'status-success';
|
||||
config.automerge = true;
|
||||
config.schedule = 'before 5am';
|
||||
|
@ -217,6 +219,9 @@ describe('workers/pr', () => {
|
|||
config.updateType = 'lockFileMaintenance';
|
||||
config.recreateClosed = true;
|
||||
config.rebaseWhen = 'never';
|
||||
for (const upgrade of config.upgrades) {
|
||||
upgrade.logJSON = await getChangeLogJSON(upgrade);
|
||||
}
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.Created);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
|
@ -230,6 +235,7 @@ describe('workers/pr', () => {
|
|||
config.schedule = 'before 5am';
|
||||
config.timezone = 'some timezone';
|
||||
config.rebaseWhen = 'behind-base-branch';
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.Created);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
|
@ -369,6 +375,7 @@ describe('workers/pr', () => {
|
|||
config.semanticCommitScope = null;
|
||||
config.automerge = true;
|
||||
config.schedule = 'before 5am';
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.NotUpdated);
|
||||
expect(platform.updatePr.mock.calls).toMatchSnapshot();
|
||||
|
@ -383,6 +390,7 @@ describe('workers/pr', () => {
|
|||
config.semanticCommitScope = null;
|
||||
config.automerge = true;
|
||||
config.schedule = 'before 5am';
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.NotUpdated);
|
||||
expect(platform.updatePr).toHaveBeenCalledTimes(0);
|
||||
|
@ -392,6 +400,7 @@ describe('workers/pr', () => {
|
|||
config.newValue = '1.2.0';
|
||||
config.automerge = true;
|
||||
config.schedule = 'before 5am';
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
platform.getBranchPr.mockResolvedValueOnce(existingPr);
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.NotUpdated);
|
||||
|
@ -455,6 +464,7 @@ describe('workers/pr', () => {
|
|||
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
|
||||
config.prCreation = 'status-success';
|
||||
config.privateRepo = false;
|
||||
config.logJSON = await getChangeLogJSON(config);
|
||||
const { prResult, pr } = await prWorker.ensurePr(config);
|
||||
expect(prResult).toEqual(PrResult.Created);
|
||||
expect(pr).toMatchObject({ displayNumber: 'New Pull Request' });
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import sampleSize from 'lodash/sampleSize';
|
||||
import uniq from 'lodash/uniq';
|
||||
import { logger } from '../../logger';
|
||||
import { ChangeLogError, getChangeLogJSON } from './changelog';
|
||||
import { ChangeLogError } from './changelog';
|
||||
import { getPrBody } from './body';
|
||||
import { platform, Pr, PlatformPrOptions } from '../../platform';
|
||||
import { BranchConfig, PrResult } from '../common';
|
||||
|
@ -193,7 +193,7 @@ export async function ensurePr(
|
|||
}
|
||||
processedUpgrades.push(upgradeKey);
|
||||
|
||||
const logJSON = await getChangeLogJSON(upgrade);
|
||||
const logJSON = upgrade.logJSON;
|
||||
|
||||
if (logJSON) {
|
||||
if (typeof logJSON.error === 'undefined') {
|
||||
|
|
|
@ -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 { ExtractAndUpdateResult } from './process/extract-update';
|
||||
import { ExtractResult } from './process/extract-update';
|
||||
|
||||
const process = mocked(_process);
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe('workers/repository', () => {
|
|||
config = getConfig();
|
||||
});
|
||||
it('runs', async () => {
|
||||
process.processRepo.mockResolvedValue(mock<ExtractAndUpdateResult>());
|
||||
process.processRepo.mockResolvedValue(mock<ExtractResult>());
|
||||
const res = await renovateRepository(config);
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ import { logger, setMeta } from '../../logger';
|
|||
import { initRepo } from './init';
|
||||
import { ensureOnboardingPr } from './onboarding/pr';
|
||||
import { processResult, ProcessResult } from './result';
|
||||
import { processRepo } from './process';
|
||||
import { processRepo, updateRepo } from './process';
|
||||
import { finaliseRepo } from './finalise';
|
||||
import { ensureMasterIssue } from './master-issue';
|
||||
import { RenovateConfig } from '../../config';
|
||||
|
@ -31,10 +31,9 @@ export async function renovateRepository(
|
|||
await fs.ensureDir(config.localDir);
|
||||
logger.debug('Using localDir: ' + config.localDir);
|
||||
config = await initRepo(config);
|
||||
const { res, branches, branchList, packageFiles } = await processRepo(
|
||||
config
|
||||
);
|
||||
const { branches, branchList, packageFiles } = await processRepo(config);
|
||||
await ensureOnboardingPr(config, packageFiles, branches);
|
||||
const res = await updateRepo(config, branches, branchList, packageFiles);
|
||||
if (res !== 'automerged') {
|
||||
await ensureMasterIssue(config, branches);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ Object {
|
|||
undefined,
|
||||
undefined,
|
||||
],
|
||||
"res": undefined,
|
||||
"packageFiles": undefined,
|
||||
}
|
||||
`;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { extractAndUpdate } from './extract-update';
|
||||
import { extract, update } from './extract-update';
|
||||
import * as _branchify from '../updates/branchify';
|
||||
import { mocked } from '../../../../test/util';
|
||||
|
||||
|
@ -16,13 +16,14 @@ branchify.branchifyUpgrades.mockResolvedValueOnce({
|
|||
});
|
||||
|
||||
describe('workers/repository/process/extract-update', () => {
|
||||
describe('extractAndUpdate()', () => {
|
||||
describe('extract()', () => {
|
||||
it('runs', async () => {
|
||||
const config = {
|
||||
repoIsOnboarded: true,
|
||||
suppressNotifications: ['deprecationWarningIssues'],
|
||||
};
|
||||
await extractAndUpdate(config);
|
||||
const res = await extract(config);
|
||||
await update(config, res.branches, res.branchList, res.packageFiles);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,16 +9,13 @@ import { PackageFile } from '../../../manager/common';
|
|||
import { RenovateConfig } from '../../../config';
|
||||
import { BranchConfig } from '../../common';
|
||||
|
||||
export type ExtractAndUpdateResult = {
|
||||
res: WriteUpdateResult | undefined;
|
||||
export type ExtractResult = {
|
||||
branches: BranchConfig[];
|
||||
branchList: string[];
|
||||
packageFiles?: Record<string, PackageFile[]>;
|
||||
packageFiles: Record<string, PackageFile[]>;
|
||||
};
|
||||
|
||||
export async function extractAndUpdate(
|
||||
config: RenovateConfig
|
||||
): Promise<ExtractAndUpdateResult> {
|
||||
export async function extract(config: RenovateConfig): Promise<ExtractResult> {
|
||||
logger.debug('extractAndUpdate()');
|
||||
const packageFiles = await extractAllDependencies(config);
|
||||
logger.trace({ config: packageFiles }, 'packageFiles');
|
||||
|
@ -30,10 +27,20 @@ export async function extractAndUpdate(
|
|||
packageFiles
|
||||
);
|
||||
sortBranches(branches);
|
||||
return { branches, branchList, packageFiles };
|
||||
}
|
||||
|
||||
export async function update(
|
||||
config: RenovateConfig,
|
||||
branches: BranchConfig[],
|
||||
branchList: string[],
|
||||
packageFiles: Record<string, PackageFile[]>
|
||||
): Promise<WriteUpdateResult | undefined> {
|
||||
let res: WriteUpdateResult | undefined;
|
||||
// istanbul ignore else
|
||||
if (config.repoIsOnboarded) {
|
||||
res = await writeUpdates(config, packageFiles, branches);
|
||||
}
|
||||
return { res, branches, branchList, packageFiles };
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { processRepo } from './index';
|
||||
import { processRepo, updateRepo } from './index';
|
||||
import * as _extractUpdate from './extract-update';
|
||||
import { getConfig, mocked, RenovateConfig } from '../../../../test/util';
|
||||
|
||||
jest.mock('./extract-update');
|
||||
|
||||
const extractAndUpdate = mocked(_extractUpdate).extractAndUpdate;
|
||||
const extract = mocked(_extractUpdate).extract;
|
||||
|
||||
let config: RenovateConfig;
|
||||
beforeEach(() => {
|
||||
|
@ -19,9 +19,10 @@ describe('workers/repository/process/index', () => {
|
|||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
it('processes baseBranches', async () => {
|
||||
extractAndUpdate.mockResolvedValue({} as never);
|
||||
extract.mockResolvedValue({} as never);
|
||||
config.baseBranches = ['branch1', 'branch2'];
|
||||
const res = await processRepo(config);
|
||||
await updateRepo(config, res.branches, res.branchList, res.packageFiles);
|
||||
expect(res).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import { logger } from '../../../logger';
|
||||
import { mergeChildConfig, RenovateConfig } from '../../../config';
|
||||
import { extractAndUpdate, ExtractAndUpdateResult } from './extract-update';
|
||||
import { extract, ExtractResult, update } from './extract-update';
|
||||
import { platform } from '../../../platform';
|
||||
import { WriteUpdateResult } from './write';
|
||||
import { BranchConfig } from '../../common';
|
||||
import { PackageFile } from '../../../manager/common';
|
||||
import { WriteUpdateResult } from './write';
|
||||
|
||||
export async function processRepo(
|
||||
config: RenovateConfig
|
||||
): Promise<ExtractAndUpdateResult> {
|
||||
): Promise<ExtractResult> {
|
||||
logger.debug('processRepo()');
|
||||
/* eslint-disable no-param-reassign */
|
||||
config.masterIssueChecks = {};
|
||||
|
@ -45,9 +46,9 @@ 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[] = [];
|
||||
let packageFiles: Record<string, PackageFile[]>;
|
||||
for (const baseBranch of config.baseBranches) {
|
||||
logger.debug(`baseBranch: ${baseBranch}`);
|
||||
const baseBranchConfig = mergeChildConfig(config, { baseBranch });
|
||||
|
@ -56,13 +57,24 @@ export async function processRepo(
|
|||
baseBranchConfig.hasBaseBranches = true;
|
||||
}
|
||||
await platform.setBaseBranch(baseBranch);
|
||||
const baseBranchRes = await extractAndUpdate(baseBranchConfig);
|
||||
({ res } = baseBranchRes);
|
||||
const baseBranchRes = await extract(baseBranchConfig);
|
||||
branches = branches.concat(baseBranchRes.branches);
|
||||
branchList = branchList.concat(baseBranchRes.branchList);
|
||||
packageFiles = baseBranchRes.packageFiles;
|
||||
}
|
||||
return { res, branches, branchList };
|
||||
return { branches, branchList, packageFiles };
|
||||
}
|
||||
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<WriteUpdateResult | undefined> {
|
||||
logger.debug('processRepo()');
|
||||
|
||||
return update(config, branches, branchList, packageFiles);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import { generateBranchConfig } from './generate';
|
|||
import { flattenUpdates } from './flatten';
|
||||
import { RenovateConfig, ValidationMessage } from '../../../config';
|
||||
import { BranchUpgradeConfig, BranchConfig } from '../../common';
|
||||
import { getChangeLogJSON } from '../../pr/changelog';
|
||||
|
||||
/**
|
||||
* Clean git branch name
|
||||
|
@ -113,6 +114,9 @@ export async function branchifyUpgrades(
|
|||
addMeta({
|
||||
branch: branchName,
|
||||
});
|
||||
for (const upgrade of branchUpgrades[branchName]) {
|
||||
upgrade.logJSON = await getChangeLogJSON(upgrade);
|
||||
}
|
||||
const branch = generateBranchConfig(branchUpgrades[branchName]);
|
||||
branch.branchName = branchName;
|
||||
branches.push(branch);
|
||||
|
|
Loading…
Reference in a new issue