From c6d7168f44a754147d4ac5aaca50f40f1bb67c97 Mon Sep 17 00:00:00 2001 From: Philip <42116482+PhilipAbed@users.noreply.github.com> Date: Thu, 18 May 2023 08:59:43 +0300 Subject: [PATCH] feat: log extended branch summary (#22056) --- lib/util/cache/repository/types.ts | 22 +++++-- lib/workers/repository/cache.ts | 21 +++++- .../repository/dependency-dashboard.ts | 1 + .../finalize/repository-statistics.spec.ts | 34 ++++++++++ .../finalize/repository-statistics.ts | 66 ++++++++++++++++++- lib/workers/types.ts | 4 +- 6 files changed, 139 insertions(+), 9 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index bbcb484864d822..3af4fa03d44c32 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -1,9 +1,11 @@ import type { RepositoryCacheConfig, RepositoryCacheType, + UpdateType, } from '../../../config/types'; import type { PackageFile } from '../../../modules/manager/types'; import type { RepoInitConfig } from '../../../workers/repository/init/types'; +import type { PrBlockedBy } from '../../../workers/types'; export interface BaseBranchCache { sha: string; // branch commit sha @@ -17,6 +19,8 @@ export interface BranchUpgradeCache { currentValue?: string; datasource?: string; depName?: string; + depType?: string; + displayPending?: unknown; fixedVersion?: string; currentVersion?: string; packageName?: string; @@ -24,6 +28,9 @@ export interface BranchUpgradeCache { newValue?: string; newVersion?: string; sourceUrl?: string; + packageFile?: string; + remediationNotPossible?: unknown; + updateType?: UpdateType; } export interface OnboardingBranchCache { @@ -45,15 +52,15 @@ export interface BranchCache { /** * Whether this branch has automerge enabled */ - automerge: boolean; + automerge?: boolean; /** * Name of base branch */ - baseBranch: string; + baseBranch?: string; /** * The base branch's most recent commit SHA */ - baseBranchSha: string | null; + baseBranchSha?: string | null; /** * Hash of the manager fingerprints and the filtered update branch config */ @@ -85,7 +92,7 @@ export interface BranchCache { /** * The branch's most recent commit SHA */ - sha: string | null; + sha?: string | null; /** * Details on the dependency upgrades that have been applied in this branch */ @@ -94,6 +101,13 @@ export interface BranchCache { * Object that has PR info */ prCache?: PrCache | null; + + /** + * Dependency dashboard information + */ + prBlockedBy?: PrBlockedBy; + prTitle?: string; + result?: string; } export interface RepoCacheData { diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index e80979449435d9..684c6220524297 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -22,23 +22,37 @@ function generateBranchUpgradeCache( const { datasource, depName, + depType, + displayPending, packageName, fixedVersion, currentVersion, newVersion, + currentValue, + newValue, currentDigest, newDigest, + packageFile, sourceUrl, + remediationNotPossible, + updateType, } = upgrade; const result: BranchUpgradeCache = { datasource, depName, + depType, + displayPending, fixedVersion, currentVersion, + currentValue, + newValue, newVersion, currentDigest, newDigest, + packageFile, sourceUrl, + remediationNotPossible, + updateType, }; if (packageName) { result.packageName = packageName; @@ -49,7 +63,7 @@ function generateBranchUpgradeCache( async function generateBranchCache( branch: BranchConfig ): Promise { - const { baseBranch, branchName } = branch; + const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch; try { const branchSha = await scm.getBranchCommit(branchName); const baseBranchSha = await scm.getBranchCommit(baseBranch); @@ -79,12 +93,14 @@ async function generateBranchCache( baseBranchSha ) ?? undefined; } + const automerge = !!branch.automerge; const upgrades: BranchUpgradeCache[] = branch.upgrades ? branch.upgrades.map(generateBranchUpgradeCache) : []; const branchFingerprint = branch.branchFingerprint; const prCache = getPrCache(branchName); + return { automerge, baseBranchSha, @@ -94,9 +110,12 @@ async function generateBranchCache( isBehindBase, isConflicted, isModified, + prBlockedBy, pristine, prCache, prNo, + prTitle, + result, sha: branchSha, upgrades, }; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 15759ff691a181..dfd9119169454c 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -168,6 +168,7 @@ function appendRepoProblems(config: RenovateConfig, issueBody: string): string { ) ); if (repoProblems.size) { + logger.debug({ repoProblems }, 'repository problems'); newIssueBody += '## Repository problems\n\n'; newIssueBody += 'These problems occurred while renovating this repository.\n\n'; diff --git a/lib/workers/repository/finalize/repository-statistics.spec.ts b/lib/workers/repository/finalize/repository-statistics.spec.ts index 3f2c323550e1be..68f7ff022e6f5c 100644 --- a/lib/workers/repository/finalize/repository-statistics.spec.ts +++ b/lib/workers/repository/finalize/repository-statistics.spec.ts @@ -11,6 +11,7 @@ import * as cache from '../../../util/cache/repository'; import type { BaseBranchCache, BranchCache, + BranchUpgradeCache, RepoCacheData, } from '../../../util/cache/repository/types'; import { @@ -103,6 +104,7 @@ describe('workers/repository/finalize/repository-statistics', () => { isModified: false, automerge: false, pristine: false, + upgrades: [], }); const expectedMeta = { automerge: branchCache.automerge, @@ -152,5 +154,37 @@ describe('workers/repository/finalize/repository-statistics', () => { `Branch summary` ); }); + + it('logs extended branch info if branchSummaryExtended', () => { + const defaultBranch = 'main'; + const config: RenovateConfig = { + defaultBranch, + branchSummaryExtended: true, + }; + const branchCache = partial({ + result: 'done', + upgrades: partial([ + { + datasource: 'npm', + depName: 'minimist', + currentValue: '1.2.3', + sourceUrl: 'someUrl', + depType: 'dependencies', + }, + ]), + }); + + const branches: BranchCache[] = [{ ...branchCache, branchName: 'b1' }]; + const cache = partial({ + scan: {}, + branches, + }); + getCacheSpy.mockReturnValueOnce(cache); + isCacheModifiedSpy.mockReturnValueOnce(false); + + runBranchSummary(config); + + expect(logger.debug).toHaveBeenCalledTimes(2); + }); }); }); diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index 1d3e487d6fd5be..e2b5224a5be35c 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -2,7 +2,10 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; import type { Pr } from '../../../modules/platform'; import { getCache, isCacheModified } from '../../../util/cache/repository'; -import type { BranchCache } from '../../../util/cache/repository/types'; +import type { + BranchCache, + BranchUpgradeCache, +} from '../../../util/cache/repository/types'; import type { BaseBranchMetadata, BranchMetadata, @@ -60,7 +63,61 @@ function branchCacheToMetadata({ }; } -export function runBranchSummary({ defaultBranch }: RenovateConfig): void { +function filterDependencyDashboardData( + branches: BranchCache[] +): Partial[] { + const branchesFiltered: Partial[] = []; + for (const branch of branches) { + const upgradesFiltered: Partial[] = []; + const { branchName, prNo, prTitle, result, upgrades, prBlockedBy } = branch; + + for (const upgrade of upgrades ?? []) { + const { + datasource, + depName, + displayPending, + fixedVersion, + currentVersion, + currentValue, + newValue, + newVersion, + packageFile, + updateType, + packageName, + } = upgrade; + + const filteredUpgrade: Partial = { + datasource, + depName, + displayPending, + fixedVersion, + currentVersion, + currentValue, + newValue, + newVersion, + packageFile, + updateType, + packageName, + }; + upgradesFiltered.push(filteredUpgrade); + } + + const filteredBranch: Partial = { + branchName, + prNo, + prTitle, + result, + prBlockedBy, + upgrades: upgradesFiltered, + }; + branchesFiltered.push(filteredBranch); + } + + return branchesFiltered; +} + +export function runBranchSummary(config: RenovateConfig): void { + const defaultBranch = config.defaultBranch; const { scan, branches } = getCache(); const baseMetadata: BaseBranchMetadata[] = []; @@ -88,4 +145,9 @@ export function runBranchSummary({ defaultBranch }: RenovateConfig): void { }; logger.debug(res, 'Branch summary'); + + if (branches?.length) { + const branchesInformation = filterDependencyDashboardData(branches); + logger.debug({ branchesInformation }, 'branches info extended'); + } } diff --git a/lib/workers/types.ts b/lib/workers/types.ts index b2ba4e1c265a32..27ac01583ae953 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -132,10 +132,10 @@ export interface BranchConfig export interface BranchMetadata { branchName: string; - branchSha: string | null; + branchSha?: string | null; baseBranch?: string; baseBranchSha?: string | null; - automerge: boolean; + automerge?: boolean; isModified?: boolean; isPristine?: boolean; }