Skip to content

Commit 579d8c8

Browse files
authoredApr 12, 2024··
feat(github): Fetch issues during repo initialization (#27785)
1 parent 771b91f commit 579d8c8

File tree

7 files changed

+480
-68
lines changed

7 files changed

+480
-68
lines changed
 

‎lib/modules/platform/github/graphql.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const repoInfoQuery = `
2-
query($owner: String!, $name: String!) {
2+
query($owner: String!, $name: String!, $user: String!) {
33
repository(owner: $owner, name: $name) {
44
id
55
isFork
@@ -20,6 +20,19 @@ query($owner: String!, $name: String!) {
2020
oid
2121
}
2222
}
23+
issues(
24+
orderBy: { field: UPDATED_AT, direction: DESC },
25+
filterBy: { createdBy: $user },
26+
first: 5
27+
) {
28+
nodes {
29+
number
30+
state
31+
title
32+
body
33+
updatedAt
34+
}
35+
}
2336
}
2437
}
2538
`;

‎lib/modules/platform/github/index.spec.ts

+56-16
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,13 @@ describe('modules/platform/github/index', () => {
17451745
},
17461746
})
17471747
.post('/repos/some/repo/issues')
1748-
.reply(200);
1748+
.reply(200, {
1749+
number: 3,
1750+
state: 'open',
1751+
title: 'new-title',
1752+
body: 'new-content',
1753+
updated_at: '2023-01-01T00:00:00Z',
1754+
});
17491755
const res = await github.ensureIssue({
17501756
title: 'new-title',
17511757
body: 'new-content',
@@ -1860,7 +1866,13 @@ describe('modules/platform/github/index', () => {
18601866
},
18611867
})
18621868
.post('/repos/some/repo/issues')
1863-
.reply(200);
1869+
.reply(200, {
1870+
number: 3,
1871+
state: 'open',
1872+
title: 'new-title',
1873+
body: 'new-content',
1874+
updated_at: '2023-01-01T00:00:00Z',
1875+
});
18641876
const res = await github.ensureIssue({
18651877
title: 'new-title',
18661878
body: 'new-content',
@@ -1966,7 +1978,13 @@ describe('modules/platform/github/index', () => {
19661978
updated_at: '2023-01-01T00:00:00Z',
19671979
})
19681980
.patch('/repos/some/repo/issues/2')
1969-
.reply(200);
1981+
.reply(200, {
1982+
number: 2,
1983+
state: 'open',
1984+
title: 'title-2',
1985+
body: 'newer-content',
1986+
updated_at: '2023-01-01T00:00:00Z',
1987+
});
19701988
const res = await github.ensureIssue({
19711989
title: 'title-3',
19721990
reuseTitle: 'title-2',
@@ -2019,7 +2037,13 @@ describe('modules/platform/github/index', () => {
20192037
updated_at: '2023-01-01T00:00:00Z',
20202038
})
20212039
.patch('/repos/some/repo/issues/2')
2022-
.reply(200);
2040+
.reply(200, {
2041+
number: 2,
2042+
state: 'open',
2043+
title: 'title-2',
2044+
body: 'newer-content',
2045+
updated_at: '2023-01-01T00:00:00Z',
2046+
});
20232047
const res = await github.ensureIssue({
20242048
title: 'title-3',
20252049
reuseTitle: 'title-2',
@@ -2108,14 +2132,6 @@ describe('modules/platform/github/index', () => {
21082132
},
21092133
},
21102134
})
2111-
.get('/repos/some/repo/issues/2')
2112-
.reply(200, {
2113-
number: 2,
2114-
state: 'open',
2115-
title: 'title-1',
2116-
body: 'newer-content',
2117-
updated_at: '2021-01-01T00:00:00Z',
2118-
})
21192135
.patch('/repos/some/repo/issues/1')
21202136
.reply(200);
21212137
const res = await github.ensureIssue({
@@ -2162,7 +2178,13 @@ describe('modules/platform/github/index', () => {
21622178
updated_at: '2023-01-01T00:00:00Z',
21632179
})
21642180
.post('/repos/some/repo/issues')
2165-
.reply(200);
2181+
.reply(200, {
2182+
number: 3,
2183+
state: 'open',
2184+
title: 'title-2',
2185+
body: 'new-content',
2186+
updated_at: '2023-01-01T00:00:00Z',
2187+
});
21662188
const res = await github.ensureIssue({
21672189
title: 'title-2',
21682190
body: 'new-content',
@@ -2253,7 +2275,13 @@ describe('modules/platform/github/index', () => {
22532275
},
22542276
})
22552277
.patch('/repos/undefined/issues/2')
2256-
.reply(200);
2278+
.reply(200, {
2279+
number: 2,
2280+
state: 'closed',
2281+
title: 'title-2',
2282+
body: 'new-content',
2283+
updated_at: '2023-01-01T00:00:00Z',
2284+
});
22572285
await expect(github.ensureIssueClosing('title-2')).toResolve();
22582286
});
22592287
});
@@ -2272,7 +2300,13 @@ describe('modules/platform/github/index', () => {
22722300
it('should add the given assignees to the issue', async () => {
22732301
const scope = httpMock.scope(githubApiHost);
22742302
initRepoMock(scope, 'some/repo');
2275-
scope.post('/repos/some/repo/issues/42/assignees').reply(200);
2303+
scope.post('/repos/some/repo/issues/42/assignees').reply(200, {
2304+
number: 42,
2305+
state: 'open',
2306+
title: 'title-42',
2307+
body: 'body-42',
2308+
updated_at: '2023-01-01T00:00:00Z',
2309+
});
22762310
await github.initRepo({ repository: 'some/repo' });
22772311
await expect(
22782312
github.addAssignees(42, ['someuser', 'someotheruser']),
@@ -3006,7 +3040,13 @@ describe('modules/platform/github/index', () => {
30063040
});
30073041
scope
30083042
.patch('/repos/some/repo/issues/123', (body) => body.milestone === 1)
3009-
.reply(200, {});
3043+
.reply(200, {
3044+
number: 123,
3045+
state: 'open',
3046+
title: 'bump someDep to v2',
3047+
body: 'many informations about someDep',
3048+
updated_at: '2023-01-01T00:00:00Z',
3049+
});
30103050
await github.initRepo({ repository: 'some/repo' });
30113051
const pr = await github.createPr({
30123052
targetBranch: 'main',

‎lib/modules/platform/github/index.ts

+47-39
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ import {
7373
repoInfoQuery,
7474
vulnerabilityAlertsQuery,
7575
} from './graphql';
76-
import { GithubIssue as Issue } from './issue';
76+
import { GithubIssueCache, GithubIssue as Issue } from './issue';
7777
import { massageMarkdownLinks } from './massage-markdown-links';
7878
import { getPrCache, updatePrCache } from './pr';
7979
import type {
@@ -497,6 +497,7 @@ export async function initRepo({
497497
variables: {
498498
owner: config.repositoryOwner,
499499
name: config.repositoryName,
500+
user: renovateUsername,
500501
},
501502
});
502503

@@ -557,6 +558,11 @@ export async function initRepo({
557558
config.autoMergeAllowed = repo.autoMergeAllowed;
558559
config.hasIssuesEnabled = repo.hasIssuesEnabled;
559560
config.hasVulnerabilityAlertsEnabled = repo.hasVulnerabilityAlertsEnabled;
561+
562+
const recentIssues = Issue.array()
563+
.catch([])
564+
.parse(res?.data?.repository?.issues?.nodes);
565+
GithubIssueCache.addIssuesToReconcile(recentIssues);
560566
} catch (err) /* istanbul ignore next */ {
561567
logger.debug({ err }, 'Caught initRepo error');
562568
if (
@@ -591,7 +597,6 @@ export async function initRepo({
591597
throw err;
592598
}
593599
// This shouldn't be necessary, but occasional strange errors happened until it was added
594-
config.issueList = null;
595600
config.prList = null;
596601

597602
if (forkToken) {
@@ -1221,17 +1226,16 @@ export async function getIssueList(): Promise<Issue[]> {
12211226
if (config.hasIssuesEnabled === false) {
12221227
return [];
12231228
}
1224-
if (!config.issueList) {
1229+
let issueList = GithubIssueCache.getIssues();
1230+
if (!issueList) {
12251231
logger.debug('Retrieving issueList');
1226-
config.issueList = await getIssues();
1232+
issueList = await getIssues();
1233+
GithubIssueCache.setIssues(issueList);
12271234
}
1228-
return config.issueList;
1235+
return issueList;
12291236
}
12301237

1231-
export async function getIssue(
1232-
number: number,
1233-
useCache = true,
1234-
): Promise<Issue | null> {
1238+
export async function getIssue(number: number): Promise<Issue | null> {
12351239
// istanbul ignore if
12361240
if (config.hasIssuesEnabled === false) {
12371241
return null;
@@ -1241,11 +1245,11 @@ export async function getIssue(
12411245
const { body: issue } = await githubApi.getJson(
12421246
`repos/${repo}/issues/${number}`,
12431247
{
1244-
memCache: useCache,
12451248
cacheProvider: repoCacheProvider,
12461249
},
12471250
Issue,
12481251
);
1252+
GithubIssueCache.updateIssue(issue);
12491253
return issue;
12501254
} catch (err) /* istanbul ignore next */ {
12511255
logger.debug({ err, number }, 'Error getting issue');
@@ -1267,12 +1271,13 @@ export async function findIssue(title: string): Promise<Issue | null> {
12671271

12681272
async function closeIssue(issueNumber: number): Promise<void> {
12691273
logger.debug(`closeIssue(${issueNumber})`);
1270-
await githubApi.patchJson(
1271-
`repos/${config.parentRepo ?? config.repository}/issues/${issueNumber}`,
1272-
{
1273-
body: { state: 'closed' },
1274-
},
1274+
const repo = config.parentRepo ?? config.repository;
1275+
const { body: closedIssue } = await githubApi.patchJson(
1276+
`repos/${repo}/issues/${issueNumber}`,
1277+
{ body: { state: 'closed' } },
1278+
Issue,
12751279
);
1280+
GithubIssueCache.updateIssue(closedIssue);
12761281
}
12771282

12781283
export async function ensureIssue({
@@ -1319,17 +1324,18 @@ export async function ensureIssue({
13191324
await closeIssue(i.number);
13201325
}
13211326
}
1327+
13221328
const repo = config.parentRepo ?? config.repository;
1323-
const {
1324-
body: { body: issueBody },
1325-
} = await githubApi.getJson(
1329+
const { body: serverIssue } = await githubApi.getJson(
13261330
`repos/${repo}/issues/${issue.number}`,
13271331
{ cacheProvider: repoCacheProvider },
13281332
Issue,
13291333
);
1334+
GithubIssueCache.updateIssue(serverIssue);
1335+
13301336
if (
13311337
issue.title === title &&
1332-
issueBody === body &&
1338+
serverIssue.body === body &&
13331339
issue.state === 'open'
13341340
) {
13351341
logger.debug('Issue is open and up to date - nothing to do');
@@ -1341,19 +1347,18 @@ export async function ensureIssue({
13411347
if (labels) {
13421348
data.labels = labels;
13431349
}
1344-
await githubApi.patchJson(
1345-
`repos/${config.parentRepo ?? config.repository}/issues/${
1346-
issue.number
1347-
}`,
1348-
{
1349-
body: data,
1350-
},
1350+
const repo = config.parentRepo ?? config.repository;
1351+
const { body: updatedIssue } = await githubApi.patchJson(
1352+
`repos/${repo}/issues/${issue.number}`,
1353+
{ body: data },
1354+
Issue,
13511355
);
1356+
GithubIssueCache.updateIssue(updatedIssue);
13521357
logger.debug('Issue updated');
13531358
return 'updated';
13541359
}
13551360
}
1356-
await githubApi.postJson(
1361+
const { body: createdIssue } = await githubApi.postJson(
13571362
`repos/${config.parentRepo ?? config.repository}/issues`,
13581363
{
13591364
body: {
@@ -1362,10 +1367,11 @@ export async function ensureIssue({
13621367
labels: labels ?? [],
13631368
},
13641369
},
1370+
Issue,
13651371
);
13661372
logger.info('Issue created');
13671373
// reset issueList so that it will be fetched again as-needed
1368-
config.issueList = null;
1374+
GithubIssueCache.updateIssue(createdIssue);
13691375
return 'created';
13701376
} catch (err) /* istanbul ignore next */ {
13711377
if (err.body?.message?.startsWith('Issues are disabled for this repo')) {
@@ -1410,13 +1416,14 @@ async function tryAddMilestone(
14101416
},
14111417
'Adding milestone to PR',
14121418
);
1413-
const repository = config.parentRepo ?? config.repository;
14141419
try {
1415-
await githubApi.patchJson(`repos/${repository}/issues/${issueNo}`, {
1416-
body: {
1417-
milestone: milestoneNo,
1418-
},
1419-
});
1420+
const repo = config.parentRepo ?? config.repository;
1421+
const { body: updatedIssue } = await githubApi.patchJson(
1422+
`repos/${repo}/issues/${issueNo}`,
1423+
{ body: { milestone: milestoneNo } },
1424+
Issue,
1425+
);
1426+
GithubIssueCache.updateIssue(updatedIssue);
14201427
} catch (err) {
14211428
const actualError = err.response?.body || /* istanbul ignore next */ err;
14221429
logger.warn(
@@ -1436,11 +1443,12 @@ export async function addAssignees(
14361443
): Promise<void> {
14371444
logger.debug(`Adding assignees '${assignees.join(', ')}' to #${issueNo}`);
14381445
const repository = config.parentRepo ?? config.repository;
1439-
await githubApi.postJson(`repos/${repository}/issues/${issueNo}/assignees`, {
1440-
body: {
1441-
assignees,
1442-
},
1443-
});
1446+
const { body: updatedIssue } = await githubApi.postJson(
1447+
`repos/${repository}/issues/${issueNo}/assignees`,
1448+
{ body: { assignees } },
1449+
Issue,
1450+
);
1451+
GithubIssueCache.updateIssue(updatedIssue);
14441452
}
14451453

14461454
export async function addReviewers(
+247
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
import * as memCache from '../../../util/cache/memory';
2+
import { getCache, resetCache } from '../../../util/cache/repository';
3+
import { GithubIssue, GithubIssueCache } from './issue';
4+
5+
describe('modules/platform/github/issue', () => {
6+
describe('GithubIssueCache', () => {
7+
let cache = getCache();
8+
9+
beforeEach(() => {
10+
resetCache();
11+
cache = getCache();
12+
memCache.init();
13+
});
14+
15+
it('returns null for empty cache', () => {
16+
expect(GithubIssueCache.getIssues()).toBeNull();
17+
});
18+
19+
it('stores issues to the cache', () => {
20+
const issues: GithubIssue[] = [
21+
{
22+
number: 1,
23+
body: 'body-1',
24+
state: 'open',
25+
title: 'title-1',
26+
lastModified: '2020-01-01T00:00:00.000Z',
27+
},
28+
{
29+
number: 2,
30+
body: 'body-2',
31+
state: 'closed',
32+
title: 'title-2',
33+
lastModified: '2020-01-02T00:00:00.000Z',
34+
},
35+
];
36+
37+
GithubIssueCache.setIssues(issues);
38+
39+
expect(cache).toEqual({
40+
platform: {
41+
github: {
42+
issuesCache: {
43+
'1': {
44+
number: 1,
45+
body: 'body-1',
46+
state: 'open',
47+
title: 'title-1',
48+
lastModified: '2020-01-01T00:00:00.000Z',
49+
},
50+
'2': {
51+
number: 2,
52+
body: 'body-2',
53+
state: 'closed',
54+
title: 'title-2',
55+
lastModified: '2020-01-02T00:00:00.000Z',
56+
},
57+
},
58+
},
59+
},
60+
});
61+
});
62+
63+
it('returns issues from the cache in the correct order', () => {
64+
cache.platform = {
65+
github: {
66+
issuesCache: {
67+
'2': {
68+
number: 2,
69+
body: 'body-2',
70+
state: 'closed',
71+
title: 'title-2',
72+
lastModified: '2020-01-02T00:00:00.000Z',
73+
},
74+
'1': {
75+
number: 1,
76+
body: 'body-1',
77+
state: 'open',
78+
title: 'title-1',
79+
lastModified: '2020-01-01T00:00:00.000Z',
80+
},
81+
'3': {
82+
number: 3,
83+
body: 'body-3',
84+
state: 'closed',
85+
title: 'title-3',
86+
lastModified: '2020-01-03T00:00:00.000Z',
87+
},
88+
},
89+
},
90+
};
91+
92+
const res = GithubIssueCache.getIssues();
93+
94+
expect(res).toEqual([
95+
{
96+
number: 3,
97+
body: 'body-3',
98+
state: 'closed',
99+
title: 'title-3',
100+
lastModified: '2020-01-03T00:00:00.000Z',
101+
},
102+
{
103+
number: 2,
104+
body: 'body-2',
105+
state: 'closed',
106+
title: 'title-2',
107+
lastModified: '2020-01-02T00:00:00.000Z',
108+
},
109+
{
110+
number: 1,
111+
body: 'body-1',
112+
state: 'open',
113+
title: 'title-1',
114+
lastModified: '2020-01-01T00:00:00.000Z',
115+
},
116+
]);
117+
});
118+
119+
it('updates particular issue in the cache', () => {
120+
cache.platform = {
121+
github: {
122+
issuesCache: {
123+
'1': {
124+
number: 1,
125+
body: 'body-1',
126+
state: 'open',
127+
title: 'title-1',
128+
lastModified: '2020-01-01T00:00:00.000Z',
129+
},
130+
},
131+
},
132+
};
133+
134+
const issue: GithubIssue = {
135+
number: 1,
136+
body: 'new-body-1',
137+
state: 'closed',
138+
title: 'new-title-1',
139+
lastModified: '2020-01-02T00:00:00.000Z',
140+
};
141+
142+
GithubIssueCache.updateIssue(issue);
143+
144+
expect(cache).toEqual({
145+
platform: {
146+
github: {
147+
issuesCache: {
148+
'1': {
149+
number: 1,
150+
body: 'new-body-1',
151+
state: 'closed',
152+
title: 'new-title-1',
153+
lastModified: '2020-01-02T00:00:00.000Z',
154+
},
155+
},
156+
},
157+
},
158+
});
159+
});
160+
161+
it('reconciles cache', () => {
162+
cache.platform = {
163+
github: {
164+
issuesCache: {
165+
'1': {
166+
number: 1,
167+
body: 'body-1',
168+
state: 'open',
169+
title: 'title-1',
170+
lastModified: '2020-01-01T00:00:00.000Z',
171+
},
172+
'2': {
173+
number: 2,
174+
body: 'body-2',
175+
state: 'closed',
176+
title: 'title-2',
177+
lastModified: '2020-01-02T00:00:00.000Z',
178+
},
179+
},
180+
},
181+
};
182+
183+
GithubIssueCache.addIssuesToReconcile([
184+
{
185+
number: 1,
186+
body: 'new-body-1',
187+
state: 'open',
188+
title: 'new-title-1',
189+
lastModified: '2020-01-04T00:00:00.000Z',
190+
},
191+
{
192+
number: 2,
193+
body: 'body-2',
194+
state: 'closed',
195+
title: 'title-2',
196+
lastModified: '2020-01-02T00:00:00.000Z',
197+
},
198+
]);
199+
const res = GithubIssueCache.getIssues();
200+
201+
expect(res).toEqual([
202+
{
203+
number: 1,
204+
body: 'new-body-1',
205+
state: 'open',
206+
title: 'new-title-1',
207+
lastModified: '2020-01-04T00:00:00.000Z',
208+
},
209+
{
210+
number: 2,
211+
body: 'body-2',
212+
state: 'closed',
213+
title: 'title-2',
214+
lastModified: '2020-01-02T00:00:00.000Z',
215+
},
216+
]);
217+
});
218+
219+
it('resets cache during failed reconciliation', () => {
220+
cache.platform = {
221+
github: {
222+
issuesCache: {
223+
'1': {
224+
number: 1,
225+
body: 'body-1',
226+
state: 'open',
227+
title: 'title-1',
228+
lastModified: '2020-01-01T00:00:00.000Z',
229+
},
230+
'2': {
231+
number: 2,
232+
body: 'body-2',
233+
state: 'closed',
234+
title: 'title-2',
235+
lastModified: '2020-01-02T00:00:00.000Z',
236+
},
237+
},
238+
},
239+
};
240+
241+
GithubIssueCache.addIssuesToReconcile([]);
242+
const res = GithubIssueCache.getIssues();
243+
244+
expect(res).toBeNull();
245+
});
246+
});
247+
});

‎lib/modules/platform/github/issue.ts

+114-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { DateTime } from 'luxon';
12
import { z } from 'zod';
2-
import type { GithubIssue as Issue } from './types';
3+
import { logger } from '../../../logger';
4+
import * as memCache from '../../../util/cache/memory';
5+
import { getCache } from '../../../util/cache/repository';
36

47
const GithubIssueBase = z.object({
58
number: z.number(),
@@ -10,19 +13,127 @@ const GithubIssueBase = z.object({
1013

1114
const GithubGraphqlIssue = GithubIssueBase.extend({
1215
updatedAt: z.string(),
13-
}).transform((issue): Issue => {
16+
}).transform((issue) => {
1417
const lastModified = issue.updatedAt;
1518
const { number, state, title, body } = issue;
1619
return { number, state, title, body, lastModified };
1720
});
1821

1922
const GithubRestIssue = GithubIssueBase.extend({
2023
updated_at: z.string(),
21-
}).transform((issue): Issue => {
24+
}).transform((issue) => {
2225
const lastModified = issue.updated_at;
2326
const { number, state, title, body } = issue;
2427
return { number, state, title, body, lastModified };
2528
});
2629

2730
export const GithubIssue = z.union([GithubGraphqlIssue, GithubRestIssue]);
2831
export type GithubIssue = z.infer<typeof GithubIssue>;
32+
33+
type CacheData = Record<number, GithubIssue>;
34+
35+
export class GithubIssueCache {
36+
private static reset(cacheData: CacheData | null): void {
37+
memCache.set('github-issues-reconcile-queue', null);
38+
const repoCache = getCache();
39+
repoCache.platform ??= {};
40+
repoCache.platform.github ??= {};
41+
if (cacheData) {
42+
repoCache.platform.github.issuesCache = cacheData;
43+
} else {
44+
delete repoCache.platform.github.issuesCache;
45+
}
46+
}
47+
48+
private static get data(): CacheData | null {
49+
let cacheData: CacheData | undefined | null = getCache().platform?.github
50+
?.issuesCache as CacheData | undefined;
51+
if (!cacheData) {
52+
return null;
53+
}
54+
55+
cacheData = this.reconcile(cacheData);
56+
return cacheData;
57+
}
58+
59+
static getIssues(): GithubIssue[] | null {
60+
const cacheData = this.data;
61+
if (!cacheData) {
62+
return null;
63+
}
64+
65+
const sortedResult = Object.values(cacheData).sort(
66+
({ lastModified: a }, { lastModified: b }) =>
67+
DateTime.fromISO(b).toMillis() - DateTime.fromISO(a).toMillis(),
68+
);
69+
70+
return sortedResult;
71+
}
72+
73+
static setIssues(issues: GithubIssue[]): void {
74+
const cacheData: CacheData = {};
75+
for (const issue of issues) {
76+
cacheData[issue.number] = issue;
77+
}
78+
this.reset(cacheData);
79+
}
80+
81+
static updateIssue(issue: GithubIssue): void {
82+
const cacheData = this.data;
83+
if (cacheData) {
84+
cacheData[issue.number] = issue;
85+
}
86+
}
87+
88+
/**
89+
* At the moment of repo initialization, repository cache is not available.
90+
* What we can do is to store issues for later reconciliation.
91+
*/
92+
static addIssuesToReconcile(issues: GithubIssue[] | undefined): void {
93+
memCache.set('github-issues-reconcile-queue', issues);
94+
}
95+
96+
private static reconcile(cacheData: CacheData): CacheData | null {
97+
const issuesToReconcile = memCache.get<GithubIssue[]>(
98+
'github-issues-reconcile-queue',
99+
);
100+
if (!issuesToReconcile) {
101+
return cacheData;
102+
}
103+
104+
let isReconciled = false;
105+
106+
for (const issue of issuesToReconcile) {
107+
const cachedIssue = cacheData[issue.number];
108+
109+
// If we reached the item which is already in the cache,
110+
// it means sync is done.
111+
if (
112+
cachedIssue &&
113+
cachedIssue.number === issue.number &&
114+
cachedIssue.lastModified === issue.lastModified
115+
) {
116+
isReconciled = true;
117+
break;
118+
}
119+
120+
cacheData[issue.number] = issue;
121+
}
122+
123+
// If we've just iterated over all the items in the cache,
124+
// it means sync is also done.
125+
if (issuesToReconcile.length >= Object.keys(cacheData).length) {
126+
isReconciled = true;
127+
}
128+
129+
if (!isReconciled) {
130+
logger.debug('Issues cache: reset');
131+
this.reset(null);
132+
return null;
133+
}
134+
135+
logger.debug('Issues cache: synced');
136+
this.reset(cacheData);
137+
return cacheData;
138+
}
139+
}

‎lib/modules/platform/github/types.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export interface LocalRepoConfig {
9797
forkToken?: string;
9898
forkCreation?: boolean;
9999
prList: GhPr[] | null;
100-
issueList: GithubIssue[] | null;
101100
mergeMethod: 'rebase' | 'squash' | 'merge';
102101
defaultBranch: string;
103102
repositoryOwner: string;
@@ -133,6 +132,7 @@ export interface GhRepo {
133132
oid: string;
134133
};
135134
};
135+
issues: { nodes: unknown[] };
136136
}
137137

138138
export interface GhAutomergeResponse {
@@ -153,11 +153,3 @@ export interface ApiPageCache<T extends ApiPageItem = ApiPageItem> {
153153
items: Record<number, T>;
154154
lastModified?: string;
155155
}
156-
157-
export interface GithubIssue {
158-
body: string;
159-
number: number;
160-
state: string;
161-
title: string;
162-
lastModified: string;
163-
}

‎lib/util/cache/repository/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface RepoCacheData {
140140
*/
141141
pullRequestsCache?: unknown;
142142
graphqlPageCache?: unknown;
143+
issuesCache?: Record<number, unknown>;
143144
};
144145
bitbucket?: {
145146
pullRequestsCache?: unknown;

0 commit comments

Comments
 (0)
Please sign in to comment.