Skip to content
This repository was archived by the owner on Nov 14, 2025. It is now read-only.

Commit 5eeaff4

Browse files
authored
Add null checks for issue retrieval in various components (#336)
1 parent f7c2535 commit 5eeaff4

File tree

39 files changed

+158
-40
lines changed

39 files changed

+158
-40
lines changed

api/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface GitHub {
3131
}
3232

3333
export interface GitHubIssue extends GitHub {
34-
getIssue(): Promise<Issue>;
34+
getIssue(): Promise<Issue | undefined>;
3535

3636
postComment(body: string): Promise<void>;
3737
deleteComment(id: number): Promise<void>;

api/octokit.js

Lines changed: 25 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/octokit.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -326,21 +326,30 @@ export class OctoKitIssue extends OctoKit implements GitHubIssue {
326326
await this.octokit.rest.issues.unlock({ ...this.params, issue_number: this.issueData.number });
327327
}
328328

329-
async getIssue(): Promise<Issue> {
329+
async getIssue(): Promise<Issue | undefined> {
330330
if (isIssue(this.issueData)) {
331331
safeLog('Got issue data from query result ' + this.issueData.number);
332332
return this.issueData;
333333
}
334334

335335
safeLog('Fetching issue ' + this.issueData.number);
336-
const issue = (
337-
await this.octokit.rest.issues.get({
338-
...this.params,
339-
issue_number: this.issueData.number,
340-
mediaType: { previews: ['squirrel-girl'] },
341-
})
342-
).data;
343-
return (this.issueData = this.octokitIssueToIssue(issue));
336+
try {
337+
const issue = (
338+
await this.octokit.rest.issues.get({
339+
...this.params,
340+
issue_number: this.issueData.number,
341+
mediaType: { previews: ['squirrel-girl'] },
342+
})
343+
).data;
344+
return (this.issueData = this.octokitIssueToIssue(issue));
345+
} catch (err) {
346+
const statusError = err as RequestError;
347+
if (statusError.status === 404) {
348+
safeLog('Issue not found');
349+
return;
350+
}
351+
throw err;
352+
}
344353
}
345354

346355
async postComment(body: string): Promise<void> {
@@ -380,7 +389,7 @@ export class OctoKitIssue extends OctoKit implements GitHubIssue {
380389
...this.params,
381390
issue_number: this.issueData.number,
382391
per_page: 100,
383-
...(last ? { per_page: 1, page: (await this.getIssue()).numComments } : {}),
392+
...(last ? { per_page: 1, page: (await this.getIssue())?.numComments } : {}),
384393
});
385394

386395
for await (const page of response) {
@@ -465,7 +474,7 @@ export class OctoKitIssue extends OctoKit implements GitHubIssue {
465474
}
466475
alreadyChecked.push(this.issueData.number);
467476

468-
if ((await this.getIssue()).open) {
477+
if ((await this.getIssue())?.open) {
469478
return;
470479
}
471480

@@ -534,7 +543,7 @@ export class OctoKitIssue extends OctoKit implements GitHubIssue {
534543
}).getClosingInfo(alreadyChecked);
535544

536545
if (closed) {
537-
if (Math.abs(closed.timestamp - ((await this.getIssue()).closedAt ?? 0)) < 5000) {
546+
if (Math.abs(closed.timestamp - ((await this.getIssue())?.closedAt ?? 0)) < 5000) {
538547
closingCommit = closed;
539548
break;
540549
}

author-verified/AuthorVerified.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

author-verified/AuthorVerified.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class AuthorVerifiedLabeler {
3333

3434
async run(): Promise<void> {
3535
const issue = await this.github.getIssue();
36+
if (!issue) return;
3637

3738
if (
3839
!issue.open &&

classifier-deep/apply/apply-labels/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classifier-deep/apply/apply-labels/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ApplyLabels extends Action {
6060
};
6161

6262
const issueData = await issue.getIssue();
63+
if (!issueData) continue;
6364

6465
if (issueData.labels.includes('invalid')) {
6566
safeLog(`issue ${labeling.number} is invalid, skipping`);

classifier-deep/apply/fetch-sources/index.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

classifier-deep/apply/fetch-sources/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class FetchIssues extends Action {
3636
for await (const page of github.query({ q: query })) {
3737
for (const issue of page) {
3838
const issueData = await issue.getIssue();
39+
if (!issueData) continue;
3940

4041
// Probably spam. Tagged for later review
4142
if (issueData.author.name === 'ghost') {
@@ -65,6 +66,8 @@ class FetchIssues extends Action {
6566
const linkedIssueData = await github
6667
.getIssueByNumber(+linkedIssue)
6768
.getIssue();
69+
if (!linkedIssueData) continue;
70+
6871
const normalized = normalizeIssue(linkedIssueData);
6972
additionalInfo = `\n\n${normalized.title}\n\n${normalized.body}`;
7073
const linkedIssueAssignee = linkedIssueData.assignees[0];

classifier/apply/apply-labels/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)