Skip to content

Commit 79431e4

Browse files
alexr00Copilot
andcommitted
CCR feedback for #8674
Co-authored-by: Copilot <copilot@github.com>
1 parent c9a03e5 commit 79431e4

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

src/view/reviewManager.ts

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export class ReviewManager extends Disposable {
7777
*/
7878
private _cachedMaxPRNumbers: Map<string, number> | undefined;
7979
private _cachedBranchName: string | undefined;
80+
private _pollHandle: NodeJS.Timeout | undefined;
8081
/**
8182
* Flag set when the "Checkout" action is used and cleared on the next git
8283
* state update, once review mode has been entered. Used to disambiguate
@@ -136,6 +137,12 @@ export class ReviewManager extends Disposable {
136137
this.updateState(true);
137138
}
138139
this.pollForStateChange();
140+
this._register(toDisposable(() => {
141+
if (this._pollHandle) {
142+
clearTimeout(this._pollHandle);
143+
this._pollHandle = undefined;
144+
}
145+
}));
139146
}
140147

141148
private registerListeners(): void {
@@ -214,12 +221,22 @@ export class ReviewManager extends Disposable {
214221
}
215222

216223
private pollForStateChange() {
217-
setTimeout(async () => {
224+
this._pollHandle = setTimeout(async () => {
225+
if (this.isDisposed) {
226+
return;
227+
}
218228
Logger.appendLine('Polling for state change...', this.id);
219-
if (!this._validateStatusInProgress && !this._folderRepoManager.activePullRequest) {
220-
await this.updateState();
229+
try {
230+
if (!this._validateStatusInProgress && !this._folderRepoManager.activePullRequest) {
231+
await this.updateState();
232+
}
233+
} catch (e) {
234+
Logger.warn(`Polling for state change failed: ${e}`, this.id);
235+
} finally {
236+
if (!this.isDisposed) {
237+
this.pollForStateChange();
238+
}
221239
}
222-
this.pollForStateChange();
223240
}, 1000 * 60 * 5);
224241
}
225242

@@ -436,21 +453,26 @@ export class ReviewManager extends Disposable {
436453
if (!headRepo) {
437454
return [];
438455
}
439-
const metadata = await headRepo.getMetadata();
440-
if (!metadata?.owner) {
456+
try {
457+
const metadata = await headRepo.getMetadata();
458+
if (!metadata?.owner) {
459+
return [headRepo];
460+
}
461+
const parentRepos = this._folderRepoManager.gitHubRepositories.filter(repo => {
462+
if (metadata.fork) {
463+
return repo.remote.owner === metadata.parent?.owner?.login && repo.remote.repositoryName === metadata.parent?.name;
464+
} else {
465+
return repo.remote.owner === metadata.owner?.login && repo.remote.repositoryName === metadata.name;
466+
}
467+
});
468+
// Include both head and parent repos, deduplicated
469+
const result = new Set<GitHubRepository>(parentRepos);
470+
result.add(headRepo);
471+
return [...result];
472+
} catch (e) {
473+
Logger.warn(`Failed to get metadata for relevant repos: ${e}`, this.id);
441474
return [headRepo];
442475
}
443-
const parentRepos = this._folderRepoManager.gitHubRepositories.filter(repo => {
444-
if (metadata.fork) {
445-
return repo.remote.owner === metadata.parent?.owner?.login && repo.remote.repositoryName === metadata.parent?.name;
446-
} else {
447-
return repo.remote.owner === metadata.owner?.login && repo.remote.repositoryName === metadata.name;
448-
}
449-
});
450-
// Include both head and parent repos, deduplicated
451-
const result = new Set<GitHubRepository>(parentRepos);
452-
result.add(headRepo);
453-
return [...result];
454476
}
455477

456478
private async getMaxPullRequestNumbers(): Promise<Map<string, number>> {
@@ -471,6 +493,11 @@ export class ReviewManager extends Disposable {
471493
return true;
472494
}
473495
const current = await this.getMaxPullRequestNumbers();
496+
// If we couldn't determine max PR for any repo, assume there may be new PRs
497+
if (current.size === 0) {
498+
this._cachedMaxPRNumbers = current;
499+
return true;
500+
}
474501
let result = false;
475502
for (const [key, value] of current) {
476503
const cached = this._cachedMaxPRNumbers.get(key);
@@ -546,9 +573,6 @@ export class ReviewManager extends Disposable {
546573
await this.clear(true);
547574
return;
548575
}
549-
if (!this._cachedMaxPRNumbers) {
550-
this._cachedMaxPRNumbers = await this.getMaxPullRequestNumbers();
551-
}
552576

553577
const branch = this._repository.state.HEAD;
554578
const ignoreBranches = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<string[]>(IGNORE_PR_BRANCHES);

0 commit comments

Comments
 (0)