Skip to content

Commit d1f6477

Browse files
Moves configured integrations and session storage to new service (#3985)
Updates Home view to use new service for configured integrations
1 parent 41981c1 commit d1f6477

File tree

20 files changed

+659
-513
lines changed

20 files changed

+659
-513
lines changed

src/container.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { ServerConnection } from './plus/gk/serverConnection';
3232
import { SubscriptionService } from './plus/gk/subscriptionService';
3333
import { GraphStatusBarController } from './plus/graph/statusbar';
3434
import type { CloudIntegrationService } from './plus/integrations/authentication/cloudIntegrationService';
35+
import { ConfiguredIntegrationService } from './plus/integrations/authentication/configuredIntegrationService';
3536
import { IntegrationAuthenticationService } from './plus/integrations/authentication/integrationAuthenticationService';
3637
import { IntegrationService } from './plus/integrations/integrationService';
3738
import type { GitHubApi } from './plus/integrations/providers/github/github';
@@ -532,8 +533,12 @@ export class Container {
532533
private _integrations: IntegrationService | undefined;
533534
get integrations(): IntegrationService {
534535
if (this._integrations == null) {
535-
const authService = new IntegrationAuthenticationService(this);
536-
this._disposables.push(authService, (this._integrations = new IntegrationService(this, authService)));
536+
const configuredIntegrationService = new ConfiguredIntegrationService(this);
537+
const authService = new IntegrationAuthenticationService(this, configuredIntegrationService);
538+
this._disposables.push(
539+
authService,
540+
(this._integrations = new IntegrationService(this, authService, configuredIntegrationService)),
541+
);
537542
}
538543
return this._integrations;
539544
}

src/env/node/git/sub-providers/remotes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
4040
async function load(this: RemotesGitSubProvider): Promise<GitRemote[]> {
4141
const providers = loadRemoteProviders(
4242
configuration.get('remotes', this.container.git.getRepository(repoPath!)?.folder?.uri ?? null),
43-
this.container.integrations.getConfiguredIntegrationDescriptors(),
43+
await this.container.integrations.getConfigured(),
4444
);
4545

4646
try {
@@ -49,7 +49,7 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
4949
this.container,
5050
data,
5151
repoPath!,
52-
getRemoteProviderMatcher(this.container, providers),
52+
await getRemoteProviderMatcher(this.container, providers),
5353
);
5454
return remotes;
5555
} catch (ex) {

src/git/parsers/remoteParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function parseGitRemotes(
1010
container: Container,
1111
data: string,
1212
repoPath: string,
13-
remoteProviderMatcher: ReturnType<typeof getRemoteProviderMatcher>,
13+
remoteProviderMatcher: Awaited<ReturnType<typeof getRemoteProviderMatcher>>,
1414
): GitRemote[] {
1515
using sw = maybeStopWatch(`Git.parseRemotes(${repoPath})`, { log: false, logLevel: 'debug' });
1616
if (!data) return [];

src/git/remotes/remoteProviders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
167167
}
168168
}
169169

170-
export function getRemoteProviderMatcher(
170+
export async function getRemoteProviderMatcher(
171171
container: Container,
172172
providers?: RemoteProviders,
173-
): (url: string, domain: string, path: string) => RemoteProvider | undefined {
173+
): Promise<(url: string, domain: string, path: string) => RemoteProvider | undefined> {
174174
if (providers == null) {
175175
providers = loadRemoteProviders(
176176
configuration.get('remotes', null),
177-
container.integrations.getConfiguredIntegrationDescriptors(),
177+
await container.integrations.getConfigured(),
178178
);
179179
}
180180

src/plus/drafts/draftsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ export class DraftService implements Disposable {
729729
} else if (data.provider?.repoName != null) {
730730
name = data.provider.repoName;
731731
} else if (data.remote?.url != null && data.remote?.domain != null && data.remote?.path != null) {
732-
const matcher = getRemoteProviderMatcher(this.container);
732+
const matcher = await getRemoteProviderMatcher(this.container);
733733
const provider = matcher(data.remote.url, data.remote.domain, data.remote.path);
734734
name = provider?.repoName ?? data.remote.path;
735735
} else {

src/plus/gk/utils/-webview/integrationAuthentication.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const getBuiltInIntegrationSession = sequentialize(
2929
return {
3030
...session,
3131
cloud: false,
32+
domain: descriptor.domain,
3233
};
3334
},
3435
),

src/plus/integrations/authentication/azureDevOps.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthentic
1212
}
1313

1414
override async createSession(
15-
descriptor?: IntegrationAuthenticationSessionDescriptor,
15+
descriptor: IntegrationAuthenticationSessionDescriptor,
1616
): Promise<ProviderAuthenticationSession | undefined> {
17-
let azureOrganization: string | undefined = descriptor?.organization as string | undefined;
17+
let azureOrganization: string | undefined = descriptor.organization as string | undefined;
1818
if (!azureOrganization) {
1919
const orgInput = window.createInputBox();
2020
orgInput.ignoreFocusOut = true;
@@ -35,9 +35,7 @@ export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthentic
3535
}),
3636
);
3737

38-
orgInput.title = `Azure DevOps Authentication${
39-
descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''
40-
}`;
38+
orgInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`;
4139
orgInput.placeholder = 'Organization';
4240
orgInput.prompt = 'Enter your Azure DevOps organization';
4341
orgInput.show();
@@ -78,24 +76,16 @@ export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthentic
7876
tokenInput.onDidTriggerButton(e => {
7977
if (e === infoButton) {
8078
void env.openExternal(
81-
Uri.parse(
82-
`https://${
83-
descriptor?.domain ?? 'dev.azure.com'
84-
}/${azureOrganization}/_usersSettings/tokens`,
85-
),
79+
Uri.parse(`https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens`),
8680
);
8781
}
8882
}),
8983
);
9084

9185
tokenInput.password = true;
92-
tokenInput.title = `Azure DevOps Authentication${
93-
descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''
94-
}`;
95-
tokenInput.placeholder = `Requires ${descriptor?.scopes.join(', ') ?? 'all'} scopes`;
96-
tokenInput.prompt = `Paste your [Azure DevOps Personal Access Token](https://${
97-
descriptor?.domain ?? 'dev.azure.com'
98-
}/${azureOrganization}/_usersSettings/tokens "Get your Azure DevOps Access Token")`;
86+
tokenInput.title = `Azure DevOps Authentication \u2022 ${descriptor.domain}`;
87+
tokenInput.placeholder = `Requires ${descriptor.scopes.join(', ') ?? 'all'} scopes`;
88+
tokenInput.prompt = `Paste your [Azure DevOps Personal Access Token](https://${descriptor.domain}/${azureOrganization}/_usersSettings/tokens "Get your Azure DevOps Access Token")`;
9989
tokenInput.buttons = [infoButton];
10090

10191
tokenInput.show();
@@ -108,14 +98,15 @@ export class AzureDevOpsAuthenticationProvider extends LocalIntegrationAuthentic
10898
if (!token) return undefined;
10999

110100
return {
111-
id: this.getSessionId(descriptor),
101+
id: this.configuredIntegrationService.getSessionId(descriptor),
112102
accessToken: base64(`:${token}`),
113-
scopes: descriptor?.scopes ?? [],
103+
scopes: descriptor.scopes,
114104
account: {
115105
id: '',
116106
label: '',
117107
},
118108
cloud: false,
109+
domain: descriptor.domain,
119110
};
120111
}
121112
}

