Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions src/autolinks/autolinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import type { IntegrationId } from '../constants.integrations';
import { IssueIntegrationId } from '../constants.integrations';
import type { Container } from '../container';
import type { GitRemote } from '../git/models/remote';
import type { RemoteProviderId } from '../git/remotes/remoteProvider';
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/utils/-webview/icons';
import type { HostingIntegration, IssueIntegration } from '../plus/integrations/integration';
import type { HostingIntegration, Integration, IssueIntegration } from '../plus/integrations/integration';
import { IntegrationBase } from '../plus/integrations/integration';
import { remoteProviderIdToIntegrationId } from '../plus/integrations/integrationService';
import { configuration } from '../system/-webview/configuration';
import { fromNow } from '../system/date';
import { debug } from '../system/decorators/log';
Expand Down Expand Up @@ -214,9 +217,29 @@ export class Autolinks implements Disposable {

const enrichedAutolinks = new Map<string, EnrichedAutolink>();
for (const [id, link] of messageOrAutolinks) {
let linkIntegration = link.provider
? await this.container.integrations.get(link.provider.id as IntegrationId)
: undefined;
let integrationId: IntegrationId | undefined;
let linkIntegration: Integration | undefined;
if (link.provider != null) {
// Try to make a smart choice
integrationId =
link.provider instanceof IntegrationBase
? link.provider.id
: // TODO: Tighten the typing on ProviderReference to be specific to a remote provider, and then have a separate "integration" property (on autolinks and elsewhere)
// that is of a new type IntegrationReference specific to integrations. Otherwise, make remote provider ids line up directly with integration ids.
// Either way, this converting/casting hackery needs to go away.
remoteProviderIdToIntegrationId(link.provider.id as RemoteProviderId);
if (integrationId == null) {
// Fall back to the old logic assuming that integration id might be saved as provider id.
// TODO: it should be removed when we put providers and integrations in order. Conversation: https://github.com/gitkraken/vscode-gitlens/pull/3996#discussion_r1936422826
integrationId = link.provider.id as IntegrationId;
}
try {
linkIntegration = await this.container.integrations.get(integrationId);
} catch (e) {
Logger.error(e, `Failed to get integration for ${link.provider.id}`);
linkIntegration = undefined;
}
}
if (linkIntegration != null) {
const connected = linkIntegration.maybeConnected ?? (await linkIntegration.isConnected());
if (!connected || !(await linkIntegration.access())) {
Expand All @@ -226,7 +249,7 @@ export class Autolinks implements Disposable {
const issueOrPullRequestPromise =
remote?.provider != null &&
integration != null &&
link.provider?.id === integration.id &&
integrationId === integration.id &&
link.provider?.domain === integration.domain
? integration.getIssueOrPullRequest(
link.descriptor ?? remote.provider.repoDesc,
Expand Down
23 changes: 23 additions & 0 deletions src/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { CloudIntegrationService } from './plus/integrations/authentication
import { ConfiguredIntegrationService } from './plus/integrations/authentication/configuredIntegrationService';
import { IntegrationAuthenticationService } from './plus/integrations/authentication/integrationAuthenticationService';
import { IntegrationService } from './plus/integrations/integrationService';
import type { AzureDevOpsApi } from './plus/integrations/providers/azure/azure';
import type { GitHubApi } from './plus/integrations/providers/github/github';
import type { GitLabApi } from './plus/integrations/providers/gitlab/gitlab';
import { EnrichmentService } from './plus/launchpad/enrichmentService';
Expand Down Expand Up @@ -477,6 +478,28 @@ export class Container {
return this._git;
}

private _azure: Promise<AzureDevOpsApi | undefined> | undefined;
get azure(): Promise<AzureDevOpsApi | undefined> {
if (this._azure == null) {
async function load(this: Container) {
try {
const azure = new (
await import(/* webpackChunkName: "integrations" */ './plus/integrations/providers/azure/azure')
).AzureDevOpsApi(this);
this._disposables.push(azure);
return azure;
} catch (ex) {
Logger.error(ex);
return undefined;
}
}

this._azure = load.call(this);
}

return this._azure;
}

private _github: Promise<GitHubApi | undefined> | undefined;
get github(): Promise<GitHubApi | undefined> {
if (this._github == null) {
Expand Down
3 changes: 0 additions & 3 deletions src/plus/integrations/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,6 @@ export function remoteProviderIdToIntegrationId(
remoteProviderId: RemoteProviderId,
): SupportedCloudIntegrationIds | undefined {
switch (remoteProviderId) {
// TODO: Uncomment when we support these integrations
// case 'bitbucket':
// return HostingIntegrationId.Bitbucket;
case 'azure-devops':
return HostingIntegrationId.AzureDevOps;
case 'github':
Expand Down
Loading