diff --git a/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap b/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap new file mode 100644 index 00000000000000..41a7139fd43448 --- /dev/null +++ b/lib/workers/repository/__snapshots__/dependency-dashboard.spec.ts.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`workers/repository/master-issue ensureMasterIssue() open or update Dependency Dashboard when all branches are closed and dependencyDashboardAutoclose is false 1`] = ` +"This issue contains a list of Renovate updates and their statuses. + +This repository currently has no open or pending branches. + +--- +And this is a footer +" +`; diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index 909d5ad9d5c1c2..0b863cb8f8a6dc 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -119,15 +119,14 @@ describe('workers/repository/master-issue', () => { it('open or update Dependency Dashboard when all branches are closed and dependencyDashboardAutoclose is false', async () => { const branches: BranchConfig[] = []; config.dependencyDashboard = true; + config.dependencyDashboardFooter = 'And this is a footer'; await dependencyDashboard.ensureMasterIssue(config, branches); expect(platform.ensureIssueClosing).toHaveBeenCalledTimes(0); expect(platform.ensureIssue).toHaveBeenCalledTimes(1); expect(platform.ensureIssue.mock.calls[0][0].title).toBe( config.dependencyDashboardTitle ); - expect(platform.ensureIssue.mock.calls[0][0].body).toBe( - 'This repository is up-to-date and has no outstanding updates open or pending.' - ); + expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot(); expect(platform.getBranchPr).toHaveBeenCalledTimes(0); expect(platform.findPr).toHaveBeenCalledTimes(0); diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index c687327704ca2e..68783b26a4cf9b 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -1,3 +1,4 @@ +import is from '@sindresorhus/is'; import { RenovateConfig } from '../../config'; import { logger } from '../../logger'; import { Pr, platform } from '../../platform'; @@ -40,34 +41,18 @@ export async function ensureMasterIssue( return; } logger.debug('Ensuring Dependency Dashboard'); - if ( - !branches.length || - branches.every((branch) => branch.res === 'automerged') - ) { - if (config.dependencyDashboardAutoclose) { - logger.debug('Closing Dependency Dashboard'); - if (config.dryRun) { - logger.info( - 'DRY-RUN: Would close Dependency Dashboard ' + - config.dependencyDashboardTitle - ); - } else { - await platform.ensureIssueClosing(config.dependencyDashboardTitle); - } - return; - } + const hasBranches = + is.nonEmptyArray(branches) && + branches.some((branch) => branch.res !== 'automerged'); + if (config.dependencyDashboardAutoclose && !hasBranches) { if (config.dryRun) { logger.info( - 'DRY-RUN: Would ensure Dependency Dashboard ' + + 'DRY-RUN: Would close Dependency Dashboard ' + config.dependencyDashboardTitle ); } else { - await platform.ensureIssue({ - title: config.dependencyDashboardTitle, - reuseTitle, - body: - 'This repository is up-to-date and has no outstanding updates open or pending.', - }); + logger.debug('Closing Dependency Dashboard'); + await platform.ensureIssueClosing(config.dependencyDashboardTitle); } return; } @@ -204,7 +189,11 @@ export async function ensureMasterIssue( issueBody += '\n'; } - // istanbul ignore if + if (!hasBranches) { + issueBody += + 'This repository currently has no open or pending branches.\n\n'; + } + if (config.dependencyDashboardFooter?.length) { issueBody += `---\n${config.dependencyDashboardFooter}\n`; }