src/plus/integrations/authentication/bitbucket.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export class BitbucketAuthenticationProvider extends LocalIntegrationAuthenticat
1212
}
1313

1414
override async createSession(
15-
descriptor?: IntegrationAuthenticationSessionDescriptor,
15+
descriptor: IntegrationAuthenticationSessionDescriptor,
1616
): Promise<ProviderAuthenticationSession | undefined> {
17-
let bitbucketUsername: string | undefined = descriptor?.username as string | undefined;
17+
let bitbucketUsername: string | undefined = descriptor.username as string | undefined;
1818
if (!bitbucketUsername) {
1919
const infoButton: QuickInputButton = {
2020
iconPath: new ThemeIcon(`link-external`),
@@ -40,20 +40,14 @@ export class BitbucketAuthenticationProvider extends LocalIntegrationAuthenticat
4040
}),
4141
usernameInput.onDidTriggerButton(e => {
4242
if (e === infoButton) {
43-
void env.openExternal(
44-
Uri.parse(`https://${descriptor?.domain ?? 'bitbucket.org'}/account/settings/`),
45-
);
43+
void env.openExternal(Uri.parse(`https://${descriptor.domain}/account/settings/`));
4644
}
4745
}),
4846
);
4947

50-
usernameInput.title = `Bitbucket Authentication${
51-
descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''
52-
}`;
48+
usernameInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`;
5349
usernameInput.placeholder = 'Username';
54-
usernameInput.prompt = `Enter your [Bitbucket Username](https://${
55-
descriptor?.domain ?? 'bitbucket.org'
56-
}/account/settings/ "Get your Bitbucket App Password")`;
50+
usernameInput.prompt = `Enter your [Bitbucket Username](https://${descriptor.domain}/account/settings/ "Get your Bitbucket App Password")`;
5751
usernameInput.show();
5852
});
5953
} finally {
@@ -92,22 +86,16 @@ export class BitbucketAuthenticationProvider extends LocalIntegrationAuthenticat
9286
appPasswordInput.onDidTriggerButton(e => {
9387
if (e === infoButton) {
9488
void env.openExternal(
95-
Uri.parse(
96-
`https://${descriptor?.domain ?? 'bitbucket.org'}/account/settings/app-passwords/`,
97-
),
89+
Uri.parse(`https://${descriptor.domain}/account/settings/app-passwords/`),
9890
);
9991
}
10092
}),
10193
);
10294

