From 04c8bda2e6f8a74a5c62bbb0ce6cf03515319f37 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh <rahultesnik@gmail.com> Date: Thu, 29 Jun 2023 14:21:56 +0545 Subject: [PATCH] fix: handle empty dependencyDashboard issue body (#23019) --- .../repository/dependency-dashboard.spec.ts | 20 +++++++++++++++++++ .../repository/dependency-dashboard.ts | 7 ++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index 054eef3f32..659ee4daaf 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -92,6 +92,26 @@ async function dryRun( describe('workers/repository/dependency-dashboard', () => { describe('readDashboardBody()', () => { + it('parses invalid dashboard body without throwing error', async () => { + const conf: RenovateConfig = {}; + conf.prCreation = 'approval'; + platform.findIssue.mockResolvedValueOnce({ + title: '', + number: 1, + body: null as never, + }); + await dependencyDashboard.readDashboardBody(conf); + expect(conf).toEqual({ + dependencyDashboardChecks: {}, + dependencyDashboardAllPending: false, + dependencyDashboardAllRateLimited: false, + dependencyDashboardIssue: 1, + dependencyDashboardRebaseAllOpen: false, + dependencyDashboardTitle: 'Dependency Dashboard', + prCreation: 'approval', + }); + }); + it('reads dashboard body', async () => { const conf: RenovateConfig = {}; conf.prCreation = 'approval'; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index e3ceff9486..54ff00693f 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -76,7 +76,8 @@ function getAllSelectedBranches( function getCheckedBranches(issueBody: string): Record<string, string> { let dependencyDashboardChecks: Record<string, string> = {}; - for (const [, type, branchName] of issueBody.matchAll(markedBranchesRe)) { + for (const [, type, branchName] of issueBody?.matchAll(markedBranchesRe) ?? + []) { dependencyDashboardChecks[branchName] = type; } dependencyDashboardChecks = getAllSelectedBranches( @@ -115,7 +116,7 @@ export async function readDashboardBody( const issue = await platform.findIssue(config.dependencyDashboardTitle); if (issue) { config.dependencyDashboardIssue = issue.number; - const dashboardChecks = parseDashboardIssue(issue.body!); + const dashboardChecks = parseDashboardIssue(issue.body ?? ''); if (config.checkedBranches) { const checkedBranchesRec: Record<string, string> = Object.fromEntries( @@ -436,7 +437,7 @@ export async function ensureDependencyDashboard( ); if (updatedIssue) { const { dependencyDashboardChecks } = parseDashboardIssue( - updatedIssue.body! + updatedIssue.body ?? '' ); for (const branchName of Object.keys(config.dependencyDashboardChecks!)) { delete dependencyDashboardChecks[branchName]; -- GitLab