From ccd9eb25aa76ea6df8e6d18d7982345827b11a7d Mon Sep 17 00:00:00 2001 From: Ramin Tadayon Date: Tue, 21 Jan 2025 10:49:38 -0700 Subject: [PATCH] Removes redundant try/catch, improves formatting and updates comment --- .../authentication/integrationAuthentication.ts | 2 +- src/plus/integrations/integrationService.ts | 15 ++++++--------- src/plus/launchpad/launchpad.ts | 1 + src/plus/launchpad/launchpadProvider.ts | 4 ++++ src/plus/startWork/startWork.ts | 1 + 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plus/integrations/authentication/integrationAuthentication.ts b/src/plus/integrations/authentication/integrationAuthentication.ts index 9d6f5f418733b..3ce0c7a37f3d5 100644 --- a/src/plus/integrations/authentication/integrationAuthentication.ts +++ b/src/plus/integrations/authentication/integrationAuthentication.ts @@ -376,7 +376,7 @@ export abstract class CloudIntegrationAuthenticationProvider< let session = await cloudIntegrations.getConnectionSession(this.authProviderId); - // Make an exception for GitHub because they always return 0 + // Make an exception for GitHub and Cloud Self-Hosted integrations because they always return 0 if ( session?.expiresIn === 0 && (this.authProviderId === HostingIntegrationId.GitHub || isCloudSelfHostedIntegrationId(this.authProviderId)) diff --git a/src/plus/integrations/integrationService.ts b/src/plus/integrations/integrationService.ts index d2bb09d6156b1..af8e8c7392b32 100644 --- a/src/plus/integrations/integrationService.ts +++ b/src/plus/integrations/integrationService.ts @@ -142,15 +142,10 @@ export class IntegrationService implements Disposable { private async *getSupportedCloudIntegrations(domainsById: Map): AsyncIterable { for (const id of getSupportedCloudIntegrationIds()) { if (isCloudSelfHostedIntegrationId(id) && !domainsById.has(id)) { - try { - // Try getting whatever we have now because we will need to disconnect - const integration = await this.get(id, undefined); - if (integration != null) { - yield integration; - } - } catch { - // Ignore this exception and continue, - // because we probably haven't ever had an instance of this integration + // Try getting whatever we have now because we will need to disconnect + const integration = await this.get(id, undefined); + if (integration != null) { + yield integration; } } else { const integration = await this.get(id, domainsById.get(id)); @@ -253,6 +248,7 @@ export class IntegrationService implements Disposable { try { const integration = await this.get(integrationId); if (integration == null) continue; + if (integration.maybeConnected ?? (await integration.isConnected())) { connectedIntegrations.add(integrationId); } @@ -377,6 +373,7 @@ export class IntegrationService implements Disposable { for (const integrationId of integrationIds) { const integration = await this.get(integrationId); if (integration == null) continue; + const connected = integration.maybeConnected ?? (await integration.isConnected()); if (connected && !connectedIntegrations.has(integrationId)) { return true; diff --git a/src/plus/launchpad/launchpad.ts b/src/plus/launchpad/launchpad.ts index 2bd18e946450f..fe8aa04f2538d 100644 --- a/src/plus/launchpad/launchpad.ts +++ b/src/plus/launchpad/launchpad.ts @@ -200,6 +200,7 @@ export class LaunchpadCommand extends QuickCommand { private async ensureIntegrationConnected(id: IntegrationId) { const integration = await this.container.integrations.get(id); if (integration == null) return false; + let connected = integration.maybeConnected ?? (await integration.isConnected()); if (!connected) { connected = await integration.connect('launchpad'); diff --git a/src/plus/launchpad/launchpadProvider.ts b/src/plus/launchpad/launchpadProvider.ts index e2852767c0709..4b430040ac1f9 100644 --- a/src/plus/launchpad/launchpadProvider.ts +++ b/src/plus/launchpad/launchpadProvider.ts @@ -275,6 +275,7 @@ export class LaunchpadProvider implements Disposable { .map(async (id: SupportedLaunchpadIntegrationIds) => { const integration = await this.container.integrations.get(id); if (integration == null) return; + const searchResult = await searchIntegrationPRs(integration); const prs = searchResult?.value; if (prs) { @@ -410,6 +411,7 @@ export class LaunchpadProvider implements Disposable { if (confirm !== 'Merge') return; const integration = await this.container.integrations.get(integrationId); if (integration == null) return; + const pr: PullRequest = fromProviderPullRequest(item, integration); await integration.mergePullRequest(pr); this.refresh(); @@ -603,6 +605,7 @@ export class LaunchpadProvider implements Disposable { if (connectedIntegrations.get(integrationId)) { const integration = await this.container.integrations.get(integrationId); if (integration == null) continue; + const prIdentity = integration.getPullRequestIdentityFromMaybeUrl(search); if (prIdentity) { return prIdentity; @@ -873,6 +876,7 @@ export class LaunchpadProvider implements Disposable { for (const integrationId of supportedLaunchpadIntegrations) { const integration = await this.container.integrations.get(integrationId); if (integration == null) continue; + if (integration.maybeConnected ?? (await integration.isConnected())) { return true; } diff --git a/src/plus/startWork/startWork.ts b/src/plus/startWork/startWork.ts index d6d10ecc1e549..4449affc8b3f4 100644 --- a/src/plus/startWork/startWork.ts +++ b/src/plus/startWork/startWork.ts @@ -317,6 +317,7 @@ export abstract class StartWorkBaseCommand extends QuickCommand { private async ensureIntegrationConnected(id: IntegrationId) { const integration = await this.container.integrations.get(id); if (integration == null) return false; + let connected = integration.maybeConnected ?? (await integration.isConnected()); if (!connected) { connected = await integration.connect(this.overrides?.ownSource ?? 'startWork');