Skip to content

Commit 672297d

Browse files
axosoft-ramintsergeibbb
authored andcommitted
Stores and uses stored values for configured integration descriptors
1 parent 9b5a815 commit 672297d

File tree

11 files changed

+208
-50
lines changed

11 files changed

+208
-50
lines changed

src/constants.storage.ts

+14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export type GlobalStorage = {
7878
'launchpadView:groups:expanded': StoredLaunchpadGroup[];
7979
'graph:searchMode': StoredGraphSearchMode;
8080
'views:scm:grouped:welcome:dismissed': boolean;
81+
'integrations:configured': StoredIntegrationConfigurations;
8182
} & { [key in `plus:preview:${FeaturePreviews}:usages`]: StoredFeaturePreviewUsagePeriod[] } & {
8283
[key in `confirm:ai:tos:${AIProviders}`]: boolean;
8384
} & {
@@ -88,6 +89,19 @@ export type GlobalStorage = {
8889
[key in `jira:${string}:projects`]: Stored<StoredJiraProject[] | undefined>;
8990
};
9091

92+
export type StoredIntegrationConfigurations = Record<
93+
string,
94+
StoredConfiguredProviderAuthenticationDescriptor[] | undefined
95+
>;
96+
97+
export interface StoredConfiguredProviderAuthenticationDescriptor {
98+
cloud: boolean;
99+
integrationId: IntegrationId;
100+
domain?: string;
101+
expiresAt?: string;
102+
scopes: string;
103+
}
104+
91105
export type DeprecatedWorkspaceStorage = {
92106
/** @deprecated use `confirm:ai:tos:${AIProviders}` */
93107
'confirm:sendToOpenAI': boolean;

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
3838
let remotesPromise = this.cache.remotes?.get(repoPath);
3939
if (remotesPromise == null) {
4040
async function load(this: RemotesGitSubProvider): Promise<GitRemote[]> {
41-
const ci = await this.container.cloudIntegrations;
42-
const connections = await ci?.getConnections();
4341
const providers = loadRemoteProviders(
4442
configuration.get('remotes', this.container.git.getRepository(repoPath!)?.folder?.uri ?? null),
45-
connections,
43+
this.container.integrations.getConfiguredIntegrationDescriptors(),
4644
);
4745

4846
try {
@@ -51,7 +49,7 @@ export class RemotesGitSubProvider extends RemotesGitProviderBase implements Git
5149
this.container,
5250
data,
5351
repoPath!,
54-
await getRemoteProviderMatcher(this.container, providers),
52+
getRemoteProviderMatcher(this.container, providers),
5553
);
5654
return remotes;
5755
} catch (ex) {

src/git/parsers/remoteParser.ts

+1-1
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: Awaited<ReturnType<typeof getRemoteProviderMatcher>>,
13+
remoteProviderMatcher: 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

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { RemotesConfig } from '../../config';
22
import { SelfHostedIntegrationId } from '../../constants.integrations';
33
import type { Container } from '../../container';
4-
import type { CloudIntegrationConnection } from '../../plus/integrations/authentication/models';
5-
import { toIntegrationId } from '../../plus/integrations/authentication/models';
4+
import type { ConfiguredProviderAuthenticationDescriptor } from '../../plus/integrations/authentication/models';
65
import { Logger } from '../../system/logger';
76
import { configuration } from '../../system/vscode/configuration';
87
import { AzureDevOpsRemote } from './azure-devops';
@@ -78,7 +77,7 @@ const builtInProviders: RemoteProviders = [
7877

7978
export function loadRemoteProviders(
8079
cfg: RemotesConfig[] | null | undefined,
81-
connectedIntegrations: CloudIntegrationConnection[] | undefined,
80+
configuredIntegrations?: ConfiguredProviderAuthenticationDescriptor[],
8281
): RemoteProviders {
8382
const providers: RemoteProviders = [];
8483

@@ -103,10 +102,10 @@ export function loadRemoteProviders(
103102
}
104103
}
105104

106-
if (connectedIntegrations?.length) {
107-
for (const ci of connectedIntegrations) {
108-
if (toIntegrationId[ci.provider] === SelfHostedIntegrationId.CloudGitHubEnterprise) {
109-
const matcher = new URL(ci.domain).host.toLocaleLowerCase();
105+
if (configuredIntegrations?.length) {
106+
for (const ci of configuredIntegrations) {
107+
if (ci.integrationId === SelfHostedIntegrationId.CloudGitHubEnterprise && ci.domain) {
108+
const matcher = ci.domain.toLocaleLowerCase();
110109
const providerCreator = (_container: Container, domain: string, path: string) =>
111110
new GitHubRemote(domain, path);
112111
const provider = {
@@ -165,14 +164,15 @@ function getCustomProviderCreator(cfg: RemotesConfig) {
165164
}
166165
}
167166

168-
export async function getRemoteProviderMatcher(
167+
export function getRemoteProviderMatcher(
169168
container: Container,
170169
providers?: RemoteProviders,
171-
): Promise<(url: string, domain: string, path: string) => RemoteProvider | undefined> {
170+
): (url: string, domain: string, path: string) => RemoteProvider | undefined {
172171
if (providers == null) {
173-
const ci = await container.cloudIntegrations;
174-
const c = await ci?.getConnections();
175-
providers = loadRemoteProviders(configuration.get('remotes', null), c);
172+
providers = loadRemoteProviders(
173+
configuration.get('remotes', null),
174+
container.integrations.getConfiguredIntegrationDescriptors(),
175+
);
176176
}
177177

178178
return (url: string, domain: string, path: string) =>

src/plus/drafts/draftsService.ts

+1-1
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 = await getRemoteProviderMatcher(this.container);
732+
const matcher = 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/integrations/authentication/github.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ 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 { IntegrationAuthenticationSessionDescriptor } from './integrationAuthentication';
7+
import type {
8+
IntegrationAuthenticationService,
9+
IntegrationAuthenticationSessionDescriptor,
10+
} from './integrationAuthentication';
811
import {
912
CloudIntegrationAuthenticationProvider,
1013
LocalIntegrationAuthenticationProvider,
1114
} from './integrationAuthentication';
1215
import type { ProviderAuthenticationSession } from './models';
1316

1417
export class GitHubAuthenticationProvider extends CloudIntegrationAuthenticationProvider<HostingIntegrationId.GitHub> {
15-
constructor(container: Container) {
16-
super(container);
18+
constructor(container: Container, authenticationService: IntegrationAuthenticationService) {
19+
super(container, authenticationService);
1720
this.disposables.push(
1821
authentication.onDidChangeSessions(e => {
1922
if (e.provider.id === this.authProviderId) {

src/plus/integrations/authentication/gitlab.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { env, ThemeIcon, Uri, window } from 'vscode';
33
import type { SelfHostedIntegrationId } from '../../../constants.integrations';
44
import { HostingIntegrationId } from '../../../constants.integrations';
55
import type { Container } from '../../../container';
6-
import type { IntegrationAuthenticationSessionDescriptor } from './integrationAuthentication';
6+
import type {
7+
IntegrationAuthenticationService,
8+
IntegrationAuthenticationSessionDescriptor,
9+
} from './integrationAuthentication';
710
import {
811
CloudIntegrationAuthenticationProvider,
912
LocalIntegrationAuthenticationProvider,
@@ -15,9 +18,10 @@ type GitLabId = HostingIntegrationId.GitLab | SelfHostedIntegrationId.GitLabSelf
1518
export class GitLabLocalAuthenticationProvider extends LocalIntegrationAuthenticationProvider<GitLabId> {
1619
constructor(
1720
container: Container,
21+
authenticationService: IntegrationAuthenticationService,
1822
protected readonly authProviderId: GitLabId,
1923
) {
20-
super(container);
24+
super(container, authenticationService);
2125
}
2226

2327
override async createSession(

0 commit comments

Comments
 (0)