Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRs do not refresh after changing account preferences in dropdown #6255

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ async function deferredActivate(context: vscode.ExtensionContext, apiImpl: GitAp

const prTree = new PullRequestsTreeDataProvider(telemetry, context, reposManager);
context.subscriptions.push(prTree);
context.subscriptions.push(credentialStore.onDidGetSession(() => prTree.refresh(undefined, true)));
Logger.appendLine('Looking for git repository');
const repositories = apiImpl.repositories;
Logger.appendLine(`Found ${repositories.length} repositories during activation`);
Expand Down
51 changes: 34 additions & 17 deletions src/github/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,42 @@ export class CredentialStore implements vscode.Disposable {
this.setScopesFromState();

this._disposables = [];
this._disposables.push(
vscode.authentication.onDidChangeSessions(async e => {
const promises: Promise<any>[] = [];
if (!this.isAuthenticated(AuthProvider.github)) {
promises.push(this.initialize(AuthProvider.github));
}
this._disposables.push(vscode.authentication.onDidChangeSessions((e) => this.handlOnDidChangeSessions(e)));
}

if (!this.isAuthenticated(AuthProvider.githubEnterprise) && hasEnterpriseUri()) {
promises.push(this.initialize(AuthProvider.githubEnterprise));
}
private async handlOnDidChangeSessions(e: vscode.AuthenticationSessionsChangeEvent) {
const currentProvider = (e.provider.id === AuthProvider.github && this._githubAPI) ? AuthProvider.github : ((e.provider.id === AuthProvider.githubEnterprise && this._githubEnterpriseAPI) ? AuthProvider.githubEnterprise : undefined);
if ((this._githubAPI || this._githubEnterpriseAPI) && !currentProvider) {
return;
}
if (currentProvider) {
const newSession = await this.getSession(currentProvider, { silent: true }, currentProvider === AuthProvider.github ? this._scopes : this._scopesEnterprise, true);
if (newSession.session?.id === this._sessionId) {
return;
}
if (currentProvider === AuthProvider.github) {
this._githubAPI = undefined;
this._sessionId = undefined;
} else {
this._githubEnterpriseAPI = undefined;
this._enterpriseSessionId = undefined;
}
}
const promises: Promise<any>[] = [];
if (!this.isAuthenticated(AuthProvider.github)) {
promises.push(this.initialize(AuthProvider.github));
}

await Promise.all(promises);
if (this.isAnyAuthenticated()) {
this._onDidGetSession.fire();
} else if (!this._isSamling) {
this._onDidChangeSessions.fire(e);
}
}),
);
if (!this.isAuthenticated(AuthProvider.githubEnterprise) && hasEnterpriseUri()) {
promises.push(this.initialize(AuthProvider.githubEnterprise));
}

await Promise.all(promises);
if (this.isAnyAuthenticated()) {
this._onDidGetSession.fire();
} else if (!this._isSamling) {
this._onDidChangeSessions.fire(e);
}
}

private allScopesIncluded(actualScopes: string[], requiredScopes: string[]) {
Expand Down
8 changes: 5 additions & 3 deletions src/view/prsTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
this._disposables.push(vscode.window.registerFileDecorationProvider(DecorationProvider));
this._disposables.push(
vscode.commands.registerCommand('pr.refreshList', _ => {
this.prsTreeModel.clearCache();
this._onDidChangeTreeData.fire();
this.refresh(undefined, true);
}),
);

Expand Down Expand Up @@ -174,7 +173,10 @@ export class PullRequestsTreeDataProvider implements vscode.TreeDataProvider<Tre
);
}

refresh(node?: TreeNode): void {
refresh(node?: TreeNode, reset?: boolean): void {
if (reset) {
this.prsTreeModel.clearCache();
}
return node ? this._onDidChangeTreeData.fire(node) : this._onDidChangeTreeData.fire();
}

Expand Down