Skip to content

Commit e307250

Browse files
authored
Try to protect against mysteriously undefined values in update time check (#8509)
* Try to protect against mysteriously undefined values in update time check * Copilot PR feedback
1 parent b47069a commit e307250

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/github/graphql.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,28 +294,28 @@ export interface LatestCommit {
294294

295295
export interface LatestReviewThread {
296296
comments: {
297-
nodes: {
297+
nodes: ({
298298
createdAt: string;
299-
}[];
299+
} | null)[];
300300
}
301301
}
302302

303303
export interface LatestUpdatesResponse {
304304
repository: {
305305
pullRequest: {
306306
reactions: {
307-
nodes: {
307+
nodes: ({
308308
createdAt: string;
309-
}[];
309+
} | null)[];
310310
}
311311
updatedAt: string;
312312
comments: {
313313
nodes: {
314314
updatedAt: string;
315315
reactions: {
316-
nodes: {
316+
nodes: ({
317317
createdAt: string;
318-
}[];
318+
} | null)[];
319319
}
320320
}[];
321321
}

src/github/issueModel.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,25 @@ export class IssueModel<TItem extends Issue = Issue> extends Disposable {
446446
const times = [
447447
time,
448448
new Date(data.repository.pullRequest.updatedAt),
449-
...(data.repository.pullRequest.reactions.nodes.map(node => new Date(node.createdAt))),
449+
...(data.repository.pullRequest.reactions.nodes.filter((node): node is { createdAt: string } => !!node).map(node => new Date(node.createdAt))),
450450
...(data.repository.pullRequest.comments.nodes.map(node => new Date(node.updatedAt))),
451-
...(data.repository.pullRequest.comments.nodes.flatMap(node => node.reactions.nodes.map(reaction => new Date(reaction.createdAt)))),
451+
...(data.repository.pullRequest.comments.nodes.flatMap(node => node.reactions.nodes.filter((reaction): reaction is { createdAt: string } => !!reaction).map(reaction => new Date(reaction.createdAt)))),
452452
...(data.repository.pullRequest.timelineItems.nodes.map(node => {
453453
const latestCommit = node as (Partial<LatestCommit> | null);
454454
if (latestCommit?.commit?.committedDate) {
455455
return new Date(latestCommit.commit.committedDate);
456456
}
457457
const latestReviewThread = node as (Partial<LatestReviewThread> | null);
458-
if ((latestReviewThread?.comments?.nodes.length ?? 0) > 0) {
458+
if (((latestReviewThread?.comments?.nodes.length ?? 0) > 0) && latestReviewThread!.comments!.nodes[0]) {
459459
return new Date(latestReviewThread!.comments!.nodes[0].createdAt);
460+
} else if (node) {
461+
return new Date((node as { createdAt: string }).createdAt);
460462
}
461-
return new Date((node as { createdAt: string }).createdAt);
462463
}))
463464
];
464465

465466
// Sort times and return the most recent one
466-
return new Date(Math.max(...times.map(t => t.getTime())));
467+
return new Date(Math.max(...times.filter((t): t is Date => !!t).map(t => t.getTime())));
467468
} catch (e) {
468469
Logger.error(`Error fetching timeline events of issue #${this.number} - ${formatError(e)}`, IssueModel.ID);
469470
return time; // Return the original time in case of an error

0 commit comments

Comments
 (0)