mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +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';
|
} 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
|
||||||
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';
|
||||||
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 { getChangeLogJSON } from './changelog';
|
||||||
|
|
||||||
const changelogHelper = mocked(_changelogHelper);
|
const changelogHelper = mocked(_changelogHelper);
|
||||||
const platform = mocked(_platform);
|
const platform = mocked(_platform);
|
||||||
|
@ -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);
|
||||||
|
config.logJSON = await getChangeLogJSON(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', () => {
|
||||||
config.updateType = 'lockFileMaintenance';
|
config.updateType = 'lockFileMaintenance';
|
||||||
config.recreateClosed = true;
|
config.recreateClosed = true;
|
||||||
config.rebaseWhen = 'never';
|
config.rebaseWhen = 'never';
|
||||||
|
for (const upgrade of config.upgrades) {
|
||||||
|
upgrade.logJSON = await getChangeLogJSON(upgrade);
|
||||||
|
}
|
||||||
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', () => {
|
||||||
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';
|
||||||
|
config.logJSON = await getChangeLogJSON(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', () => {
|
||||||
config.semanticCommitScope = null;
|
config.semanticCommitScope = null;
|
||||||
config.automerge = true;
|
config.automerge = true;
|
||||||
config.schedule = 'before 5am';
|
config.schedule = 'before 5am';
|
||||||
|
config.logJSON = await getChangeLogJSON(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', () => {
|
||||||
config.semanticCommitScope = null;
|
config.semanticCommitScope = null;
|
||||||
config.automerge = true;
|
config.automerge = true;
|
||||||
config.schedule = 'before 5am';
|
config.schedule = 'before 5am';
|
||||||
|
config.logJSON = await getChangeLogJSON(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', () => {
|
||||||
config.newValue = '1.2.0';
|
config.newValue = '1.2.0';
|
||||||
config.automerge = true;
|
config.automerge = true;
|
||||||
config.schedule = 'before 5am';
|
config.schedule = 'before 5am';
|
||||||
|
config.logJSON = await getChangeLogJSON(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', () => {
|
||||||
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
|
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
|
||||||
config.prCreation = 'status-success';
|
config.prCreation = 'status-success';
|
||||||
config.privateRepo = false;
|
config.privateRepo = false;
|
||||||
|
config.logJSON = await getChangeLogJSON(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' });
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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(
|
||||||
}
|
}
|
||||||
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') {
|
||||||
|
|
|
@ -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', () => {
|
||||||
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,7 +6,7 @@ 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';
|
||||||
|
@ -31,10 +31,9 @@ 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 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,7 @@ Object {
|
||||||
undefined,
|
undefined,
|
||||||
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 * as _branchify from '../updates/branchify';
|
||||||
import { mocked } from '../../../../test/util';
|
import { mocked } from '../../../../test/util';
|
||||||
|
|
||||||
|
@ -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,13 @@ 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 async function extract(config: RenovateConfig): Promise<ExtractResult> {
|
||||||
config: RenovateConfig
|
|
||||||
): Promise<ExtractAndUpdateResult> {
|
|
||||||
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 +27,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<WriteUpdateResult | undefined> {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
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', () => {
|
||||||
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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
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 } 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';
|
||||||
|
import { WriteUpdateResult } from './write';
|
||||||
|
|
||||||
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,9 +46,9 @@ 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[] = [];
|
||||||
|
let packageFiles: Record<string, PackageFile[]>;
|
||||||
for (const baseBranch of config.baseBranches) {
|
for (const baseBranch of config.baseBranches) {
|
||||||
logger.debug(`baseBranch: ${baseBranch}`);
|
logger.debug(`baseBranch: ${baseBranch}`);
|
||||||
const baseBranchConfig = mergeChildConfig(config, { baseBranch });
|
const baseBranchConfig = mergeChildConfig(config, { baseBranch });
|
||||||
|
@ -56,13 +57,24 @@ 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);
|
||||||
|
packageFiles = baseBranchRes.packageFiles;
|
||||||
}
|
}
|
||||||
return { res, branches, branchList };
|
return { branches, branchList, packageFiles };
|
||||||
}
|
}
|
||||||
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<WriteUpdateResult | undefined> {
|
||||||
|
logger.debug('processRepo()');
|
||||||
|
|
||||||
|
return update(config, branches, branchList, packageFiles);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { generateBranchConfig } from './generate';
|
||||||
import { flattenUpdates } from './flatten';
|
import { flattenUpdates } from './flatten';
|
||||||
import { RenovateConfig, ValidationMessage } from '../../../config';
|
import { RenovateConfig, ValidationMessage } from '../../../config';
|
||||||
import { BranchUpgradeConfig, BranchConfig } from '../../common';
|
import { BranchUpgradeConfig, BranchConfig } from '../../common';
|
||||||
|
import { getChangeLogJSON } from '../../pr/changelog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean git branch name
|
* Clean git branch name
|
||||||
|
@ -113,6 +114,9 @@ export async function branchifyUpgrades(
|
||||||
addMeta({
|
addMeta({
|
||||||
branch: branchName,
|
branch: branchName,
|
||||||
});
|
});
|
||||||
|
for (const upgrade of branchUpgrades[branchName]) {
|
||||||
|
upgrade.logJSON = await getChangeLogJSON(upgrade);
|
||||||
|
}
|
||||||
const branch = generateBranchConfig(branchUpgrades[branchName]);
|
const branch = generateBranchConfig(branchUpgrades[branchName]);
|
||||||
branch.branchName = branchName;
|
branch.branchName = branchName;
|
||||||
branches.push(branch);
|
branches.push(branch);
|
||||||
|
|
Loading…
Reference in a new issue