10395
appPasswordInput.password = true;
104-
appPasswordInput.title = `Bitbucket Authentication${
105-
descriptor?.domain ? ` \u2022 ${descriptor.domain}` : ''
106-
}`;
107-
appPasswordInput.placeholder = `Requires ${descriptor?.scopes.join(', ') ?? 'all'} scopes`;
108-
appPasswordInput.prompt = `Paste your [Bitbucket App Password](https://${
109-
descriptor?.domain ?? 'bitbucket.org'
110-
}/account/settings/app-passwords/ "Get your Bitbucket App Password")`;
96+
appPasswordInput.title = `Bitbucket Authentication \u2022 ${descriptor.domain}`;
97+
appPasswordInput.placeholder = `Requires ${descriptor.scopes.join(', ')} scopes`;
98+
appPasswordInput.prompt = `Paste your [Bitbucket App Password](https://${descriptor.domain}/account/settings/app-passwords/ "Get your Bitbucket App Password")`;
11199
appPasswordInput.buttons = [infoButton];
112100

113101
appPasswordInput.show();
@@ -120,14 +108,15 @@ export class BitbucketAuthenticationProvider extends LocalIntegrationAuthenticat
120108
if (!appPassword) return undefined;
121109

122110
return {
123-
id: this.getSessionId(descriptor),
111+
id: this.configuredIntegrationService.getSessionId(descriptor),
124112
accessToken: base64(`${bitbucketUsername}:${appPassword}`),
125-
scopes: descriptor?.scopes ?? [],
113+
scopes: descriptor.scopes,
126114
account: {
127115
id: '',
128116
label: '',
129117
},
130118
cloud: false,
119+
domain: descriptor.domain,
131120
};
132121
}
133122
}

0 commit comments

Comments
 (0)