From ffeced4cabd467233fd33c39ad6aef88b7cceb92 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Mon, 22 Jan 2024 10:07:37 +0100 Subject: [PATCH] fix(dependency-dashboard): skip unnecessary cache bust when unchanged (#26794) Co-authored-by: Michael Kriese --- .../repository/dependency-dashboard.spec.ts | 29 +++++++++++++++++++ .../repository/dependency-dashboard.ts | 12 ++++++++ 2 files changed, 41 insertions(+) diff --git a/lib/workers/repository/dependency-dashboard.spec.ts b/lib/workers/repository/dependency-dashboard.spec.ts index a0d6ffc8d870cc3..8b12cbfba9e73d9 100644 --- a/lib/workers/repository/dependency-dashboard.spec.ts +++ b/lib/workers/repository/dependency-dashboard.spec.ts @@ -839,6 +839,10 @@ describe('workers/repository/dependency-dashboard', () => { config.dependencyDashboard = true; config.dependencyDashboardChecks = { branchName2: 'approve-branch' }; config.dependencyDashboardIssue = 1; + mockedFunction(platform.getIssue).mockResolvedValueOnce({ + title: 'Dependency Dashboard', + body: '', + }); mockedFunction(platform.getIssue).mockResolvedValueOnce({ title: 'Dependency Dashboard', body: `This issue contains a list of Renovate updates and their statuses. @@ -863,6 +867,31 @@ describe('workers/repository/dependency-dashboard', () => { expect(platform.ensureIssue.mock.calls[0][0].body).toMatchSnapshot(); }); + it('skips fetching issue if content unchanged', async () => { + const branches: BranchConfig[] = []; + config.dependencyDashboard = true; + config.dependencyDashboardChecks = {}; + config.dependencyDashboardIssue = 1; + mockedFunction(platform.getIssue).mockResolvedValueOnce({ + title: 'Dependency Dashboard', + body: `This issue lists Renovate updates and detected dependencies. Read the [Dependency Dashboard](https://docs.renovatebot.com/key-concepts/dashboard/) docs to learn more. + +This repository currently has no open or pending branches. + +## Detected dependencies + +None detected + +`, + }); + mockedFunction(platform.getIssue).mockResolvedValueOnce({ + title: 'Dependency Dashboard', + body: '', + }); + await dependencyDashboard.ensureDependencyDashboard(config, branches); + expect(platform.ensureIssue).not.toHaveBeenCalled(); + }); + it('forwards configured labels to the ensure issue call', async () => { const branches: BranchConfig[] = []; config.dependencyDashboard = true; diff --git a/lib/workers/repository/dependency-dashboard.ts b/lib/workers/repository/dependency-dashboard.ts index 8ca7e3aa2d32506..92a9bbf6dc4acae 100644 --- a/lib/workers/repository/dependency-dashboard.ts +++ b/lib/workers/repository/dependency-dashboard.ts @@ -423,6 +423,18 @@ export async function ensureDependencyDashboard( issueBody += footer; if (config.dependencyDashboardIssue) { + // If we're not changing the dashboard issue then we can skip checking if the user changed it + // The cached issue we get back here will reflect its state at the _start_ of our run + const cachedIssue = await platform.getIssue?.( + config.dependencyDashboardIssue, + ); + if (cachedIssue?.body === issueBody) { + logger.debug('No changes to dependency dashboard issue needed'); + return; + } + + // Skip cache when getting the issue to ensure we get the latest body, + // including any updates the user made after we started the run const updatedIssue = await platform.getIssue?.( config.dependencyDashboardIssue, false,