Skip to content

Commit

Permalink
fix(dependency-dashboard): skip unnecessary cache bust when unchanged (
Browse files Browse the repository at this point in the history
…renovatebot#26794)

Co-authored-by: Michael Kriese <[email protected]>
  • Loading branch information
2 people authored and zT-1337 committed Jan 24, 2024
1 parent 367dbfd commit ffeced4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/workers/repository/dependency-dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions lib/workers/repository/dependency-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit ffeced4

Please sign in to comment.