diff --git a/lib/logger/pretty-stdout.ts b/lib/logger/pretty-stdout.ts index 2259b880177b5b1425ab32e9d3bdb44a7ec8d37b..6cb1282494f3782fbce7b0cbac7753cbc2175b55 100644 --- a/lib/logger/pretty-stdout.ts +++ b/lib/logger/pretty-stdout.ts @@ -19,6 +19,7 @@ const bunyanFields = [ ]; const metaFields = [ 'repository', + 'baseBranch', 'packageFile', 'depType', 'dependency', diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts index 98eefd5de0bc051022aeae58c3a4eeb22513430b..e151e5b7aeb2d8259cc3219f97c97b16a913d736 100644 --- a/lib/workers/repository/process/extract-update.ts +++ b/lib/workers/repository/process/extract-update.ts @@ -129,7 +129,10 @@ export async function lookup( config, packageFiles ); - logger.debug({ config: packageFiles }, 'packageFiles with updates'); + logger.debug( + { baseBranch: config.baseBranch, config: packageFiles }, + 'packageFiles with updates' + ); sortBranches(branches); return { branches, branchList, packageFiles }; } diff --git a/lib/workers/repository/process/index.spec.ts b/lib/workers/repository/process/index.spec.ts index 143837f27f159d77a5f9209e9c871e558bbafeae..0e45a6058e78b6722e07f84025f06aa06b53da96 100644 --- a/lib/workers/repository/process/index.spec.ts +++ b/lib/workers/repository/process/index.spec.ts @@ -7,6 +7,7 @@ import { } from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; import { CONFIG_VALIDATION } from '../../../constants/error-messages'; +import { addMeta } from '../../../logger'; import { getCache } from '../../../util/cache/repository'; import * as _extractUpdate from './extract-update'; import { lookup } from './extract-update'; @@ -83,6 +84,8 @@ describe('workers/repository/process/index', () => { undefined, 'dev' ); + expect(addMeta).toHaveBeenNthCalledWith(1, { baseBranch: 'master' }); + expect(addMeta).toHaveBeenNthCalledWith(2, { baseBranch: 'dev' }); }); it('handles config name mismatch between baseBranches if useBaseBranchConfig specified', async () => { @@ -101,6 +104,8 @@ describe('workers/repository/process/index', () => { await expect(extractDependencies(config)).rejects.toThrow( CONFIG_VALIDATION ); + expect(addMeta).toHaveBeenNthCalledWith(1, { baseBranch: 'master' }); + expect(addMeta).toHaveBeenNthCalledWith(2, { baseBranch: 'dev' }); }); it('processes baseBranches dryRun extract', async () => { diff --git a/lib/workers/repository/process/index.ts b/lib/workers/repository/process/index.ts index 407f41014ce64ddd410cd2c3b52291a9fcdb7fab..02c9266e600095db80aa292936bc4f00a6c283a1 100644 --- a/lib/workers/repository/process/index.ts +++ b/lib/workers/repository/process/index.ts @@ -3,7 +3,7 @@ import { mergeChildConfig } from '../../../config'; import { GlobalConfig } from '../../../config/global'; import type { RenovateConfig } from '../../../config/types'; import { CONFIG_VALIDATION } from '../../../constants/error-messages'; -import { logger } from '../../../logger'; +import { addMeta, logger, removeMeta } from '../../../logger'; import type { PackageFile } from '../../../modules/manager/types'; import { platform } from '../../../modules/platform'; import { getCache } from '../../../util/cache/repository'; @@ -84,6 +84,7 @@ export async function extractDependencies( logger.debug({ baseBranches: config.baseBranches }, 'baseBranches'); const extracted: Record<string, Record<string, PackageFile[]>> = {}; for (const baseBranch of config.baseBranches) { + addMeta({ baseBranch }); if (branchExists(baseBranch)) { const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); extracted[baseBranch] = await extract(baseBranchConfig); @@ -94,6 +95,7 @@ export async function extractDependencies( addSplit('extract'); for (const baseBranch of config.baseBranches) { if (branchExists(baseBranch)) { + addMeta({ baseBranch }); const baseBranchConfig = await getBaseBranchConfig(baseBranch, config); const packageFiles = extracted[baseBranch]; const baseBranchRes = await lookup(baseBranchConfig, packageFiles); @@ -102,6 +104,7 @@ export async function extractDependencies( res.packageFiles = res.packageFiles || baseBranchRes?.packageFiles; // Use the first branch } } + removeMeta(['baseBranch']); } else { logger.debug('No baseBranches'); const packageFiles = await extract(config); diff --git a/lib/workers/repository/process/write.spec.ts b/lib/workers/repository/process/write.spec.ts index bf02f04a41515f93ffd8987b35f1f0799bab0722..b94cb734ba3f4a231d670ded95ca2c3297d150bb 100644 --- a/lib/workers/repository/process/write.spec.ts +++ b/lib/workers/repository/process/write.spec.ts @@ -1,5 +1,12 @@ -import { RenovateConfig, getConfig, git, mocked } from '../../../../test/util'; +import { + RenovateConfig, + getConfig, + git, + mocked, + partial, +} from '../../../../test/util'; import { GlobalConfig } from '../../../config/global'; +import { addMeta } from '../../../logger'; import { Limit, isLimitReached } from '../../global/limits'; import { BranchConfig, BranchResult } from '../../types'; import * as _branchWorker from '../update/branch'; @@ -57,7 +64,11 @@ describe('workers/repository/process/write', () => { }); it('increments branch counter', async () => { - const branches: BranchConfig[] = [{}] as never; + const branchName = 'branchName'; + const branches: BranchConfig[] = [ + partial<BranchConfig>({ baseBranch: 'main', branchName }), + partial<BranchConfig>({ baseBranch: 'dev', branchName }), + ] as never; branchWorker.processBranch.mockResolvedValueOnce({ branchExists: true, result: BranchResult.PrCreated, @@ -67,8 +78,17 @@ describe('workers/repository/process/write', () => { limits.getBranchesRemaining.mockResolvedValueOnce(1); expect(isLimitReached(Limit.Branches)).toBeFalse(); GlobalConfig.set({ dryRun: 'full' }); - await writeUpdates({ config }, branches); + config.baseBranches = ['main', 'dev']; + await writeUpdates(config, branches); expect(isLimitReached(Limit.Branches)).toBeTrue(); + expect(addMeta).toHaveBeenCalledWith({ + baseBranch: 'main', + branch: branchName, + }); + expect(addMeta).toHaveBeenCalledWith({ + baseBranch: 'dev', + branch: branchName, + }); }); }); }); diff --git a/lib/workers/repository/process/write.ts b/lib/workers/repository/process/write.ts index 4f56afd0b8052cccf2db1924eb314978b1fb8d71..dbd830c10a61062664133428b2adcc9fa9ada731 100644 --- a/lib/workers/repository/process/write.ts +++ b/lib/workers/repository/process/write.ts @@ -33,7 +33,12 @@ export async function writeUpdates( setMaxLimit(Limit.Branches, branchesRemaining); for (const branch of branches) { - addMeta({ branch: branch.branchName }); + const { baseBranch, branchName } = branch; + const meta: Record<string, string> = { branch: branchName }; + if (config.baseBranches?.length && baseBranch) { + meta['baseBranch'] = baseBranch; + } + addMeta(meta); const branchExisted = branchExists(branch.branchName); const res = await processBranch(branch); branch.prBlockedBy = res?.prBlockedBy; @@ -50,6 +55,6 @@ export async function writeUpdates( incLimitedValue(Limit.Branches); } } - removeMeta(['branch']); + removeMeta(['branch', 'baseBranch']); return 'done'; }