Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(github): remove deleted issue from issues cache #33349

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/modules/platform/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,11 @@ export async function getIssue(number: number): Promise<Issue | null> {
return issue;
} catch (err) /* istanbul ignore next */ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should no longer ignore this

logger.debug({ err, number }, 'Error getting issue');
// istanbul ignore if
if (err.message === 'Response Code 410(Gone)') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should check status code instead

logger.debug(`Issue #${number} has been deleted`);
GithubIssueCache.deleteIssue(number);
}
return null;
}
}
Expand Down
26 changes: 26 additions & 0 deletions lib/modules/platform/github/issue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,32 @@ describe('modules/platform/github/issue', () => {
});
});

it('removes particular issue from the cache', () => {
cache.platform = {
github: {
issuesCache: {
'1': {
number: 1,
body: 'body-1',
state: 'open',
title: 'title-1',
lastModified: '2020-01-01T00:00:00.000Z',
},
},
},
};

GithubIssueCache.deleteIssue(1);

expect(cache).toEqual({
platform: {
github: {
issuesCache: {},
},
},
});
});

it('reconciles cache', () => {
cache.platform = {
github: {
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/platform/github/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ export class GithubIssueCache {
}
}

static deleteIssue(number: number): void {
const cacheData = this.data;
if (cacheData) {
delete cacheData[number];
}
}

/**
* At the moment of repo initialization, repository cache is not available.
* What we can do is to store issues for later reconciliation.
Expand Down
Loading