Skip to content

Commit b8fadeb

Browse files
authored
Extension should still work if only upstream requires SAML (microsoft#6414)
Fixes microsoft#6159
1 parent c0fb8d0 commit b8fadeb

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/github/folderRepositoryManager.ts

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ export class FolderRepositoryManager implements vscode.Disposable {
214214
private _onDidDispose = new vscode.EventEmitter<void>();
215215
readonly onDidDispose: vscode.Event<void> = this._onDidDispose.event;
216216

217+
private _sessionIgnoredRemoteNames: Set<string> = new Set();
218+
217219
constructor(
218220
private _id: number,
219221
public context: vscode.ExtensionContext,
@@ -330,7 +332,7 @@ export class FolderRepositoryManager implements vscode.Disposable {
330332

331333
return remotesSetting
332334
.map(remote => allGitHubRemotes.find(repo => repo.remoteName === remote))
333-
.filter((repo: GitHubRemote | undefined): repo is GitHubRemote => !!repo);
335+
.filter((repo: GitHubRemote | undefined): repo is GitHubRemote => !!repo && !this._sessionIgnoredRemoteNames.has(repo.remoteName));
334336
}
335337

336338
get activeIssue(): IssueModel | undefined {
@@ -485,6 +487,17 @@ export class FolderRepositoryManager implements vscode.Disposable {
485487
repositories.push(repository);
486488
}
487489

490+
const cleanUpMissingSaml = async (missingSaml: GitHubRepository[]) => {
491+
for (const missing of missingSaml) {
492+
this._sessionIgnoredRemoteNames.add(missing.remote.remoteName);
493+
this.removeGitHubRepository(missing.remote);
494+
const index = repositories.indexOf(missing);
495+
if (index > -1) {
496+
repositories.splice(index, 1);
497+
}
498+
}
499+
};
500+
488501
return Promise.all(resolveRemotePromises).then(async (remoteResults: boolean[]) => {
489502
const missingSaml: GitHubRepository[] = [];
490503
for (let i = 0; i < remoteResults.length; i++) {
@@ -494,18 +507,18 @@ export class FolderRepositoryManager implements vscode.Disposable {
494507
}
495508
if (missingSaml.length > 0) {
496509
const result = await this._credentialStore.showSamlMessageAndAuth(missingSaml.map(repo => repo.remote.owner));
497-
if (result.canceled) {
498-
this.dispose();
499-
return true;
500-
} else {
501-
// Make a test call to see if the user has SAML enabled.
502-
const samlTest = await Promise.all(missingSaml.map(repo => repo.resolveRemote()));
503-
504-
if (samlTest.some(result => !result)) {
510+
// Make a test call to see if the user has SAML enabled.
511+
const samlTest = result.canceled ? [] : await Promise.all(missingSaml.map(repo => repo.resolveRemote()));
512+
const stillMissing = result.canceled ? missingSaml : samlTest.map((result, index) => !result ? missingSaml[index] : undefined).filter((repo): repo is GitHubRepository => !!repo);
513+
// Make a test call to see if the user has SAML enabled.
514+
if (stillMissing.length > 0) {
515+
if (stillMissing.length === repositories.length) {
505516
await vscode.window.showErrorMessage(vscode.l10n.t('SAML access was not provided. GitHub Pull Requests will not work.'), { modal: true });
506517
this.dispose();
507518
return true;
508519
}
520+
await vscode.window.showErrorMessage(vscode.l10n.t('SAML access was not provided. Some GitHub repositories will not be available.'), { modal: true });
521+
cleanUpMissingSaml(stillMissing);
509522
}
510523
}
511524

@@ -2470,6 +2483,18 @@ export class FolderRepositoryManager implements vscode.Disposable {
24702483
return repo;
24712484
}
24722485

2486+
private removeGitHubRepository(remote: Remote) {
2487+
const index = this._githubRepositories.findIndex(
2488+
r =>
2489+
(r.remote.owner.toLowerCase() === remote.owner.toLowerCase())
2490+
&& (r.remote.repositoryName.toLowerCase() === remote.repositoryName.toLowerCase())
2491+
&& (!remote.remoteName || (r.remote.remoteName === remote.remoteName))
2492+
);
2493+
if (index > -1) {
2494+
this._githubRepositories.splice(index, 1);
2495+
}
2496+
}
2497+
24732498
private _createGitHubRepositoryBulkhead = bulkhead(1, 300);
24742499
async createGitHubRepository(remote: Remote, credentialStore: CredentialStore, silent?: boolean, ignoreRemoteName: boolean = false): Promise<GitHubRepository> {
24752500
// Use a bulkhead/semaphore to ensure that we don't create multiple GitHubRepositories for the same remote at the same time.

0 commit comments

Comments
 (0)