From aaa03f63d3931ecd94e10ccdaa20cd206ba805af Mon Sep 17 00:00:00 2001 From: philipabed Date: Tue, 9 May 2023 13:22:56 +0300 Subject: [PATCH 01/14] extended branch summary and dashboard info --- docs/usage/self-hosted-configuration.md | 4 + lib/config/options/index.ts | 8 + lib/config/types.ts | 1 + lib/util/cache/repository/types.ts | 21 ++ lib/workers/repository/cache.ts | 68 +++++- .../repository/dependency-dashboard.ts | 207 +++++++++++------- lib/workers/repository/errors-warnings.ts | 4 +- .../finalize/repository-statistics.spec.ts | 23 ++ .../finalize/repository-statistics.ts | 6 +- lib/workers/types.ts | 22 ++ 10 files changed, 285 insertions(+), 79 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index fcf72c943a86ab..eb298510e5565a 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -191,6 +191,10 @@ If all projects are managed by Hermit, you can tell Renovate to use the tooling Tools not on this list fall back to `binarySource=global`. +## branchSummaryExtended + +When enabled, will print extra information about the branches and dependency dashboard. + ## cacheDir By default Renovate stores cache data in a temporary directory like `/tmp/renovate/cache`. diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index a020d9dae72157..48a95f6450a42e 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2634,6 +2634,14 @@ const options: RenovateOptions[] = [ globalOnly: true, default: [], }, + { + name: 'branchSummaryExtended', + description: 'Extends the branch summary by printing all', + type: 'boolean', + experimental: true, + globalOnly: true, + default: false, + }, ]; export function getOptions(): RenovateOptions[] { diff --git a/lib/config/types.ts b/lib/config/types.ts index 0df00b27a9a688..ac3a907924731e 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -262,6 +262,7 @@ export interface RenovateConfig constraintsFiltering?: ConstraintsFilter; checkedBranches?: string[]; + branchSummaryExtended?: boolean; } export interface AllConfig diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index 6f5cbfe32601da..978186f043e3f8 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -2,8 +2,10 @@ import type { RepositoryCacheConfig, RepositoryCacheType, } from '../../../config/types'; +import { UpdateType } from '../../../config/types'; import type { PackageFile } from '../../../modules/manager/types'; import type { RepoInitConfig } from '../../../workers/repository/init/types'; +import { PrBlockedBy } from '../../../workers/types'; export interface BaseBranchCache { sha: string; // branch commit sha @@ -17,6 +19,9 @@ export interface BranchUpgradeCache { currentValue?: string; datasource?: string; depName?: string; + depNameLinked?: string; + depType?: string; + displayPending?: string; fixedVersion?: string; currentVersion?: string; packageName?: string; @@ -24,6 +29,9 @@ export interface BranchUpgradeCache { newValue?: string; newVersion?: string; sourceUrl?: string; + packageFile?: string; + remediationNotPossible?: boolean; + updateType?: UpdateType; } export interface OnboardingBranchCache { @@ -93,6 +101,19 @@ export interface BranchCache { * Object that has PR info */ prCache?: PrCache | null; + + /** + * Dependency dashboard information + */ + dependencyDashboard?: boolean; + dependencyDashboardApproval?: boolean; + dependencyDashboardPrApproval?: boolean; + dependencyDashboardTitle?: string; + dependencyDashboardFooter?: string; + dependencyDashboardHeader?: string; + prBlockedBy?: PrBlockedBy; + repoProblems?: Set; + result?: string; } export interface RepoCacheData { diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index e80979449435d9..192f66544eb6ba 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -1,7 +1,8 @@ /* istanbul ignore file */ +import { nameFromLevel } from 'bunyan'; import { REPOSITORY_CHANGED } from '../../constants/error-messages'; -import { logger } from '../../logger'; +import { getProblems, logger } from '../../logger'; import { platform } from '../../modules/platform'; import { scm } from '../../modules/platform/scm'; import { getCache } from '../../util/cache/repository'; @@ -14,6 +15,7 @@ import { getCachedConflictResult } from '../../util/git/conflicts-cache'; import { getCachedModifiedResult } from '../../util/git/modified-cache'; import { getCachedPristineResult } from '../../util/git/pristine'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; +import { PackageFiles } from './package-files'; import { getPrCache } from './update/pr/pr-cache'; function generateBranchUpgradeCache( @@ -22,23 +24,39 @@ function generateBranchUpgradeCache( const { datasource, depName, + depNameLinked, + depType, + displayPending, packageName, fixedVersion, currentVersion, newVersion, + currentValue, + newValue, currentDigest, newDigest, + packageFile, sourceUrl, + remediationNotPossible, + updateType, } = upgrade; const result: BranchUpgradeCache = { datasource, depName, + depNameLinked, + depType, + displayPending, fixedVersion, currentVersion, + currentValue, + newValue, newVersion, currentDigest, newDigest, + packageFile, sourceUrl, + remediationNotPossible, + updateType, }; if (packageName) { result.packageName = packageName; @@ -49,7 +67,20 @@ function generateBranchUpgradeCache( async function generateBranchCache( branch: BranchConfig ): Promise { - const { baseBranch, branchName } = branch; + const { + baseBranch, + branchName, + dependencyDashboard, + dependencyDashboardApproval, + dependencyDashboardFooter, + dependencyDashboardHeader, + dependencyDashboardPrApproval, + dependencyDashboardTitle, + packageFiles, + prBlockedBy, + repository, + result, + } = branch; try { const branchSha = await scm.getBranchCommit(branchName); const baseBranchSha = await scm.getBranchCommit(baseBranch); @@ -79,24 +110,57 @@ 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); + + // we minimize to packageFile+warnings because that's what getDepWarningsDashboard needs. + const packageFilesMinimized: Partial = {}; + for (const [fileType, files] of Object.entries(packageFiles)) { + packageFilesMinimized[fileType] = files.map((file) => ({ + deps: file.deps.map(({ warnings }) => ({ warnings })), + packageFile: file.packageFile, + })); + } + + //get repo problems to log into branch summary + const repoProblems = new Set( + getProblems() + .filter( + (problem) => + problem.repository === repository && !problem.artifactErrors + ) + .map( + (problem) => + `${nameFromLevel[problem.level].toUpperCase()}: ${problem.msg}` + ) + ); + return { automerge, baseBranchSha, baseBranch, branchFingerprint, branchName, + dependencyDashboard, + dependencyDashboardApproval, + dependencyDashboardFooter, + dependencyDashboardHeader, + dependencyDashboardPrApproval, + dependencyDashboardTitle, isBehindBase, isConflicted, isModified, + prBlockedBy, pristine, prCache, prNo, + repoProblems, + result, sha: branchSha, upgrades, }; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 6054f0e58e9573..4c82dfb1637fe3 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -8,7 +8,12 @@ import { platform } from '../../modules/platform'; import { GitHubMaxPrBodyLen } from '../../modules/platform/github'; import { regEx } from '../../util/regex'; import * as template from '../../util/template'; -import type { BranchConfig, SelectAllConfig } from '../types'; +import type { + BranchConfig, + Dashboard, + DashboardBody, + SelectAllConfig, +} from '../types'; import { getDepWarningsDashboard } from './errors-warnings'; import { PackageFiles } from './package-files'; @@ -133,9 +138,9 @@ export async function readDashboardBody( } } -function getListItem(branch: BranchConfig, type: string): string { +function getListItem(branch: Partial, type: string): string { let item = ' - [ ] '; - item += ``; + item += ``; if (branch.prNo) { // TODO: types (#7154) item += `[${branch.prTitle!}](../pull/${branch.prNo})`; @@ -152,9 +157,8 @@ function getListItem(branch: BranchConfig, type: string): string { return item + ' (' + uniquePackages.join(', ') + ')\n'; } -function appendRepoProblems(config: RenovateConfig, issueBody: string): string { - let newIssueBody = issueBody; - const repoProblems = new Set( +function extractRepoProblems(config: RenovateConfig): Set { + return new Set( getProblems() .filter( (problem) => @@ -165,88 +169,57 @@ function appendRepoProblems(config: RenovateConfig, issueBody: string): string { `${nameFromLevel[problem.level].toUpperCase()}: ${problem.msg}` ) ); - if (repoProblems.size) { - newIssueBody += '## Repository problems\n\n'; - newIssueBody += - 'These problems occurred while renovating this repository.\n\n'; - for (const repoProblem of repoProblems) { - newIssueBody += ` - ${repoProblem}\n`; - } - newIssueBody += '\n'; - } - return newIssueBody; } -export async function ensureDependencyDashboard( - config: SelectAllConfig, - allBranches: BranchConfig[], - packageFiles: Record = {} -): Promise { - // legacy/migrated issue - const reuseTitle = 'Update Dependencies (Renovate Bot)'; - const branches = allBranches.filter( - (branch) => - branch.result !== 'automerged' && - !branch.upgrades?.every((upgrade) => upgrade.remediationNotPossible) - ); - if ( - !( - config.dependencyDashboard || - config.dependencyDashboardApproval || - config.packageRules?.some((rule) => rule.dependencyDashboardApproval) || - branches.some( - (branch) => - !!branch.dependencyDashboardApproval || - !!branch.dependencyDashboardPrApproval - ) - ) - ) { - if (GlobalConfig.get('dryRun')) { - logger.info( - { title: config.dependencyDashboardTitle }, - 'DRY-RUN: Would close Dependency Dashboard' - ); - } else { - logger.debug('Closing Dependency Dashboard'); - await platform.ensureIssueClosing(config.dependencyDashboardTitle!); - } - return; - } - // istanbul ignore if - if (config.repoIsOnboarded === false) { - logger.debug('Repo is onboarding - skipping dependency dashboard'); - return; - } - logger.debug('Ensuring Dependency Dashboard'); - const hasBranches = is.nonEmptyArray(branches); - if (config.dependencyDashboardAutoclose && !hasBranches) { - if (GlobalConfig.get('dryRun')) { - logger.info( - { title: config.dependencyDashboardTitle }, - 'DRY-RUN: Would close Dependency Dashboard' - ); - } else { - logger.debug('Closing Dependency Dashboard'); - await platform.ensureIssueClosing(config.dependencyDashboardTitle!); - } - return; - } +export function createDashboardBody( + header: string, + repoProblems: Set, + branches: Partial[], + packageFiles: Record[]> +): DashboardBody { let issueBody = ''; - if (config.dependencyDashboardHeader?.length) { - issueBody += - template.compile(config.dependencyDashboardHeader, config) + '\n\n'; + + const dashboard: Dashboard = { + awaitingSchedule: [], + prCreationApprovalRequired: [], + editedOrBlocked: [], + errored: [], + ignoredOrBlocked: [], + open: [], + otherBranches: [], + pendingApprovals: [], + pendingAutomerge: [], + pendingStatusChecks: [], + rateLimited: [], + repositoryProblems: new Set(), + header: '', + }; + + if (header) { + issueBody += header + '\n\n'; } - issueBody = appendRepoProblems(config, issueBody); + if (repoProblems.size) { + issueBody += '## Repository problems\n\n'; + issueBody += + 'These problems occurred while renovating this repository.\n\n'; + for (const repoProblem of repoProblems) { + issueBody += ` - ${repoProblem}\n`; + } + issueBody += '\n'; + dashboard.repositoryProblems = repoProblems; + } const pendingApprovals = branches.filter( (branch) => branch.result === 'needs-approval' ); + if (pendingApprovals.length) { issueBody += '## Pending Approval\n\n'; issueBody += `These branches will be created by Renovate only once you click their checkbox below.\n\n`; for (const branch of pendingApprovals) { issueBody += getListItem(branch, 'approve'); + dashboard.pendingApprovals.push(branch); } if (pendingApprovals.length > 1) { issueBody += ' - [ ] '; @@ -255,6 +228,7 @@ export async function ensureDependencyDashboard( } issueBody += '\n'; } + const awaitingSchedule = branches.filter( (branch) => branch.result === 'not-scheduled' ); @@ -264,9 +238,11 @@ export async function ensureDependencyDashboard( 'These updates are awaiting their schedule. Click on a checkbox to get an update now.\n\n'; for (const branch of awaitingSchedule) { issueBody += getListItem(branch, 'unschedule'); + dashboard.awaitingSchedule.push(branch); } issueBody += '\n'; } + const rateLimited = branches.filter( (branch) => branch.result === 'branch-limit-reached' || @@ -279,6 +255,7 @@ export async function ensureDependencyDashboard( 'These updates are currently rate-limited. Click on a checkbox below to force their creation now.\n\n'; for (const branch of rateLimited) { issueBody += getListItem(branch, 'unlimit'); + dashboard.rateLimited.push(branch); } if (rateLimited.length > 1) { issueBody += ' - [ ] '; @@ -287,6 +264,7 @@ export async function ensureDependencyDashboard( } issueBody += '\n'; } + const errorList = branches.filter((branch) => branch.result === 'error'); if (errorList.length) { issueBody += '## Errored\n\n'; @@ -294,9 +272,11 @@ export async function ensureDependencyDashboard( 'These updates encountered an error and will be retried. Click on a checkbox below to force a retry now.\n\n'; for (const branch of errorList) { issueBody += getListItem(branch, 'retry'); + dashboard.errored.push(branch); } issueBody += '\n'; } + const awaitingPr = branches.filter( (branch) => branch.result === 'needs-pr-approval' ); @@ -306,15 +286,18 @@ export async function ensureDependencyDashboard( "These branches exist but PRs won't be created until you approve them by clicking on a checkbox.\n\n"; for (const branch of awaitingPr) { issueBody += getListItem(branch, 'approvePr'); + dashboard.prCreationApprovalRequired.push(branch); } issueBody += '\n'; } + const prEdited = branches.filter((branch) => branch.result === 'pr-edited'); if (prEdited.length) { issueBody += '## Edited/Blocked\n\n'; issueBody += `These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.\n\n`; for (const branch of prEdited) { issueBody += getListItem(branch, 'rebase'); + dashboard.editedOrBlocked.push(branch); } issueBody += '\n'; } @@ -324,6 +307,7 @@ export async function ensureDependencyDashboard( issueBody += `These updates await pending status checks. To force their creation now, click the checkbox below.\n\n`; for (const branch of prPending) { issueBody += getListItem(branch, 'approvePr'); + dashboard.pendingStatusChecks.push(branch); } issueBody += '\n'; } @@ -335,12 +319,14 @@ export async function ensureDependencyDashboard( issueBody += `These updates await pending status checks before automerging. Click on a checkbox to abort the branch automerge, and create a PR instead.\n\n`; for (const branch of prPendingBranchAutomerge) { issueBody += getListItem(branch, 'approvePr'); + dashboard.pendingAutomerge.push(branch); } issueBody += '\n'; } const warn = getDepWarningsDashboard(packageFiles); if (warn) { + dashboard.warn = warn; issueBody += warn; issueBody += '\n'; } @@ -372,6 +358,7 @@ export async function ensureDependencyDashboard( issueBody += `These updates are pending. To force PRs open, click the checkbox below.\n\n`; for (const branch of otherBranches) { issueBody += getListItem(branch, 'other'); + dashboard.otherBranches.push(branch); } issueBody += '\n'; } @@ -384,6 +371,7 @@ export async function ensureDependencyDashboard( 'These updates have all been created already. Click a checkbox below to force a retry/rebase of any.\n\n'; for (const branch of inProgress) { issueBody += getListItem(branch, 'rebase'); + dashboard.open.push(branch); } if (inProgress.length > 2) { issueBody += ' - [ ] '; @@ -402,9 +390,80 @@ export async function ensureDependencyDashboard( 'These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.\n\n'; for (const branch of alreadyExisted) { issueBody += getListItem(branch, 'recreate'); + dashboard.ignoredOrBlocked.push(branch); } issueBody += '\n'; } + return { issueBody, dashboard }; +} + +export async function ensureDependencyDashboard( + config: SelectAllConfig, + allBranches: BranchConfig[], + packageFiles: Record = {} +): Promise { + // legacy/migrated issue + const reuseTitle = 'Update Dependencies (Renovate Bot)'; + const branches = allBranches.filter( + (branch) => + branch.result !== 'automerged' && + !branch.upgrades?.every((upgrade) => upgrade.remediationNotPossible) + ); + if ( + !( + config.dependencyDashboard || + config.dependencyDashboardApproval || + config.packageRules?.some((rule) => rule.dependencyDashboardApproval) || + branches.some( + (branch) => + !!branch.dependencyDashboardApproval || + !!branch.dependencyDashboardPrApproval + ) + ) + ) { + if (GlobalConfig.get('dryRun')) { + logger.info( + { title: config.dependencyDashboardTitle }, + 'DRY-RUN: Would close Dependency Dashboard' + ); + } else { + logger.debug('Closing Dependency Dashboard'); + await platform.ensureIssueClosing(config.dependencyDashboardTitle!); + } + return; + } + // istanbul ignore if + if (config.repoIsOnboarded === false) { + logger.debug('Repo is onboarding - skipping dependency dashboard'); + return; + } + logger.debug('Ensuring Dependency Dashboard'); + const hasBranches = is.nonEmptyArray(branches); + if (config.dependencyDashboardAutoclose && !hasBranches) { + if (GlobalConfig.get('dryRun')) { + logger.info( + { title: config.dependencyDashboardTitle }, + 'DRY-RUN: Would close Dependency Dashboard' + ); + } else { + logger.debug('Closing Dependency Dashboard'); + await platform.ensureIssueClosing(config.dependencyDashboardTitle!); + } + return; + } + + let header; + if (config.dependencyDashboardHeader?.length) { + header = template.compile(config.dependencyDashboardHeader, config); + } + const repoProblems = extractRepoProblems(config); + + let { issueBody } = createDashboardBody( + header, + repoProblems, + branches, + packageFiles + ); if (!hasBranches) { issueBody += diff --git a/lib/workers/repository/errors-warnings.ts b/lib/workers/repository/errors-warnings.ts index 306cf9a939e667..e7935c6b68079e 100644 --- a/lib/workers/repository/errors-warnings.ts +++ b/lib/workers/repository/errors-warnings.ts @@ -33,7 +33,7 @@ export function getErrors(config: RenovateConfig): string { } function getDepWarnings( - packageFiles: Record + packageFiles: Record[]> ): DepWarnings { const warnings: string[] = []; const warningFiles: string[] = []; @@ -104,7 +104,7 @@ export function getDepWarningsPR( } export function getDepWarningsDashboard( - packageFiles: Record + packageFiles: Record[]> ): string { const { warnings, warningFiles } = getDepWarnings(packageFiles); if (!warnings.length) { diff --git a/lib/workers/repository/finalize/repository-statistics.spec.ts b/lib/workers/repository/finalize/repository-statistics.spec.ts index 3f2c323550e1be..7506a6ea584f0f 100644 --- a/lib/workers/repository/finalize/repository-statistics.spec.ts +++ b/lib/workers/repository/finalize/repository-statistics.spec.ts @@ -152,5 +152,28 @@ 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({ + dependencyDashboard: true, + result: 'done', + }); + 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..db19e30e5e33c7 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -60,7 +60,8 @@ function branchCacheToMetadata({ }; } -export function runBranchSummary({ defaultBranch }: RenovateConfig): void { +export function runBranchSummary(config: RenovateConfig): void { + const defaultBranch = config.defaultBranch; const { scan, branches } = getCache(); const baseMetadata: BaseBranchMetadata[] = []; @@ -88,4 +89,7 @@ export function runBranchSummary({ defaultBranch }: RenovateConfig): void { }; logger.debug(res, 'Branch summary'); + if (config.branchSummaryExtended) { + logger.debug({ branches }, 'Branches info extended'); + } } diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 3a14f60295b1ae..e5766ac527a63f 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -194,3 +194,25 @@ export interface ExtractResult { extractionFingerprints: Record; packageFiles: Record; } + +export interface Dashboard { + awaitingSchedule: Partial[]; + prCreationApprovalRequired: Partial[]; + editedOrBlocked: Partial[]; + errored: Partial[]; + ignoredOrBlocked: Partial[]; + open: Partial[]; + otherBranches: Partial[]; + pendingApprovals: Partial[]; + pendingAutomerge: Partial[]; + pendingStatusChecks: Partial[]; + rateLimited: Partial[]; + repositoryProblems?: Set; + header: string; + warn?: string; +} + +export interface DashboardBody { + issueBody: string; + dashboarrd: Dashboard; +} From e71c0d35fde7cd5f232d92c264a3ce0c36bc7f1d Mon Sep 17 00:00:00 2001 From: philipabed Date: Tue, 9 May 2023 14:50:04 +0300 Subject: [PATCH 02/14] extended branch summary and dashboard info --- lib/util/cache/repository/types.ts | 17 +++++++++-------- lib/workers/repository/cache.ts | 18 +++++++++++------- lib/workers/repository/dependency-dashboard.ts | 4 ++-- lib/workers/types.ts | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index 978186f043e3f8..cc829eb15da338 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -1,11 +1,11 @@ import type { RepositoryCacheConfig, RepositoryCacheType, + UpdateType, } from '../../../config/types'; -import { UpdateType } from '../../../config/types'; import type { PackageFile } from '../../../modules/manager/types'; import type { RepoInitConfig } from '../../../workers/repository/init/types'; -import { PrBlockedBy } from '../../../workers/types'; +import type { PrBlockedBy } from '../../../workers/types'; export interface BaseBranchCache { sha: string; // branch commit sha @@ -19,9 +19,9 @@ export interface BranchUpgradeCache { currentValue?: string; datasource?: string; depName?: string; - depNameLinked?: string; + depNameLinked?: unknown; depType?: string; - displayPending?: string; + displayPending?: unknown; fixedVersion?: string; currentVersion?: string; packageName?: string; @@ -30,7 +30,7 @@ export interface BranchUpgradeCache { newVersion?: string; sourceUrl?: string; packageFile?: string; - remediationNotPossible?: boolean; + remediationNotPossible?: unknown; updateType?: UpdateType; } @@ -107,13 +107,14 @@ export interface BranchCache { */ dependencyDashboard?: boolean; dependencyDashboardApproval?: boolean; - dependencyDashboardPrApproval?: boolean; + dependencyDashboardPrApproval?: unknown; dependencyDashboardTitle?: string; - dependencyDashboardFooter?: string; - dependencyDashboardHeader?: string; + dependencyDashboardFooter?: unknown; + dependencyDashboardHeader?: unknown; prBlockedBy?: PrBlockedBy; repoProblems?: Set; result?: string; + packageFiles?: Record[]>; } export interface RepoCacheData { diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 192f66544eb6ba..6d3ed7ec6ecd5a 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -3,6 +3,7 @@ import { nameFromLevel } from 'bunyan'; import { REPOSITORY_CHANGED } from '../../constants/error-messages'; import { getProblems, logger } from '../../logger'; +import type { PackageFile } from '../../modules/manager/types'; import { platform } from '../../modules/platform'; import { scm } from '../../modules/platform/scm'; import { getCache } from '../../util/cache/repository'; @@ -15,7 +16,6 @@ import { getCachedConflictResult } from '../../util/git/conflicts-cache'; import { getCachedModifiedResult } from '../../util/git/modified-cache'; import { getCachedPristineResult } from '../../util/git/pristine'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; -import { PackageFiles } from './package-files'; import { getPrCache } from './update/pr/pr-cache'; function generateBranchUpgradeCache( @@ -119,12 +119,15 @@ async function generateBranchCache( const prCache = getPrCache(branchName); // we minimize to packageFile+warnings because that's what getDepWarningsDashboard needs. - const packageFilesMinimized: Partial = {}; - for (const [fileType, files] of Object.entries(packageFiles)) { - packageFilesMinimized[fileType] = files.map((file) => ({ - deps: file.deps.map(({ warnings }) => ({ warnings })), - packageFile: file.packageFile, - })); + const packageFilesMinimized: Record[]> = {}; + if (packageFiles) { + for (const key in packageFiles) { + const packageFile = packageFiles[key]; + packageFilesMinimized[key] = packageFile.map((file) => ({ + deps: file.deps.map(({ warnings }) => ({ warnings })), + packageFile: file.packageFile, + })); + } } //get repo problems to log into branch summary @@ -163,6 +166,7 @@ async function generateBranchCache( result, sha: branchSha, upgrades, + packageFiles: packageFilesMinimized, }; } catch (error) { const err = error.err || error; // external host error nests err diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 4c82dfb1637fe3..843ebe4f92c368 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -149,7 +149,7 @@ function getListItem(branch: Partial, type: string): string { } const uniquePackages = [ // TODO: types (#7154) - ...new Set(branch.upgrades.map((upgrade) => `\`${upgrade.depName!}\``)), + ...new Set(branch.upgrades!.map((upgrade) => `\`${upgrade.depName!}\``)), ]; if (uniquePackages.length < 2) { return item + '\n'; @@ -172,7 +172,7 @@ function extractRepoProblems(config: RenovateConfig): Set { } export function createDashboardBody( - header: string, + header: string | undefined, repoProblems: Set, branches: Partial[], packageFiles: Record[]> diff --git a/lib/workers/types.ts b/lib/workers/types.ts index e5766ac527a63f..d9a731bae44188 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -214,5 +214,5 @@ export interface Dashboard { export interface DashboardBody { issueBody: string; - dashboarrd: Dashboard; + dashboard: Dashboard; } From 2fdda8a0dc8a348655d4f7f3c66d6c27e7f0c329 Mon Sep 17 00:00:00 2001 From: philipabed Date: Tue, 9 May 2023 14:54:26 +0300 Subject: [PATCH 03/14] a new commit --- lib/util/cache/repository/types.ts | 17 +++++++++-------- lib/workers/repository/cache.ts | 18 +++++++++++------- lib/workers/repository/dependency-dashboard.ts | 4 ++-- lib/workers/types.ts | 2 +- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index 978186f043e3f8..cc829eb15da338 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -1,11 +1,11 @@ import type { RepositoryCacheConfig, RepositoryCacheType, + UpdateType, } from '../../../config/types'; -import { UpdateType } from '../../../config/types'; import type { PackageFile } from '../../../modules/manager/types'; import type { RepoInitConfig } from '../../../workers/repository/init/types'; -import { PrBlockedBy } from '../../../workers/types'; +import type { PrBlockedBy } from '../../../workers/types'; export interface BaseBranchCache { sha: string; // branch commit sha @@ -19,9 +19,9 @@ export interface BranchUpgradeCache { currentValue?: string; datasource?: string; depName?: string; - depNameLinked?: string; + depNameLinked?: unknown; depType?: string; - displayPending?: string; + displayPending?: unknown; fixedVersion?: string; currentVersion?: string; packageName?: string; @@ -30,7 +30,7 @@ export interface BranchUpgradeCache { newVersion?: string; sourceUrl?: string; packageFile?: string; - remediationNotPossible?: boolean; + remediationNotPossible?: unknown; updateType?: UpdateType; } @@ -107,13 +107,14 @@ export interface BranchCache { */ dependencyDashboard?: boolean; dependencyDashboardApproval?: boolean; - dependencyDashboardPrApproval?: boolean; + dependencyDashboardPrApproval?: unknown; dependencyDashboardTitle?: string; - dependencyDashboardFooter?: string; - dependencyDashboardHeader?: string; + dependencyDashboardFooter?: unknown; + dependencyDashboardHeader?: unknown; prBlockedBy?: PrBlockedBy; repoProblems?: Set; result?: string; + packageFiles?: Record[]>; } export interface RepoCacheData { diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 192f66544eb6ba..6d3ed7ec6ecd5a 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -3,6 +3,7 @@ import { nameFromLevel } from 'bunyan'; import { REPOSITORY_CHANGED } from '../../constants/error-messages'; import { getProblems, logger } from '../../logger'; +import type { PackageFile } from '../../modules/manager/types'; import { platform } from '../../modules/platform'; import { scm } from '../../modules/platform/scm'; import { getCache } from '../../util/cache/repository'; @@ -15,7 +16,6 @@ import { getCachedConflictResult } from '../../util/git/conflicts-cache'; import { getCachedModifiedResult } from '../../util/git/modified-cache'; import { getCachedPristineResult } from '../../util/git/pristine'; import type { BranchConfig, BranchUpgradeConfig } from '../types'; -import { PackageFiles } from './package-files'; import { getPrCache } from './update/pr/pr-cache'; function generateBranchUpgradeCache( @@ -119,12 +119,15 @@ async function generateBranchCache( const prCache = getPrCache(branchName); // we minimize to packageFile+warnings because that's what getDepWarningsDashboard needs. - const packageFilesMinimized: Partial = {}; - for (const [fileType, files] of Object.entries(packageFiles)) { - packageFilesMinimized[fileType] = files.map((file) => ({ - deps: file.deps.map(({ warnings }) => ({ warnings })), - packageFile: file.packageFile, - })); + const packageFilesMinimized: Record[]> = {}; + if (packageFiles) { + for (const key in packageFiles) { + const packageFile = packageFiles[key]; + packageFilesMinimized[key] = packageFile.map((file) => ({ + deps: file.deps.map(({ warnings }) => ({ warnings })), + packageFile: file.packageFile, + })); + } } //get repo problems to log into branch summary @@ -163,6 +166,7 @@ async function generateBranchCache( result, sha: branchSha, upgrades, + packageFiles: packageFilesMinimized, }; } catch (error) { const err = error.err || error; // external host error nests err diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 4c82dfb1637fe3..843ebe4f92c368 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -149,7 +149,7 @@ function getListItem(branch: Partial, type: string): string { } const uniquePackages = [ // TODO: types (#7154) - ...new Set(branch.upgrades.map((upgrade) => `\`${upgrade.depName!}\``)), + ...new Set(branch.upgrades!.map((upgrade) => `\`${upgrade.depName!}\``)), ]; if (uniquePackages.length < 2) { return item + '\n'; @@ -172,7 +172,7 @@ function extractRepoProblems(config: RenovateConfig): Set { } export function createDashboardBody( - header: string, + header: string | undefined, repoProblems: Set, branches: Partial[], packageFiles: Record[]> diff --git a/lib/workers/types.ts b/lib/workers/types.ts index e5766ac527a63f..d9a731bae44188 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -214,5 +214,5 @@ export interface Dashboard { export interface DashboardBody { issueBody: string; - dashboarrd: Dashboard; + dashboard: Dashboard; } From 36d957c7d5c71e0069c8e3c8ba1a0cbd8d8eb94a Mon Sep 17 00:00:00 2001 From: philipabed Date: Tue, 9 May 2023 17:27:31 +0300 Subject: [PATCH 04/14] a new second commit --- lib/util/cache/repository/types.ts | 1 + lib/workers/repository/cache.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index cc829eb15da338..39053c9bc1405a 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -112,6 +112,7 @@ export interface BranchCache { dependencyDashboardFooter?: unknown; dependencyDashboardHeader?: unknown; prBlockedBy?: PrBlockedBy; + prTitle?: string; repoProblems?: Set; result?: string; packageFiles?: Record[]>; diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 6d3ed7ec6ecd5a..7ec3fdc5adc6e9 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -78,6 +78,7 @@ async function generateBranchCache( dependencyDashboardTitle, packageFiles, prBlockedBy, + prTitle, repository, result, } = branch; @@ -121,9 +122,9 @@ async function generateBranchCache( // we minimize to packageFile+warnings because that's what getDepWarningsDashboard needs. const packageFilesMinimized: Record[]> = {}; if (packageFiles) { - for (const key in packageFiles) { - const packageFile = packageFiles[key]; - packageFilesMinimized[key] = packageFile.map((file) => ({ + for (const manager in packageFiles) { + const packageFile = packageFiles[manager]; + packageFilesMinimized[manager] = packageFile.map((file) => ({ deps: file.deps.map(({ warnings }) => ({ warnings })), packageFile: file.packageFile, })); @@ -162,6 +163,7 @@ async function generateBranchCache( pristine, prCache, prNo, + prTitle, repoProblems, result, sha: branchSha, From 3d9d06e1efc489cd6b1484a472e231d8a94d6731 Mon Sep 17 00:00:00 2001 From: philipabed Date: Wed, 10 May 2023 18:00:39 +0300 Subject: [PATCH 05/14] minimize --- lib/util/cache/repository/types.ts | 5 ++- lib/workers/repository/cache.ts | 2 -- .../finalize/repository-statistics.ts | 33 +++++++++++++++++-- lib/workers/types.ts | 6 ++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index 39053c9bc1405a..beb9f37a844c19 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -19,7 +19,6 @@ export interface BranchUpgradeCache { currentValue?: string; datasource?: string; depName?: string; - depNameLinked?: unknown; depType?: string; displayPending?: unknown; fixedVersion?: string; @@ -52,7 +51,7 @@ export interface BranchCache { /** * Whether this branch has automerge enabled */ - automerge: boolean; + automerge?: boolean; /** * Name of base branch */ @@ -92,7 +91,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 */ diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 7ec3fdc5adc6e9..8cbe62ebc0b670 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -24,7 +24,6 @@ function generateBranchUpgradeCache( const { datasource, depName, - depNameLinked, depType, displayPending, packageName, @@ -43,7 +42,6 @@ function generateBranchUpgradeCache( const result: BranchUpgradeCache = { datasource, depName, - depNameLinked, depType, displayPending, fixedVersion, diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index db19e30e5e33c7..dfd17aa0865bcb 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -60,6 +60,32 @@ function branchCacheToMetadata({ }; } +function extractDependencyDashboardData( + branches: BranchCache[] +): Partial[] { + let dependencyDashboardData = [...branches]; + dependencyDashboardData = dependencyDashboardData.map((branch) => { + const b = { ...branch }; + delete b.isModified; + delete b.automerge; + delete b.isModified; + delete b.isBehindBase; + delete b.isModified; + delete b.branchFingerprint; + delete b.pristine; + delete b.prCache; + delete b.sha; + b.upgrades.map((upgrade) => { + const u = { ...upgrade }; + delete u.sourceUrl; + delete u.depType; + delete u.sourceUrl; + }); + return b; + }); + return dependencyDashboardData; +} + export function runBranchSummary(config: RenovateConfig): void { const defaultBranch = config.defaultBranch; const { scan, branches } = getCache(); @@ -89,7 +115,10 @@ export function runBranchSummary(config: RenovateConfig): void { }; logger.debug(res, 'Branch summary'); - if (config.branchSummaryExtended) { - logger.debug({ branches }, 'Branches info extended'); + if (branches) { + const branchesInformation = extractDependencyDashboardData(branches); + if (config.branchSummaryExtended) { + logger.debug({ branchesInformation }, 'Branches info extended'); + } } } diff --git a/lib/workers/types.ts b/lib/workers/types.ts index d9a731bae44188..28c3649fec9148 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -131,17 +131,17 @@ export interface BranchConfig export interface BranchMetadata { branchName: string; - branchSha: string | null; + branchSha: string | null | undefined; baseBranch?: string; baseBranchSha?: string | null; - automerge: boolean; + automerge: boolean | undefined; isModified?: boolean; isPristine?: boolean; } export interface BaseBranchMetadata { branchName: string; - sha: string; + sha: string | undefined; } export interface BranchSummary { From 189dfbcd657e06e584dc43dae16dd8a0cbc79aa4 Mon Sep 17 00:00:00 2001 From: philipabed Date: Wed, 10 May 2023 18:08:16 +0300 Subject: [PATCH 06/14] minimize --- lib/util/cache/repository/types.ts | 4 ++-- lib/workers/repository/finalize/repository-statistics.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index beb9f37a844c19..f133f68a62c33d 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -55,11 +55,11 @@ export interface BranchCache { /** * 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 */ diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index dfd17aa0865bcb..1b30b02e5039be 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -68,9 +68,10 @@ function extractDependencyDashboardData( const b = { ...branch }; delete b.isModified; delete b.automerge; - delete b.isModified; delete b.isBehindBase; - delete b.isModified; + delete b.isConflicted; + delete b.baseBranch; + delete b.baseBranchSha; delete b.branchFingerprint; delete b.pristine; delete b.prCache; @@ -79,7 +80,6 @@ function extractDependencyDashboardData( const u = { ...upgrade }; delete u.sourceUrl; delete u.depType; - delete u.sourceUrl; }); return b; }); From f79f19bed054fe8e2b9e3fc44003d39bd6deab42 Mon Sep 17 00:00:00 2001 From: philipabed Date: Sun, 14 May 2023 14:31:41 +0300 Subject: [PATCH 07/14] fix --- .../finalize/repository-statistics.spec.ts | 12 ++++++++++++ .../repository/finalize/repository-statistics.ts | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/workers/repository/finalize/repository-statistics.spec.ts b/lib/workers/repository/finalize/repository-statistics.spec.ts index 7506a6ea584f0f..84c04a2542ef8e 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, @@ -162,7 +164,17 @@ describe('workers/repository/finalize/repository-statistics', () => { const branchCache = partial({ dependencyDashboard: true, 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: {}, diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index 1b30b02e5039be..044c6e68f5b2aa 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -60,7 +60,7 @@ function branchCacheToMetadata({ }; } -function extractDependencyDashboardData( +function filterDependencyDashboardData( branches: BranchCache[] ): Partial[] { let dependencyDashboardData = [...branches]; @@ -76,10 +76,11 @@ function extractDependencyDashboardData( delete b.pristine; delete b.prCache; delete b.sha; - b.upgrades.map((upgrade) => { + b.upgrades = b.upgrades?.map((upgrade) => { const u = { ...upgrade }; delete u.sourceUrl; delete u.depType; + return u; }); return b; }); @@ -116,7 +117,7 @@ export function runBranchSummary(config: RenovateConfig): void { logger.debug(res, 'Branch summary'); if (branches) { - const branchesInformation = extractDependencyDashboardData(branches); + const branchesInformation = filterDependencyDashboardData(branches); if (config.branchSummaryExtended) { logger.debug({ branchesInformation }, 'Branches info extended'); } From c5b6a37bdfb2a153b41a930506e9a011419e115d Mon Sep 17 00:00:00 2001 From: philipabed Date: Sun, 14 May 2023 17:24:43 +0300 Subject: [PATCH 08/14] fix --- lib/config/options/index.ts | 5 +- lib/config/types.ts | 2 +- lib/workers/repository/cache.ts | 53 +---------------- .../repository/dependency-dashboard.ts | 2 +- lib/workers/repository/finalize/index.ts | 6 +- .../finalize/repository-statistics.spec.ts | 14 +++-- .../finalize/repository-statistics.ts | 58 +++++++++++++++---- lib/workers/repository/index.ts | 2 +- lib/workers/types.ts | 4 +- 9 files changed, 70 insertions(+), 76 deletions(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 48a95f6450a42e..36350d7ebf3da6 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2635,8 +2635,9 @@ const options: RenovateOptions[] = [ default: [], }, { - name: 'branchSummaryExtended', - description: 'Extends the branch summary by printing all', + name: 'logDependencyDashboardInfo', + description: + 'logs dependency dashboard information before transforming into dependency dashboard issue', type: 'boolean', experimental: true, globalOnly: true, diff --git a/lib/config/types.ts b/lib/config/types.ts index 54d18840999e73..dc83cc4167939f 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -263,7 +263,7 @@ export interface RenovateConfig constraintsFiltering?: ConstraintsFilter; checkedBranches?: string[]; - branchSummaryExtended?: boolean; + logDependencyDashboardInfo?: boolean; } export interface AllConfig diff --git a/lib/workers/repository/cache.ts b/lib/workers/repository/cache.ts index 8cbe62ebc0b670..684c6220524297 100644 --- a/lib/workers/repository/cache.ts +++ b/lib/workers/repository/cache.ts @@ -1,9 +1,7 @@ /* istanbul ignore file */ -import { nameFromLevel } from 'bunyan'; import { REPOSITORY_CHANGED } from '../../constants/error-messages'; -import { getProblems, logger } from '../../logger'; -import type { PackageFile } from '../../modules/manager/types'; +import { logger } from '../../logger'; import { platform } from '../../modules/platform'; import { scm } from '../../modules/platform/scm'; import { getCache } from '../../util/cache/repository'; @@ -65,21 +63,7 @@ function generateBranchUpgradeCache( async function generateBranchCache( branch: BranchConfig ): Promise { - const { - baseBranch, - branchName, - dependencyDashboard, - dependencyDashboardApproval, - dependencyDashboardFooter, - dependencyDashboardHeader, - dependencyDashboardPrApproval, - dependencyDashboardTitle, - packageFiles, - prBlockedBy, - prTitle, - repository, - result, - } = branch; + const { baseBranch, branchName, prBlockedBy, prTitle, result } = branch; try { const branchSha = await scm.getBranchCommit(branchName); const baseBranchSha = await scm.getBranchCommit(baseBranch); @@ -117,43 +101,12 @@ async function generateBranchCache( const branchFingerprint = branch.branchFingerprint; const prCache = getPrCache(branchName); - // we minimize to packageFile+warnings because that's what getDepWarningsDashboard needs. - const packageFilesMinimized: Record[]> = {}; - if (packageFiles) { - for (const manager in packageFiles) { - const packageFile = packageFiles[manager]; - packageFilesMinimized[manager] = packageFile.map((file) => ({ - deps: file.deps.map(({ warnings }) => ({ warnings })), - packageFile: file.packageFile, - })); - } - } - - //get repo problems to log into branch summary - const repoProblems = new Set( - getProblems() - .filter( - (problem) => - problem.repository === repository && !problem.artifactErrors - ) - .map( - (problem) => - `${nameFromLevel[problem.level].toUpperCase()}: ${problem.msg}` - ) - ); - return { automerge, baseBranchSha, baseBranch, branchFingerprint, branchName, - dependencyDashboard, - dependencyDashboardApproval, - dependencyDashboardFooter, - dependencyDashboardHeader, - dependencyDashboardPrApproval, - dependencyDashboardTitle, isBehindBase, isConflicted, isModified, @@ -162,11 +115,9 @@ async function generateBranchCache( prCache, prNo, prTitle, - repoProblems, result, sha: branchSha, upgrades, - packageFiles: packageFilesMinimized, }; } catch (error) { const err = error.err || error; // external host error nests err diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 843ebe4f92c368..5324bad1416fe7 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -157,7 +157,7 @@ function getListItem(branch: Partial, type: string): string { return item + ' (' + uniquePackages.join(', ') + ')\n'; } -function extractRepoProblems(config: RenovateConfig): Set { +export function extractRepoProblems(config: RenovateConfig): Set { return new Set( getProblems() .filter( diff --git a/lib/workers/repository/finalize/index.ts b/lib/workers/repository/finalize/index.ts index 0a5064e4458399..edb2c3858064fa 100644 --- a/lib/workers/repository/finalize/index.ts +++ b/lib/workers/repository/finalize/index.ts @@ -1,5 +1,6 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; +import type { PackageFile } from '../../../modules/manager/types'; import { platform } from '../../../modules/platform'; import * as repositoryCache from '../../../util/cache/repository'; import { clearRenovateRefs } from '../../../util/git'; @@ -14,7 +15,8 @@ import { // istanbul ignore next export async function finalizeRepo( config: RenovateConfig, - branchList: string[] + branchList: string[], + packageFiles: Record ): Promise { await configMigration(config, branchList); await repositoryCache.saveCache(); @@ -36,6 +38,6 @@ export async function finalizeRepo( logger.debug('Repo is activated'); config.repoIsActivated = true; } - runBranchSummary(config); + runBranchSummary(config, packageFiles); runRenovateRepoStats(config, prList); } diff --git a/lib/workers/repository/finalize/repository-statistics.spec.ts b/lib/workers/repository/finalize/repository-statistics.spec.ts index 84c04a2542ef8e..f0860f174a9097 100644 --- a/lib/workers/repository/finalize/repository-statistics.spec.ts +++ b/lib/workers/repository/finalize/repository-statistics.spec.ts @@ -6,6 +6,7 @@ import { partial, } from '../../../../test/util'; import { logger } from '../../../logger'; +import type { PackageFile } from '../../../modules/manager/types'; import { platform } from '../../../modules/platform'; import * as cache from '../../../util/cache/repository'; import type { @@ -67,8 +68,9 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(true); + const packageFiles: Record = {}; - runBranchSummary(config); + runBranchSummary(config, packageFiles); expect(logger.debug).toHaveBeenCalledWith( { @@ -128,8 +130,9 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(false); + const packageFiles: Record = {}; - runBranchSummary(config); + runBranchSummary(config, packageFiles); expect(logger.debug).toHaveBeenCalledWith( { @@ -155,11 +158,11 @@ describe('workers/repository/finalize/repository-statistics', () => { ); }); - it('logs extended branch info if branchSummaryExtended', () => { + it('logs extended branch info if logDependencyDashboardInfo', () => { const defaultBranch = 'main'; const config: RenovateConfig = { defaultBranch, - branchSummaryExtended: true, + logDependencyDashboardInfo: true, }; const branchCache = partial({ dependencyDashboard: true, @@ -182,8 +185,9 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(false); + const packageFiles: Record = {}; - runBranchSummary(config); + runBranchSummary(config, packageFiles); expect(logger.debug).toHaveBeenCalledTimes(2); }); diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index 044c6e68f5b2aa..e3e5e268fb27db 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -1,5 +1,6 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; +import type { PackageFile } from '../../../modules/manager/types'; import type { Pr } from '../../../modules/platform'; import { getCache, isCacheModified } from '../../../util/cache/repository'; import type { BranchCache } from '../../../util/cache/repository/types'; @@ -8,6 +9,7 @@ import type { BranchMetadata, BranchSummary, } from '../../types'; +import { extractRepoProblems } from '../dependency-dashboard'; export function runRenovateRepoStats( config: RenovateConfig, @@ -76,18 +78,43 @@ function filterDependencyDashboardData( delete b.pristine; delete b.prCache; delete b.sha; - b.upgrades = b.upgrades?.map((upgrade) => { - const u = { ...upgrade }; - delete u.sourceUrl; - delete u.depType; - return u; - }); + delete b.dependencyDashboard, + delete b.dependencyDashboardApproval, + delete b.dependencyDashboardFooter, + delete b.dependencyDashboardHeader, + delete b.dependencyDashboardPrApproval, + delete b.dependencyDashboardTitle, + (b.upgrades = b.upgrades?.map((upgrade) => { + const u = { ...upgrade }; + delete u.sourceUrl; + delete u.depType; + return u; + })); return b; }); return dependencyDashboardData; } -export function runBranchSummary(config: RenovateConfig): void { +function minimizePackageFiles( + packageFiles: Record +): Record[]> { + const packageFilesMinimized: Record[]> = {}; + if (packageFiles) { + for (const manager in packageFiles) { + const packageFile = packageFiles[manager]; + packageFilesMinimized[manager] = packageFile.map((file) => ({ + deps: file.deps.map(({ warnings }) => ({ warnings })), + packageFile: file.packageFile, + })); + } + } + return packageFilesMinimized; +} + +export function runBranchSummary( + config: RenovateConfig, + packageFiles: Record +): void { const defaultBranch = config.defaultBranch; const { scan, branches } = getCache(); @@ -116,10 +143,19 @@ export function runBranchSummary(config: RenovateConfig): void { }; logger.debug(res, 'Branch summary'); - if (branches) { + + if (config.logDependencyDashboardInfo && branches?.length) { const branchesInformation = filterDependencyDashboardData(branches); - if (config.branchSummaryExtended) { - logger.debug({ branchesInformation }, 'Branches info extended'); - } + + // log repo problems for dependency dashboard + const repoProblems = extractRepoProblems(config); + + // log minimized packageFiles necessary for dependency dashboard + const packageFilesToPrint = minimizePackageFiles(packageFiles); + + logger.debug( + { branchesInformation, repoProblems, packageFilesToPrint }, + 'branches info extended' + ); } } diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts index 45103753917f34..d35d9cca848ace 100644 --- a/lib/workers/repository/index.ts +++ b/lib/workers/repository/index.ts @@ -90,7 +90,7 @@ export async function renovateRepository( } else { await ensureDependencyDashboard(config, branches, packageFiles); } - await finalizeRepo(config, branchList); + await finalizeRepo(config, branchList, packageFiles); // TODO #7154 repoResult = processResult(config, res!); } diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 28c3649fec9148..baf9a029d5a3f3 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -131,10 +131,10 @@ export interface BranchConfig export interface BranchMetadata { branchName: string; - branchSha: string | null | undefined; + branchSha?: string | null; baseBranch?: string; baseBranchSha?: string | null; - automerge: boolean | undefined; + automerge?: boolean; isModified?: boolean; isPristine?: boolean; } From de263395e2fe2e71e0f941a0526310e8b5eb09b2 Mon Sep 17 00:00:00 2001 From: philipabed Date: Sun, 14 May 2023 17:29:57 +0300 Subject: [PATCH 09/14] fix --- lib/workers/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/workers/types.ts b/lib/workers/types.ts index baf9a029d5a3f3..d7c0feac3f1a98 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -141,7 +141,7 @@ export interface BranchMetadata { export interface BaseBranchMetadata { branchName: string; - sha: string | undefined; + sha?: string; } export interface BranchSummary { From 103353b64b2d18cad8a14752902db238f7bd311d Mon Sep 17 00:00:00 2001 From: philipabed Date: Sun, 14 May 2023 19:07:28 +0300 Subject: [PATCH 10/14] review fix --- lib/config/options/index.ts | 5 +- lib/config/types.ts | 2 +- lib/util/cache/repository/types.ts | 8 --- lib/workers/global/index.ts | 1 + .../repository/dependency-dashboard.ts | 1 + lib/workers/repository/finalize/index.ts | 6 +-- .../finalize/repository-statistics.spec.ts | 15 ++---- .../finalize/repository-statistics.ts | 54 ++++--------------- lib/workers/repository/index.ts | 2 +- 9 files changed, 22 insertions(+), 72 deletions(-) diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 36350d7ebf3da6..a11246abff1508 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2635,9 +2635,8 @@ const options: RenovateOptions[] = [ default: [], }, { - name: 'logDependencyDashboardInfo', - description: - 'logs dependency dashboard information before transforming into dependency dashboard issue', + name: 'branchSummaryExtended', + description: 'logs extra branch metadata', type: 'boolean', experimental: true, globalOnly: true, diff --git a/lib/config/types.ts b/lib/config/types.ts index dc83cc4167939f..54d18840999e73 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -263,7 +263,7 @@ export interface RenovateConfig constraintsFiltering?: ConstraintsFilter; checkedBranches?: string[]; - logDependencyDashboardInfo?: boolean; + branchSummaryExtended?: boolean; } export interface AllConfig diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index f133f68a62c33d..18c223498a128d 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -104,17 +104,9 @@ export interface BranchCache { /** * Dependency dashboard information */ - dependencyDashboard?: boolean; - dependencyDashboardApproval?: boolean; - dependencyDashboardPrApproval?: unknown; - dependencyDashboardTitle?: string; - dependencyDashboardFooter?: unknown; - dependencyDashboardHeader?: unknown; prBlockedBy?: PrBlockedBy; prTitle?: string; - repoProblems?: Set; result?: string; - packageFiles?: Record[]>; } export interface RepoCacheData { diff --git a/lib/workers/global/index.ts b/lib/workers/global/index.ts index 80869a7426c87e..e89dfd61914f89 100644 --- a/lib/workers/global/index.ts +++ b/lib/workers/global/index.ts @@ -209,6 +209,7 @@ export async function start(): Promise { await globalFinalize(config!); logger.debug(`Renovate exiting`); } + const loggerErrors = getProblems().filter((p) => p.level >= ERROR); if (loggerErrors.length) { logger.info( diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 5324bad1416fe7..5bfd7857547f5b 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -457,6 +457,7 @@ export async function ensureDependencyDashboard( header = template.compile(config.dependencyDashboardHeader, config); } const repoProblems = extractRepoProblems(config); + logger.debug({ repoProblems }, 'repository problems'); let { issueBody } = createDashboardBody( header, diff --git a/lib/workers/repository/finalize/index.ts b/lib/workers/repository/finalize/index.ts index edb2c3858064fa..0a5064e4458399 100644 --- a/lib/workers/repository/finalize/index.ts +++ b/lib/workers/repository/finalize/index.ts @@ -1,6 +1,5 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; -import type { PackageFile } from '../../../modules/manager/types'; import { platform } from '../../../modules/platform'; import * as repositoryCache from '../../../util/cache/repository'; import { clearRenovateRefs } from '../../../util/git'; @@ -15,8 +14,7 @@ import { // istanbul ignore next export async function finalizeRepo( config: RenovateConfig, - branchList: string[], - packageFiles: Record + branchList: string[] ): Promise { await configMigration(config, branchList); await repositoryCache.saveCache(); @@ -38,6 +36,6 @@ export async function finalizeRepo( logger.debug('Repo is activated'); config.repoIsActivated = true; } - runBranchSummary(config, packageFiles); + runBranchSummary(config); runRenovateRepoStats(config, prList); } diff --git a/lib/workers/repository/finalize/repository-statistics.spec.ts b/lib/workers/repository/finalize/repository-statistics.spec.ts index f0860f174a9097..68f7ff022e6f5c 100644 --- a/lib/workers/repository/finalize/repository-statistics.spec.ts +++ b/lib/workers/repository/finalize/repository-statistics.spec.ts @@ -6,7 +6,6 @@ import { partial, } from '../../../../test/util'; import { logger } from '../../../logger'; -import type { PackageFile } from '../../../modules/manager/types'; import { platform } from '../../../modules/platform'; import * as cache from '../../../util/cache/repository'; import type { @@ -68,9 +67,8 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(true); - const packageFiles: Record = {}; - runBranchSummary(config, packageFiles); + runBranchSummary(config); expect(logger.debug).toHaveBeenCalledWith( { @@ -130,9 +128,8 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(false); - const packageFiles: Record = {}; - runBranchSummary(config, packageFiles); + runBranchSummary(config); expect(logger.debug).toHaveBeenCalledWith( { @@ -158,14 +155,13 @@ describe('workers/repository/finalize/repository-statistics', () => { ); }); - it('logs extended branch info if logDependencyDashboardInfo', () => { + it('logs extended branch info if branchSummaryExtended', () => { const defaultBranch = 'main'; const config: RenovateConfig = { defaultBranch, - logDependencyDashboardInfo: true, + branchSummaryExtended: true, }; const branchCache = partial({ - dependencyDashboard: true, result: 'done', upgrades: partial([ { @@ -185,9 +181,8 @@ describe('workers/repository/finalize/repository-statistics', () => { }); getCacheSpy.mockReturnValueOnce(cache); isCacheModifiedSpy.mockReturnValueOnce(false); - const packageFiles: Record = {}; - runBranchSummary(config, packageFiles); + 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 e3e5e268fb27db..9e3ffe0880600b 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -1,6 +1,5 @@ import type { RenovateConfig } from '../../../config/types'; import { logger } from '../../../logger'; -import type { PackageFile } from '../../../modules/manager/types'; import type { Pr } from '../../../modules/platform'; import { getCache, isCacheModified } from '../../../util/cache/repository'; import type { BranchCache } from '../../../util/cache/repository/types'; @@ -9,7 +8,6 @@ import type { BranchMetadata, BranchSummary, } from '../../types'; -import { extractRepoProblems } from '../dependency-dashboard'; export function runRenovateRepoStats( config: RenovateConfig, @@ -78,43 +76,18 @@ function filterDependencyDashboardData( delete b.pristine; delete b.prCache; delete b.sha; - delete b.dependencyDashboard, - delete b.dependencyDashboardApproval, - delete b.dependencyDashboardFooter, - delete b.dependencyDashboardHeader, - delete b.dependencyDashboardPrApproval, - delete b.dependencyDashboardTitle, - (b.upgrades = b.upgrades?.map((upgrade) => { - const u = { ...upgrade }; - delete u.sourceUrl; - delete u.depType; - return u; - })); + b.upgrades = b.upgrades?.map((upgrade) => { + const u = { ...upgrade }; + delete u.sourceUrl; + delete u.depType; + return u; + }); return b; }); return dependencyDashboardData; } -function minimizePackageFiles( - packageFiles: Record -): Record[]> { - const packageFilesMinimized: Record[]> = {}; - if (packageFiles) { - for (const manager in packageFiles) { - const packageFile = packageFiles[manager]; - packageFilesMinimized[manager] = packageFile.map((file) => ({ - deps: file.deps.map(({ warnings }) => ({ warnings })), - packageFile: file.packageFile, - })); - } - } - return packageFilesMinimized; -} - -export function runBranchSummary( - config: RenovateConfig, - packageFiles: Record -): void { +export function runBranchSummary(config: RenovateConfig): void { const defaultBranch = config.defaultBranch; const { scan, branches } = getCache(); @@ -144,18 +117,9 @@ export function runBranchSummary( logger.debug(res, 'Branch summary'); - if (config.logDependencyDashboardInfo && branches?.length) { + if (config.branchSummaryExtended && branches?.length) { const branchesInformation = filterDependencyDashboardData(branches); - // log repo problems for dependency dashboard - const repoProblems = extractRepoProblems(config); - - // log minimized packageFiles necessary for dependency dashboard - const packageFilesToPrint = minimizePackageFiles(packageFiles); - - logger.debug( - { branchesInformation, repoProblems, packageFilesToPrint }, - 'branches info extended' - ); + logger.debug({ branchesInformation }, 'branches info extended'); } } diff --git a/lib/workers/repository/index.ts b/lib/workers/repository/index.ts index d35d9cca848ace..45103753917f34 100644 --- a/lib/workers/repository/index.ts +++ b/lib/workers/repository/index.ts @@ -90,7 +90,7 @@ export async function renovateRepository( } else { await ensureDependencyDashboard(config, branches, packageFiles); } - await finalizeRepo(config, branchList, packageFiles); + await finalizeRepo(config, branchList); // TODO #7154 repoResult = processResult(config, res!); } From c90eef47266082d93b33c4e5e44ed39d2566df75 Mon Sep 17 00:00:00 2001 From: philipabed Date: Sun, 14 May 2023 19:17:09 +0300 Subject: [PATCH 11/14] review fix --- lib/workers/repository/dependency-dashboard.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 5bfd7857547f5b..c976211e095a25 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -456,8 +456,11 @@ export async function ensureDependencyDashboard( if (config.dependencyDashboardHeader?.length) { header = template.compile(config.dependencyDashboardHeader, config); } + const repoProblems = extractRepoProblems(config); - logger.debug({ repoProblems }, 'repository problems'); + if (repoProblems.size) { + logger.debug({ repoProblems }, 'repository problems'); + } let { issueBody } = createDashboardBody( header, From f546690c4eed238705efd3f357a8066bc9d4a1f6 Mon Sep 17 00:00:00 2001 From: philipabed Date: Mon, 15 May 2023 17:48:00 +0300 Subject: [PATCH 12/14] review fix --- docs/usage/self-hosted-configuration.md | 4 - lib/config/options/index.ts | 8 - lib/config/types.ts | 1 - lib/workers/global/index.ts | 1 - .../repository/dependency-dashboard.ts | 214 +++++++----------- lib/workers/repository/errors-warnings.ts | 4 +- .../finalize/repository-statistics.ts | 3 +- lib/workers/types.ts | 24 +- 8 files changed, 80 insertions(+), 179 deletions(-) diff --git a/docs/usage/self-hosted-configuration.md b/docs/usage/self-hosted-configuration.md index eb298510e5565a..fcf72c943a86ab 100644 --- a/docs/usage/self-hosted-configuration.md +++ b/docs/usage/self-hosted-configuration.md @@ -191,10 +191,6 @@ If all projects are managed by Hermit, you can tell Renovate to use the tooling Tools not on this list fall back to `binarySource=global`. -## branchSummaryExtended - -When enabled, will print extra information about the branches and dependency dashboard. - ## cacheDir By default Renovate stores cache data in a temporary directory like `/tmp/renovate/cache`. diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index a11246abff1508..a020d9dae72157 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -2634,14 +2634,6 @@ const options: RenovateOptions[] = [ globalOnly: true, default: [], }, - { - name: 'branchSummaryExtended', - description: 'logs extra branch metadata', - type: 'boolean', - experimental: true, - globalOnly: true, - default: false, - }, ]; export function getOptions(): RenovateOptions[] { diff --git a/lib/config/types.ts b/lib/config/types.ts index 54d18840999e73..4286c5a512e242 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -263,7 +263,6 @@ export interface RenovateConfig constraintsFiltering?: ConstraintsFilter; checkedBranches?: string[]; - branchSummaryExtended?: boolean; } export interface AllConfig diff --git a/lib/workers/global/index.ts b/lib/workers/global/index.ts index e89dfd61914f89..80869a7426c87e 100644 --- a/lib/workers/global/index.ts +++ b/lib/workers/global/index.ts @@ -209,7 +209,6 @@ export async function start(): Promise { await globalFinalize(config!); logger.debug(`Renovate exiting`); } - const loggerErrors = getProblems().filter((p) => p.level >= ERROR); if (loggerErrors.length) { logger.info( diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index c976211e095a25..3796d9f0fca149 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -8,12 +8,7 @@ import { platform } from '../../modules/platform'; import { GitHubMaxPrBodyLen } from '../../modules/platform/github'; import { regEx } from '../../util/regex'; import * as template from '../../util/template'; -import type { - BranchConfig, - Dashboard, - DashboardBody, - SelectAllConfig, -} from '../types'; +import type { BranchConfig, SelectAllConfig } from '../types'; import { getDepWarningsDashboard } from './errors-warnings'; import { PackageFiles } from './package-files'; @@ -138,9 +133,9 @@ export async function readDashboardBody( } } -function getListItem(branch: Partial, type: string): string { +function getListItem(branch: BranchConfig, type: string): string { let item = ' - [ ] '; - item += ``; + item += ``; if (branch.prNo) { // TODO: types (#7154) item += `[${branch.prTitle!}](../pull/${branch.prNo})`; @@ -149,7 +144,7 @@ function getListItem(branch: Partial, type: string): string { } const uniquePackages = [ // TODO: types (#7154) - ...new Set(branch.upgrades!.map((upgrade) => `\`${upgrade.depName!}\``)), + ...new Set(branch.upgrades.map((upgrade) => `\`${upgrade.depName!}\``)), ]; if (uniquePackages.length < 2) { return item + '\n'; @@ -157,8 +152,9 @@ function getListItem(branch: Partial, type: string): string { return item + ' (' + uniquePackages.join(', ') + ')\n'; } -export function extractRepoProblems(config: RenovateConfig): Set { - return new Set( +function appendRepoProblems(config: RenovateConfig, issueBody: string): string { + let newIssueBody = issueBody; + const repoProblems = new Set( getProblems() .filter( (problem) => @@ -169,57 +165,89 @@ export function extractRepoProblems(config: RenovateConfig): Set { `${nameFromLevel[problem.level].toUpperCase()}: ${problem.msg}` ) ); -} - -export function createDashboardBody( - header: string | undefined, - repoProblems: Set, - branches: Partial[], - packageFiles: Record[]> -): DashboardBody { - let issueBody = ''; - - const dashboard: Dashboard = { - awaitingSchedule: [], - prCreationApprovalRequired: [], - editedOrBlocked: [], - errored: [], - ignoredOrBlocked: [], - open: [], - otherBranches: [], - pendingApprovals: [], - pendingAutomerge: [], - pendingStatusChecks: [], - rateLimited: [], - repositoryProblems: new Set(), - header: '', - }; - - if (header) { - issueBody += header + '\n\n'; - } - if (repoProblems.size) { - issueBody += '## Repository problems\n\n'; - issueBody += + logger.debug({ repoProblems }, 'repository problems'); + newIssueBody += '## Repository problems\n\n'; + newIssueBody += 'These problems occurred while renovating this repository.\n\n'; for (const repoProblem of repoProblems) { - issueBody += ` - ${repoProblem}\n`; + newIssueBody += ` - ${repoProblem}\n`; } - issueBody += '\n'; - dashboard.repositoryProblems = repoProblems; + newIssueBody += '\n'; + } + return newIssueBody; +} + +export async function ensureDependencyDashboard( + config: SelectAllConfig, + allBranches: BranchConfig[], + packageFiles: Record = {} +): Promise { + // legacy/migrated issue + const reuseTitle = 'Update Dependencies (Renovate Bot)'; + const branches = allBranches.filter( + (branch) => + branch.result !== 'automerged' && + !branch.upgrades?.every((upgrade) => upgrade.remediationNotPossible) + ); + if ( + !( + config.dependencyDashboard || + config.dependencyDashboardApproval || + config.packageRules?.some((rule) => rule.dependencyDashboardApproval) || + branches.some( + (branch) => + !!branch.dependencyDashboardApproval || + !!branch.dependencyDashboardPrApproval + ) + ) + ) { + if (GlobalConfig.get('dryRun')) { + logger.info( + { title: config.dependencyDashboardTitle }, + 'DRY-RUN: Would close Dependency Dashboard' + ); + } else { + logger.debug('Closing Dependency Dashboard'); + await platform.ensureIssueClosing(config.dependencyDashboardTitle!); + } + return; + } + // istanbul ignore if + if (config.repoIsOnboarded === false) { + logger.debug('Repo is onboarding - skipping dependency dashboard'); + return; + } + logger.debug('Ensuring Dependency Dashboard'); + const hasBranches = is.nonEmptyArray(branches); + if (config.dependencyDashboardAutoclose && !hasBranches) { + if (GlobalConfig.get('dryRun')) { + logger.info( + { title: config.dependencyDashboardTitle }, + 'DRY-RUN: Would close Dependency Dashboard' + ); + } else { + logger.debug('Closing Dependency Dashboard'); + await platform.ensureIssueClosing(config.dependencyDashboardTitle!); + } + return; } + let issueBody = ''; + if (config.dependencyDashboardHeader?.length) { + issueBody += + template.compile(config.dependencyDashboardHeader, config) + '\n\n'; + } + + issueBody = appendRepoProblems(config, issueBody); const pendingApprovals = branches.filter( (branch) => branch.result === 'needs-approval' ); - if (pendingApprovals.length) { issueBody += '## Pending Approval\n\n'; issueBody += `These branches will be created by Renovate only once you click their checkbox below.\n\n`; for (const branch of pendingApprovals) { issueBody += getListItem(branch, 'approve'); - dashboard.pendingApprovals.push(branch); } if (pendingApprovals.length > 1) { issueBody += ' - [ ] '; @@ -228,7 +256,6 @@ export function createDashboardBody( } issueBody += '\n'; } - const awaitingSchedule = branches.filter( (branch) => branch.result === 'not-scheduled' ); @@ -238,11 +265,9 @@ export function createDashboardBody( 'These updates are awaiting their schedule. Click on a checkbox to get an update now.\n\n'; for (const branch of awaitingSchedule) { issueBody += getListItem(branch, 'unschedule'); - dashboard.awaitingSchedule.push(branch); } issueBody += '\n'; } - const rateLimited = branches.filter( (branch) => branch.result === 'branch-limit-reached' || @@ -255,7 +280,6 @@ export function createDashboardBody( 'These updates are currently rate-limited. Click on a checkbox below to force their creation now.\n\n'; for (const branch of rateLimited) { issueBody += getListItem(branch, 'unlimit'); - dashboard.rateLimited.push(branch); } if (rateLimited.length > 1) { issueBody += ' - [ ] '; @@ -264,7 +288,6 @@ export function createDashboardBody( } issueBody += '\n'; } - const errorList = branches.filter((branch) => branch.result === 'error'); if (errorList.length) { issueBody += '## Errored\n\n'; @@ -272,11 +295,9 @@ export function createDashboardBody( 'These updates encountered an error and will be retried. Click on a checkbox below to force a retry now.\n\n'; for (const branch of errorList) { issueBody += getListItem(branch, 'retry'); - dashboard.errored.push(branch); } issueBody += '\n'; } - const awaitingPr = branches.filter( (branch) => branch.result === 'needs-pr-approval' ); @@ -286,18 +307,15 @@ export function createDashboardBody( "These branches exist but PRs won't be created until you approve them by clicking on a checkbox.\n\n"; for (const branch of awaitingPr) { issueBody += getListItem(branch, 'approvePr'); - dashboard.prCreationApprovalRequired.push(branch); } issueBody += '\n'; } - const prEdited = branches.filter((branch) => branch.result === 'pr-edited'); if (prEdited.length) { issueBody += '## Edited/Blocked\n\n'; issueBody += `These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.\n\n`; for (const branch of prEdited) { issueBody += getListItem(branch, 'rebase'); - dashboard.editedOrBlocked.push(branch); } issueBody += '\n'; } @@ -307,7 +325,6 @@ export function createDashboardBody( issueBody += `These updates await pending status checks. To force their creation now, click the checkbox below.\n\n`; for (const branch of prPending) { issueBody += getListItem(branch, 'approvePr'); - dashboard.pendingStatusChecks.push(branch); } issueBody += '\n'; } @@ -319,14 +336,12 @@ export function createDashboardBody( issueBody += `These updates await pending status checks before automerging. Click on a checkbox to abort the branch automerge, and create a PR instead.\n\n`; for (const branch of prPendingBranchAutomerge) { issueBody += getListItem(branch, 'approvePr'); - dashboard.pendingAutomerge.push(branch); } issueBody += '\n'; } const warn = getDepWarningsDashboard(packageFiles); if (warn) { - dashboard.warn = warn; issueBody += warn; issueBody += '\n'; } @@ -358,7 +373,6 @@ export function createDashboardBody( issueBody += `These updates are pending. To force PRs open, click the checkbox below.\n\n`; for (const branch of otherBranches) { issueBody += getListItem(branch, 'other'); - dashboard.otherBranches.push(branch); } issueBody += '\n'; } @@ -371,7 +385,6 @@ export function createDashboardBody( 'These updates have all been created already. Click a checkbox below to force a retry/rebase of any.\n\n'; for (const branch of inProgress) { issueBody += getListItem(branch, 'rebase'); - dashboard.open.push(branch); } if (inProgress.length > 2) { issueBody += ' - [ ] '; @@ -390,84 +403,9 @@ export function createDashboardBody( 'These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.\n\n'; for (const branch of alreadyExisted) { issueBody += getListItem(branch, 'recreate'); - dashboard.ignoredOrBlocked.push(branch); } issueBody += '\n'; } - return { issueBody, dashboard }; -} - -export async function ensureDependencyDashboard( - config: SelectAllConfig, - allBranches: BranchConfig[], - packageFiles: Record = {} -): Promise { - // legacy/migrated issue - const reuseTitle = 'Update Dependencies (Renovate Bot)'; - const branches = allBranches.filter( - (branch) => - branch.result !== 'automerged' && - !branch.upgrades?.every((upgrade) => upgrade.remediationNotPossible) - ); - if ( - !( - config.dependencyDashboard || - config.dependencyDashboardApproval || - config.packageRules?.some((rule) => rule.dependencyDashboardApproval) || - branches.some( - (branch) => - !!branch.dependencyDashboardApproval || - !!branch.dependencyDashboardPrApproval - ) - ) - ) { - if (GlobalConfig.get('dryRun')) { - logger.info( - { title: config.dependencyDashboardTitle }, - 'DRY-RUN: Would close Dependency Dashboard' - ); - } else { - logger.debug('Closing Dependency Dashboard'); - await platform.ensureIssueClosing(config.dependencyDashboardTitle!); - } - return; - } - // istanbul ignore if - if (config.repoIsOnboarded === false) { - logger.debug('Repo is onboarding - skipping dependency dashboard'); - return; - } - logger.debug('Ensuring Dependency Dashboard'); - const hasBranches = is.nonEmptyArray(branches); - if (config.dependencyDashboardAutoclose && !hasBranches) { - if (GlobalConfig.get('dryRun')) { - logger.info( - { title: config.dependencyDashboardTitle }, - 'DRY-RUN: Would close Dependency Dashboard' - ); - } else { - logger.debug('Closing Dependency Dashboard'); - await platform.ensureIssueClosing(config.dependencyDashboardTitle!); - } - return; - } - - let header; - if (config.dependencyDashboardHeader?.length) { - header = template.compile(config.dependencyDashboardHeader, config); - } - - const repoProblems = extractRepoProblems(config); - if (repoProblems.size) { - logger.debug({ repoProblems }, 'repository problems'); - } - - let { issueBody } = createDashboardBody( - header, - repoProblems, - branches, - packageFiles - ); if (!hasBranches) { issueBody += diff --git a/lib/workers/repository/errors-warnings.ts b/lib/workers/repository/errors-warnings.ts index e7935c6b68079e..306cf9a939e667 100644 --- a/lib/workers/repository/errors-warnings.ts +++ b/lib/workers/repository/errors-warnings.ts @@ -33,7 +33,7 @@ export function getErrors(config: RenovateConfig): string { } function getDepWarnings( - packageFiles: Record[]> + packageFiles: Record ): DepWarnings { const warnings: string[] = []; const warningFiles: string[] = []; @@ -104,7 +104,7 @@ export function getDepWarningsPR( } export function getDepWarningsDashboard( - packageFiles: Record[]> + packageFiles: Record ): string { const { warnings, warningFiles } = getDepWarnings(packageFiles); if (!warnings.length) { diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index 9e3ffe0880600b..44ebe6445c2659 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -117,9 +117,8 @@ export function runBranchSummary(config: RenovateConfig): void { logger.debug(res, 'Branch summary'); - if (config.branchSummaryExtended && branches?.length) { + 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 d7c0feac3f1a98..3c22c632cc9e82 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -141,7 +141,7 @@ export interface BranchMetadata { export interface BaseBranchMetadata { branchName: string; - sha?: string; + sha: string; } export interface BranchSummary { @@ -194,25 +194,3 @@ export interface ExtractResult { extractionFingerprints: Record; packageFiles: Record; } - -export interface Dashboard { - awaitingSchedule: Partial[]; - prCreationApprovalRequired: Partial[]; - editedOrBlocked: Partial[]; - errored: Partial[]; - ignoredOrBlocked: Partial[]; - open: Partial[]; - otherBranches: Partial[]; - pendingApprovals: Partial[]; - pendingAutomerge: Partial[]; - pendingStatusChecks: Partial[]; - rateLimited: Partial[]; - repositoryProblems?: Set; - header: string; - warn?: string; -} - -export interface DashboardBody { - issueBody: string; - dashboard: Dashboard; -} From ea9bc6bdcb5562de76f9afb7361fe28dcc130aed Mon Sep 17 00:00:00 2001 From: philipabed Date: Tue, 16 May 2023 11:15:39 +0300 Subject: [PATCH 13/14] review fix --- .../finalize/repository-statistics.ts | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index 44ebe6445c2659..f7e9f7a53a104d 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, @@ -63,28 +66,53 @@ function branchCacheToMetadata({ function filterDependencyDashboardData( branches: BranchCache[] ): Partial[] { - let dependencyDashboardData = [...branches]; - dependencyDashboardData = dependencyDashboardData.map((branch) => { - const b = { ...branch }; - delete b.isModified; - delete b.automerge; - delete b.isBehindBase; - delete b.isConflicted; - delete b.baseBranch; - delete b.baseBranchSha; - delete b.branchFingerprint; - delete b.pristine; - delete b.prCache; - delete b.sha; - b.upgrades = b.upgrades?.map((upgrade) => { - const u = { ...upgrade }; - delete u.sourceUrl; - delete u.depType; - return u; - }); - return b; - }); - return dependencyDashboardData; + const branchesFiltered: Partial[] = []; + for (const branch of branches) { + const upgradesFiltered: Partial[] = []; + const { branchName, prNo, prTitle, result, upgrades } = 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, + upgrades: upgradesFiltered, + }; + branchesFiltered.push(filteredBranch); + } + + return branchesFiltered; } export function runBranchSummary(config: RenovateConfig): void { From 7ba4534d3188e6fa6b6fb0159d5d29151f1b2be1 Mon Sep 17 00:00:00 2001 From: philipabed Date: Wed, 17 May 2023 17:34:28 +0300 Subject: [PATCH 14/14] add prBlockedBy --- lib/workers/repository/finalize/repository-statistics.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/workers/repository/finalize/repository-statistics.ts b/lib/workers/repository/finalize/repository-statistics.ts index f7e9f7a53a104d..e2b5224a5be35c 100644 --- a/lib/workers/repository/finalize/repository-statistics.ts +++ b/lib/workers/repository/finalize/repository-statistics.ts @@ -69,7 +69,7 @@ function filterDependencyDashboardData( const branchesFiltered: Partial[] = []; for (const branch of branches) { const upgradesFiltered: Partial[] = []; - const { branchName, prNo, prTitle, result, upgrades } = branch; + const { branchName, prNo, prTitle, result, upgrades, prBlockedBy } = branch; for (const upgrade of upgrades ?? []) { const { @@ -107,6 +107,7 @@ function filterDependencyDashboardData( prNo, prTitle, result, + prBlockedBy, upgrades: upgradesFiltered, }; branchesFiltered.push(filteredBranch);