Skip to content

Commit 32d7548

Browse files
Copilotalexr00
andcommitted
Code review fixes: use makeKey, existing getNotificationsCount method, and repo getter
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 26cc215 commit 32d7548

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

src/commands.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -919,9 +919,8 @@ export function registerCommands(
919919

920920
context.subscriptions.push(
921921
vscode.commands.registerCommand('pr.markAllCopilotNotificationsAsRead', node => {
922-
if (node instanceof CategoryTreeNode && node.isCopilot && node.folderRepoManager.gitHubRepositories.length > 0) {
923-
const repo = node.folderRepoManager.gitHubRepositories[0];
924-
copilotRemoteAgentManager.clearAllNotifications(repo.remote.owner, repo.remote.repositoryName);
922+
if (node instanceof CategoryTreeNode && node.isCopilot && node.repo) {
923+
copilotRemoteAgentManager.clearAllNotifications(node.repo.owner, node.repo.repositoryName);
925924
tree.refresh(node);
926925
}
927926
}),

src/github/copilotPrWatcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ export class CopilotStateModel extends Disposable {
114114
// If owner and repo are specified, only clear notifications for that repo
115115
if (owner && repo) {
116116
const keysToRemove: string[] = [];
117+
const prefix = `${this.makeKey(owner, repo)}#`;
117118
for (const key of this._showNotification.keys()) {
118-
if (key.startsWith(`${owner}/${repo}#`)) {
119+
if (key.startsWith(prefix)) {
119120
const item = this._states.get(key)?.item;
120121
if (item) {
121122
items.push(item);

src/github/copilotRemoteAgent.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -880,14 +880,7 @@ export class CopilotRemoteAgentManager extends Disposable {
880880
}
881881

882882
getNotificationsCountForRepo(owner: string, repo: string): number {
883-
let count = 0;
884-
const prefix = `${owner}/${repo}#`;
885-
for (const key of this._stateModel.notifications.keys()) {
886-
if (key.startsWith(prefix)) {
887-
count++;
888-
}
889-
}
890-
return count;
883+
return this._stateModel.getNotificationsCount(owner, repo);
891884
}
892885

893886
public clearAllNotifications(owner?: string, repo?: string): void {

src/view/treeNodes/categoryNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ export class CategoryTreeNode extends TreeNode implements vscode.TreeItem {
195195
}
196196
}
197197

198+
get repo(): RemoteInfo | undefined {
199+
return this._repo;
200+
}
201+
198202
private _getDescription(): string | undefined {
199203
if (!this.isCopilot || !this._repo) {
200204
return undefined;

0 commit comments

Comments
 (0)