Skip to content

Commit 3f59afb

Browse files
authored
marking all return types as optional (#6442)
1 parent ba1657a commit 3f59afb

4 files changed

Lines changed: 44 additions & 32 deletions

File tree

src/lm/tools/fetchIssueTool.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,42 @@ import { PullRequestModel } from '../../github/pullRequestModel';
1010
import { RepoToolBase } from './toolsUtils';
1111

1212
interface FetchIssueToolParameters {
13-
issueNumber: number;
13+
issueNumber?: number;
1414
repo?: {
15-
owner: string;
16-
name: string;
15+
owner?: string;
16+
name?: string;
1717
};
1818
}
1919

2020
interface FileChange {
21-
fileName: string;
22-
patch: string;
21+
fileName?: string;
22+
patch?: string;
2323
}
2424

2525
export interface FetchIssueResult {
26-
title: string;
27-
body: string;
28-
comments: {
29-
author: string;
30-
body: string;
26+
title?: string;
27+
body?: string;
28+
comments?: {
29+
author?: string;
30+
body?: string;
3131
}[];
32-
owner: string;
33-
repo: string;
32+
owner?: string;
33+
repo?: string;
3434
fileChanges?: FileChange[];
3535
}
3636

3737
export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
3838
public static readonly toolId = 'github-pull-request_issue_fetch';
3939

4040
async invoke(options: vscode.LanguageModelToolInvocationOptions<FetchIssueToolParameters>, _token: vscode.CancellationToken): Promise<vscode.LanguageModelToolResult> {
41+
const issueNumber = options.input.issueNumber;
42+
if (!issueNumber) {
43+
throw new Error('No issue/PR number provided.');
44+
}
4145
const { owner, name, folderManager } = await this.getRepoInfo({ owner: options.input.repo?.owner, name: options.input.repo?.name });
42-
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, options.input.issueNumber);
46+
const issueOrPullRequest = await folderManager.resolveIssueOrPullRequest(owner, name, issueNumber);
4347
if (!issueOrPullRequest) {
44-
throw new Error(`No issue or PR found for ${owner}/${name}/${options.input.issueNumber}. Make sure the issue or PR exists.`);
48+
throw new Error(`No issue or PR found for ${owner}/${name}/${issueNumber}. Make sure the issue or PR exists.`);
4549
}
4650
const result: FetchIssueResult = {
4751
owner,
@@ -79,6 +83,5 @@ export class FetchIssueTool extends RepoToolBase<FetchIssueToolParameters> {
7983
return {
8084
invocationMessage: url ? vscode.l10n.t('Fetching item [#{0}]({1}) from GitHub', options.input.issueNumber, url) : vscode.l10n.t('Fetching item #{0} from GitHub', options.input.issueNumber),
8185
};
82-
8386
}
8487
}

src/lm/tools/fetchNotificationTool.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ import { getNotificationKey } from '../../github/utils';
1111
import { RepoToolBase } from './toolsUtils';
1212

1313
interface FetchNotificationToolParameters {
14-
thread_id: number;
14+
thread_id?: number;
1515
}
1616

1717
interface FileChange {
18-
fileName: string;
19-
patch: string;
18+
fileName?: string;
19+
patch?: string;
2020
}
2121

2222
export interface FetchNotificationResult {
2323
lastReadAt?: string;
24-
lastUpdatedAt: string;
25-
unread: boolean;
26-
title: string;
27-
body: string;
24+
lastUpdatedAt?: string;
25+
unread?: boolean;
26+
title?: string;
27+
body?: string;
2828
comments?: {
29-
author: string;
30-
body: string;
29+
author?: string;
30+
body?: string;
3131
}[];
32-
owner: string;
33-
repo: string;
32+
owner?: string;
33+
repo?: string;
3434
itemNumber?: string;
3535
itemType?: 'issue' | 'pr';
3636
fileChanges?: FileChange[];
@@ -53,6 +53,9 @@ export class FetchNotificationTool extends RepoToolBase<FetchNotificationToolPar
5353
return undefined;
5454
}
5555
const threadId = options.input.thread_id;
56+
if (threadId === undefined) {
57+
return undefined;
58+
}
5659
const thread = await github.octokit.api.activity.getThread({
5760
thread_id: threadId
5861
});

src/lm/tools/summarizeIssueTool.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ Patch: ${fileChange.patch}
4242
}
4343
}
4444
const comments = options.input.comments;
45-
for (const [index, comment] of comments.entries()) {
46-
issueOrPullRequestInfo += `
45+
if (comments) {
46+
for (const [index, comment] of comments.entries()) {
47+
issueOrPullRequestInfo += `
4748
Comment ${index} :
4849
Author: ${comment.author}
4950
Body: ${comment.body}
5051
`;
52+
}
5153
}
5254
const models = await vscode.lm.selectChatModels({
5355
vendor: 'copilot',
5456
family: 'gpt-4o'
5557
});
5658
const model = models[0];
59+
const repo = options.input.repo;
60+
const owner = options.input.owner;
5761

58-
if (model) {
59-
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.input.repo, options.input.owner))];
62+
if (model && repo && owner) {
63+
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(repo, owner))];
6064
messages.push(vscode.LanguageModelChatMessage.User(`The issue or pull request information is as follows:`));
6165
messages.push(vscode.LanguageModelChatMessage.User(issueOrPullRequestInfo));
6266
const response = await model.sendRequest(messages, {});

src/lm/tools/summarizeNotificationsTool.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ Body: ${comment.body}
7979
content.push(new vscode.LanguageModelTextPart(TOOL_COMMAND_RESULT));
8080
content.push(new vscode.LanguageModelTextPart(JSON.stringify(markAsReadCommand)));
8181
}
82-
if (model) {
83-
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(options.input.owner, options.input.repo))];
82+
const owner = options.input.owner;
83+
const repo = options.input.repo;
84+
if (model && owner && repo) {
85+
const messages = [vscode.LanguageModelChatMessage.User(this.summarizeInstructions(owner, repo))];
8486
messages.push(vscode.LanguageModelChatMessage.User(`The notification information is as follows:`));
8587
messages.push(vscode.LanguageModelChatMessage.User(notificationInfo));
8688
const response = await model.sendRequest(messages, {});

0 commit comments

Comments
 (0)