Skip to content

Commit

Permalink
feat: Enhance lookup logs to show branches extended info (#23696)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
PhilipAbed and viceice authored Aug 14, 2023
1 parent 4abf457 commit fe039fe
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 14 deletions.
68 changes: 68 additions & 0 deletions lib/workers/repository/finalize/__fixtures__/branches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
[
{
"branchName": "renovate/lodash-monorepo",
"prTitle": "Update dependency lodash to v4.17.21",
"upgrades": [
{
"datasource": "npm",
"depName": "lodash",
"fixedVersion": "4.17.20",
"currentVersion": "4.17.20",
"currentValue": "4.17.20",
"newValue": "4.17.21",
"newVersion": "4.17.21",
"packageFile": "package.json",
"updateType": "patch",
"packageName": "lodash"
}
]
},
{
"branchName": "renovate/date-io-monorepo",
"prTitle": "Update date-io monorepo to v2.17.0",
"upgrades": [
{
"datasource": "npm",
"depName": "@date-io/date-fns",
"fixedVersion": "2.10.0",
"currentVersion": "2.10.0",
"currentValue": "2.10.0",
"newValue": "2.17.0",
"newVersion": "2.17.0",
"packageFile": "package.json",
"updateType": "minor",
"packageName": "@date-io/date-fns"
},
{
"datasource": "npm",
"depName": "@date-io/moment",
"fixedVersion": "2.10.0",
"currentVersion": "2.10.0",
"currentValue": "2.10.0",
"newValue": "2.17.0",
"newVersion": "2.17.0",
"packageFile": "package.json",
"updateType": "minor",
"packageName": "@date-io/moment"
}
]
},
{
"branchName": "renovate/commander-11.x",
"prTitle": "Update dependency commander to v11",
"upgrades": [
{
"datasource": "npm",
"depName": "commander",
"fixedVersion": "2.20.3",
"currentVersion": "2.20.3",
"currentValue": "2.20.3",
"newValue": "11.0.0",
"newVersion": "11.0.0",
"packageFile": "package.json",
"updateType": "major",
"packageName": "commander"
}
]
}
]
6 changes: 1 addition & 5 deletions lib/workers/repository/finalize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import { clearRenovateRefs } from '../../../util/git';
import { configMigration } from '../config-migration';
import { PackageFiles } from '../package-files';
import { pruneStaleBranches } from './prune';
import {
runBranchSummary,
runRenovateRepoStats,
} from './repository-statistics';
import { runRenovateRepoStats } from './repository-statistics';

// istanbul ignore next
export async function finalizeRepo(
Expand All @@ -34,7 +31,6 @@ export async function finalizeRepo(
logger.debug('Repo is activated');
config.repoIsActivated = true;
}
runBranchSummary(config);
runRenovateRepoStats(config, prList);
}

Expand Down
26 changes: 20 additions & 6 deletions lib/workers/repository/finalize/repository-statistics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jest.mock('../../../modules/platform/github/pr');
jest.mock('../../../util/http/github');

const prJson = Fixtures.getJson('./pr-list.json');
const branchesJson = Fixtures.getJson('./branches.json');
const result = Object.keys(prJson).map((key) => {
return prJson[key];
});
Expand Down Expand Up @@ -66,7 +67,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(true);

runBranchSummary(config);
runBranchSummary(config, []);

expect(logger.debug).toHaveBeenCalledWith(
{
Expand Down Expand Up @@ -127,7 +128,7 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config);
runBranchSummary(config, []);

expect(logger.debug).toHaveBeenCalledWith(
{
Expand All @@ -153,11 +154,10 @@ describe('workers/repository/finalize/repository-statistics', () => {
);
});

it('logs extended branch info if branchSummaryExtended', () => {
it('logs extended branch info', () => {
const defaultBranch = 'main';
const config: RenovateConfig = {
defaultBranch,
branchSummaryExtended: true,
};
const branchCache = partial<BranchCache>({
result: 'done',
Expand All @@ -171,7 +171,6 @@ describe('workers/repository/finalize/repository-statistics', () => {
},
]),
});

const branches: BranchCache[] = [{ ...branchCache, branchName: 'b1' }];
const cache = partial<RepoCacheData>({
scan: {},
Expand All @@ -180,7 +179,22 @@ describe('workers/repository/finalize/repository-statistics', () => {
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config);
runBranchSummary(config, []);

expect(logger.debug).toHaveBeenCalledTimes(2);
});

it('logs extended branch info on lookup only', () => {
const config: RenovateConfig = {
defaultBranch: 'main',
};
const cache = partial<RepoCacheData>({
scan: {},
});
getCacheSpy.mockReturnValueOnce(cache);
isCacheModifiedSpy.mockReturnValueOnce(false);

runBranchSummary(config, branchesJson);

expect(logger.debug).toHaveBeenCalledTimes(2);
});
Expand Down
66 changes: 63 additions & 3 deletions lib/workers/repository/finalize/repository-statistics.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import type { RenovateConfig } from '../../../config/types';
import { logger } from '../../../logger';
import type { Pr } from '../../../modules/platform';
import { coerceArray } from '../../../util/array';
import { getCache, isCacheModified } from '../../../util/cache/repository';
import type {
BranchCache,
BranchUpgradeCache,
} from '../../../util/cache/repository/types';
import type {
BaseBranchMetadata,
BranchConfig,
BranchMetadata,
BranchSummary,
BranchUpgradeConfig,
} from '../../types';

export function runRenovateRepoStats(
Expand Down Expand Up @@ -63,6 +66,55 @@ function branchCacheToMetadata({
};
}

function filterDependencyLookupData(
branches: BranchConfig[]
): Partial<BranchConfig>[] {
const branchesFiltered: Partial<BranchConfig>[] = [];
for (const branch of branches) {
const upgradesFiltered: Partial<BranchUpgradeConfig>[] = [];
const { branchName, prTitle, upgrades } = branch;

for (const upgrade of coerceArray(upgrades)) {
const {
datasource,
depName,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
} = upgrade;

const filteredUpgrade: Partial<BranchUpgradeConfig> = {
datasource,
depName,
fixedVersion,
currentVersion,
currentValue,
newValue,
newVersion,
packageFile,
updateType,
packageName,
};
upgradesFiltered.push(filteredUpgrade);
}

const filteredBranch: Partial<BranchConfig> = {
branchName,
prTitle,
result: 'no-work',
upgrades: upgradesFiltered as BranchUpgradeConfig[],
};
branchesFiltered.push(filteredBranch);
}

return branchesFiltered;
}

function filterDependencyDashboardData(
branches: BranchCache[]
): Partial<BranchCache>[] {
Expand All @@ -71,7 +123,7 @@ function filterDependencyDashboardData(
const upgradesFiltered: Partial<BranchUpgradeCache>[] = [];
const { branchName, prNo, prTitle, result, upgrades, prBlockedBy } = branch;

for (const upgrade of upgrades ?? []) {
for (const upgrade of coerceArray(upgrades)) {
const {
datasource,
depName,
Expand Down Expand Up @@ -116,7 +168,10 @@ function filterDependencyDashboardData(
return branchesFiltered;
}

export function runBranchSummary(config: RenovateConfig): void {
export function runBranchSummary(
config: RenovateConfig,
lookupBranchConfig: BranchConfig[]
): void {
const defaultBranch = config.defaultBranch;
const { scan, branches } = getCache();

Expand Down Expand Up @@ -146,8 +201,13 @@ export function runBranchSummary(config: RenovateConfig): void {

logger.debug(res, 'Branch summary');

let branchesInformation;
if (branches?.length) {
const branchesInformation = filterDependencyDashboardData(branches);
branchesInformation = filterDependencyDashboardData(branches);
} else if (lookupBranchConfig?.length) {
branchesInformation = filterDependencyLookupData(lookupBranchConfig);
}
if (branchesInformation) {
logger.debug({ branchesInformation }, 'branches info extended');
}
}
2 changes: 2 additions & 0 deletions lib/workers/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ensureDependencyDashboard } from './dependency-dashboard';
import handleError from './error';
import { finalizeRepo } from './finalize';
import { pruneStaleBranches } from './finalize/prune';
import { runBranchSummary } from './finalize/repository-statistics';
import { initRepo } from './init';
import { OnboardingState } from './onboarding/common';
import { ensureOnboardingPr } from './onboarding/pr';
Expand Down Expand Up @@ -94,6 +95,7 @@ export async function renovateRepository(
// TODO #7154
repoResult = processResult(config, res!);
}
runBranchSummary(config, branches);
} catch (err) /* istanbul ignore next */ {
setMeta({ repository: config.repository });
const errorRes = await handleError(config, err);
Expand Down

0 comments on commit fe039fe

Please sign in to comment.