Skip to content

Commit

Permalink
fix: handle empty dependencyDashboard issue body (#23019)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh authored Jun 29, 2023

Verified

This commit was signed with the committer’s verified signature.
targos Michaël Zasso
1 parent 888d953 commit 04c8bda
Showing 2 changed files with 24 additions and 3 deletions.
20 changes: 20 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
7 changes: 4 additions & 3 deletions lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
@@ -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];

0 comments on commit 04c8bda

Please sign in to comment.