Skip to content

Commit 58991fd

Browse files
Moves integration auth service and removes from GitHub git provider
1 parent f332ba7 commit 58991fd

File tree

13 files changed

+221
-241
lines changed

13 files changed

+221
-241
lines changed

src/container.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { ServerConnection } from './plus/gk/serverConnection';
2727
import { SubscriptionService } from './plus/gk/subscriptionService';
2828
import { GraphStatusBarController } from './plus/graph/statusbar';
2929
import type { CloudIntegrationService } from './plus/integrations/authentication/cloudIntegrationService';
30-
import { IntegrationAuthenticationService } from './plus/integrations/authentication/integrationAuthentication';
30+
import { IntegrationAuthenticationService } from './plus/integrations/authentication/integrationAuthenticationService';
3131
import { IntegrationService } from './plus/integrations/integrationService';
3232
import type { GitHubApi } from './plus/integrations/providers/github/github';
3333
import type { GitLabApi } from './plus/integrations/providers/gitlab/gitlab';
@@ -297,7 +297,7 @@ export class Container {
297297

298298
@log()
299299
private async registerGitProviders() {
300-
const providers = await getSupportedGitProviders(this, this.authenticationService);
300+
const providers = await getSupportedGitProviders(this);
301301
for (const provider of providers) {
302302
this._disposables.push(this._git.register(provider.descriptor.id, provider));
303303
}
@@ -530,18 +530,11 @@ export class Container {
530530
return this._context.extension.id;
531531
}
532532

533-
private _authenticationService: IntegrationAuthenticationService | undefined;
534-
private get authenticationService() {
535-
if (this._authenticationService == null) {
536-
this._disposables.push((this._authenticationService = new IntegrationAuthenticationService(this)));
537-
}
538-
return this._authenticationService;
539-
}
540-
541533
private _integrations: IntegrationService | undefined;
542534
get integrations(): IntegrationService {
543535
if (this._integrations == null) {
544-
this._disposables.push((this._integrations = new IntegrationService(this, this.authenticationService)));
536+
const authService = new IntegrationAuthenticationService(this);
537+
this._disposables.push(authService, (this._integrations = new IntegrationService(this, authService)));
545538
}
546539
return this._integrations;
547540
}

src/env/browser/providers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { GitCommandOptions } from '../../git/commandOptions';
33
// Force import of GitHub since dynamic imports are not supported in the WebWorker ExtensionHost
44
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
55
import { GitProvider } from '../../git/gitProvider';
6-
import type { IntegrationAuthenticationService } from '../../plus/integrations/authentication/integrationAuthentication';
76
import { GitHubGitProvider } from '../../plus/integrations/providers/github/githubGitProvider';
87
import { RepositoryWebPathMappingProvider } from './pathMapping/repositoryWebPathMappingProvider';
98
import { WorkspacesWebPathMappingProvider } from './pathMapping/workspacesWebPathMappingProvider';
@@ -22,11 +21,8 @@ export function gitLogStreamTo(
2221
return Promise.resolve([[''], 0]);
2322
}
2423

25-
export function getSupportedGitProviders(
26-
container: Container,
27-
authenticationService: IntegrationAuthenticationService,
28-
): Promise<GitProvider[]> {
29-
return Promise.resolve([new GitHubGitProvider(container, authenticationService)]);
24+
export function getSupportedGitProviders(container: Container): Promise<GitProvider[]> {
25+
return Promise.resolve([new GitHubGitProvider(container)]);
3026
}
3127

3228
export function getSupportedRepositoryPathMappingProvider(container: Container) {

src/env/node/providers.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Container } from '../../container';
22
import type { GitCommandOptions } from '../../git/commandOptions';
33
import type { GitProvider } from '../../git/gitProvider';
4-
import type { IntegrationAuthenticationService } from '../../plus/integrations/authentication/integrationAuthentication';
54
import { configuration } from '../../system/-webview/configuration';
65
// import { GitHubGitProvider } from '../../plus/github/githubGitProvider';
76
import { Git } from './git/git';
@@ -32,10 +31,7 @@ export function gitLogStreamTo(
3231
return ensureGit().logStreamTo(repoPath, sha, limit, options, ...args);
3332
}
3433

35-
export async function getSupportedGitProviders(
36-
container: Container,
37-
authenticationService: IntegrationAuthenticationService,
38-
): Promise<GitProvider[]> {
34+
export async function getSupportedGitProviders(container: Container): Promise<GitProvider[]> {
3935
const git = ensureGit();
4036

4137
const providers: GitProvider[] = [
@@ -49,7 +45,7 @@ export async function getSupportedGitProviders(
4945
await import(
5046
/* webpackChunkName: "integrations" */ '../../plus/integrations/providers/github/githubGitProvider'
5147
)
52-
).GitHubGitProvider(container, authenticationService),
48+
).GitHubGitProvider(container),
5349
);
5450
}
5551

src/plus/integrations/authentication/github.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import { wrapForForcedInsecureSSL } from '@env/fetch';
44
import { HostingIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
55
import type { Sources } from '../../../constants.telemetry';
66
import type { Container } from '../../../container';
7-
import type {
8-
IntegrationAuthenticationService,
9-
IntegrationAuthenticationSessionDescriptor,
10-
} from './integrationAuthentication';
7+
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthentication';
118
import {
129
CloudIntegrationAuthenticationProvider,
1310
LocalIntegrationAuthenticationProvider,
1411
} from './integrationAuthentication';
12+
import type { IntegrationAuthenticationService } from './integrationAuthenticationService';
1513
import type { ProviderAuthenticationSession } from './models';
1614

1715
export class GitHubAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.GitHub> {

src/plus/integrations/authentication/gitlab.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ import type { Disposable, QuickInputButton } from 'vscode';
22
import { env, ThemeIcon, Uri, window } from 'vscode';
33
import { HostingIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
44
import type { Container } from '../../../container';
5-
import type {
6-
IntegrationAuthenticationService,
7-
IntegrationAuthenticationSessionDescriptor,
8-
} from './integrationAuthentication';
5+
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthentication';
96
import {
107
CloudIntegrationAuthenticationProvider,
118
LocalIntegrationAuthenticationProvider,
129
} from './integrationAuthentication';
10+
import type { IntegrationAuthenticationService } from './integrationAuthenticationService';
1311
import type { ProviderAuthenticationSession } from './models';
1412

1513
type GitLabId = HostingIntegrationId.GitLab | SelfHostedIntegrationId.GitLabSelfHosted;

src/plus/integrations/authentication/integrationAuthentication.ts

Lines changed: 7 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
import type { CancellationToken, Disposable, Event, Uri } from 'vscode';
22
import { authentication, EventEmitter, window } from 'vscode';
33
import type { IntegrationId } from '../../../constants.integrations';
4-
import { HostingIntegrationId, IssueIntegrationId, SelfHostedIntegrationId } from '../../../constants.integrations';
5-
import type { IntegrationAuthenticationKeys, StoredConfiguredIntegrationDescriptor } from '../../../constants.storage';
4+
import { HostingIntegrationId } from '../../../constants.integrations';
5+
import type { IntegrationAuthenticationKeys } from '../../../constants.storage';
66
import type { Sources } from '../../../constants.telemetry';
77
import type { Container } from '../../../container';
8-
import { gate } from '../../../system/decorators/-webview/gate';
9-
import { debug, log } from '../../../system/decorators/log';
8+
import { debug } from '../../../system/decorators/log';
109
import type { DeferredEventExecutor } from '../../../system/event';
1110
import { getBuiltInIntegrationSession } from '../../gk/utils/-webview/integrationAuthentication.utils';
12-
import {
13-
isCloudSelfHostedIntegrationId,
14-
isSelfHostedIntegrationId,
15-
supportedIntegrationIds,
16-
} from '../providers/models';
17-
import type { ConfiguredIntegrationDescriptor, ProviderAuthenticationSession } from './models';
11+
import { isCloudSelfHostedIntegrationId, isSelfHostedIntegrationId } from '../providers/models';
12+
import type { IntegrationAuthenticationService } from './integrationAuthenticationService';
13+
import type { ProviderAuthenticationSession } from './models';
1814
import { isSupportedCloudIntegrationId } from './models';
1915

2016
const maxSmallIntegerV8 = 2 ** 30 - 1; // Max number that can be stored in V8's smis (small integers)
@@ -458,7 +454,7 @@ export abstract class CloudIntegrationAuthenticationProvider<
458454
}
459455
}
460456

461-
class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvider {
457+
export class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvider {
462458
constructor(
463459
container: Container,
464460
authenticationService: IntegrationAuthenticationService,
@@ -495,171 +491,6 @@ class BuiltInAuthenticationProvider extends LocalIntegrationAuthenticationProvid
495491
}
496492
}
497493

498-
export class IntegrationAuthenticationService implements Disposable {
499-
private readonly providers = new Map<IntegrationId, IntegrationAuthenticationProvider>();
500-
private _configured?: Map<IntegrationId, ConfiguredIntegrationDescriptor[]>;
501-
502-
constructor(private readonly container: Container) {}
503-
504-
dispose() {
505-
this.providers.forEach(p => void p.dispose());
506-
this.providers.clear();
507-
}
508-
509-
get configured(): Map<IntegrationId, ConfiguredIntegrationDescriptor[]> {
510-
if (this._configured == null) {
511-
this._configured = new Map();
512-
const storedConfigured = this.container.storage.get('integrations:configured');
513-
for (const [id, configured] of Object.entries(storedConfigured ?? {})) {
514-
if (configured == null) continue;
515-
const descriptors = configured.map(d => ({
516-
...d,
517-
expiresAt: d.expiresAt ? new Date(d.expiresAt) : undefined,
518-
}));
519-
this._configured.set(id as IntegrationId, descriptors);
520-
}
521-
}
522-
523-
return this._configured;
524-
}
525-
526-
private async storeConfigured() {
527-
// We need to convert the map to a record to store
528-
const configured: Record<string, StoredConfiguredIntegrationDescriptor[]> = {};
529-
for (const [id, descriptors] of this.configured) {
530-
configured[id] = descriptors.map(d => ({
531-
...d,
532-
expiresAt: d.expiresAt
533-
? d.expiresAt instanceof Date
534-
? d.expiresAt.toISOString()
535-
: d.expiresAt
536-
: undefined,
537-
}));
538-
}
539-
540-
await this.container.storage.store('integrations:configured', configured);
541-
}
542-
543-
async addConfigured(descriptor: ConfiguredIntegrationDescriptor) {
544-
const descriptors = this.configured.get(descriptor.integrationId) ?? [];
545-
// Only add if one does not exist
546-
if (descriptors.some(d => d.domain === descriptor.domain && d.integrationId === descriptor.integrationId)) {
547-
return;
548-
}
549-
descriptors.push(descriptor);
550-
this.configured.set(descriptor.integrationId, descriptors);
551-
await this.storeConfigured();
552-
}
553-
554-
async removeConfigured(descriptor: Pick<ConfiguredIntegrationDescriptor, 'integrationId' | 'domain'>) {
555-
const descriptors = this.configured.get(descriptor.integrationId);
556-
if (descriptors == null) return;
557-
const index = descriptors.findIndex(
558-
d => d.domain === descriptor.domain && d.integrationId === descriptor.integrationId,
559-
);
560-
if (index === -1) return;
561-
562-
descriptors.splice(index, 1);
563-
this.configured.set(descriptor.integrationId, descriptors);
564-
565-
await this.storeConfigured();
566-
}
567-
568-
async get(providerId: IntegrationId): Promise<IntegrationAuthenticationProvider> {
569-
return this.ensureProvider(providerId);
570-
}
571-
572-
@log()
573-
async reset() {
574-
// TODO: This really isn't ideal, since it will only work for "cloud" providers as we won't have any more specific descriptors
575-
await Promise.allSettled(
576-
supportedIntegrationIds.map(async providerId => (await this.ensureProvider(providerId)).deleteSession()),
577-
);
578-
}
579-
580-
supports(providerId: string): boolean {
581-
switch (providerId) {
582-
case HostingIntegrationId.AzureDevOps:
583-
case HostingIntegrationId.Bitbucket:
584-
case SelfHostedIntegrationId.GitHubEnterprise:
585-
case HostingIntegrationId.GitLab:
586-
case SelfHostedIntegrationId.GitLabSelfHosted:
587-
case IssueIntegrationId.Jira:
588-
return true;
589-
case HostingIntegrationId.GitHub:
590-
return isSupportedCloudIntegrationId(HostingIntegrationId.GitHub);
591-
default:
592-
return false;
593-
}
594-
}
595-
596-
@gate()
597-
private async ensureProvider(providerId: IntegrationId): Promise<IntegrationAuthenticationProvider> {
598-
let provider = this.providers.get(providerId);
599-
if (provider == null) {
600-
switch (providerId) {
601-
case HostingIntegrationId.AzureDevOps:
602-
provider = new (
603-
await import(/* webpackChunkName: "integrations" */ './azureDevOps')
604-
).AzureDevOpsAuthenticationProvider(this.container, this);
605-
break;
606-
case HostingIntegrationId.Bitbucket:
607-
provider = new (
608-
await import(/* webpackChunkName: "integrations" */ './bitbucket')
609-
).BitbucketAuthenticationProvider(this.container, this);
610-
break;
611-
case HostingIntegrationId.GitHub:
612-
provider = isSupportedCloudIntegrationId(HostingIntegrationId.GitHub)
613-
? new (
614-
await import(/* webpackChunkName: "integrations" */ './github')
615-
).GitHubAuthenticationProvider(this.container, this)
616-
: new BuiltInAuthenticationProvider(this.container, this, providerId);
617-
618-
break;
619-
case SelfHostedIntegrationId.CloudGitHubEnterprise:
620-
provider = new (
621-
await import(/* webpackChunkName: "integrations" */ './github')
622-
).GitHubEnterpriseCloudAuthenticationProvider(this.container, this);
623-
break;
624-
case SelfHostedIntegrationId.GitHubEnterprise:
625-
provider = new (
626-
await import(/* webpackChunkName: "integrations" */ './github')
627-
).GitHubEnterpriseAuthenticationProvider(this.container, this);
628-
break;
629-
case HostingIntegrationId.GitLab:
630-
provider = isSupportedCloudIntegrationId(HostingIntegrationId.GitLab)
631-
? new (
632-
await import(/* webpackChunkName: "integrations" */ './gitlab')
633-
).GitLabCloudAuthenticationProvider(this.container, this)
634-
: new (
635-
await import(/* webpackChunkName: "integrations" */ './gitlab')
636-
).GitLabLocalAuthenticationProvider(this.container, this, HostingIntegrationId.GitLab);
637-
break;
638-
case SelfHostedIntegrationId.CloudGitLabSelfHosted:
639-
provider = new (
640-
await import(/* webpackChunkName: "integrations" */ './gitlab')
641-
).GitLabSelfHostedCloudAuthenticationProvider(this.container, this);
642-
break;
643-
case SelfHostedIntegrationId.GitLabSelfHosted:
644-
provider = new (
645-
await import(/* webpackChunkName: "integrations" */ './gitlab')
646-
).GitLabLocalAuthenticationProvider(this.container, this, SelfHostedIntegrationId.GitLabSelfHosted);
647-
break;
648-
case IssueIntegrationId.Jira:
649-
provider = new (
650-
await import(/* webpackChunkName: "integrations" */ './jira')
651-
).JiraAuthenticationProvider(this.container, this);
652-
break;
653-
default:
654-
provider = new BuiltInAuthenticationProvider(this.container, this, providerId);
655-
}
656-
this.providers.set(providerId, provider);
657-
}
658-
659-
return provider;
660-
}
661-
}
662-
663494
function convertStoredSessionToSession(
664495
storedSession: StoredSession,
665496
cloudIfMissing: boolean,

0 commit comments

Comments
 (0)