Skip to content

Commit 22796d9

Browse files
committed
Makes UI to request Auzure autolinks properly
(#3977, #3996)
1 parent c77c2ac commit 22796d9

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/autolinks/autolinks.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import { IssueIntegrationId } from '../constants.integrations';
66
import type { Container } from '../container';
77
import type { GitRemote } from '../git/models/remote';
88
import { getIssueOrPullRequestHtmlIcon, getIssueOrPullRequestMarkdownIcon } from '../git/utils/-webview/icons';
9-
import type { HostingIntegration, IssueIntegration } from '../plus/integrations/integration';
9+
import type { HostingIntegration, Integration, IssueIntegration } from '../plus/integrations/integration';
10+
import { IntegrationBase } from '../plus/integrations/integration';
11+
import { remoteProviderIdToIntegrationId } from '../plus/integrations/integrationService';
1012
import { configuration } from '../system/-webview/configuration';
1113
import { fromNow } from '../system/date';
1214
import { debug } from '../system/decorators/log';
@@ -214,9 +216,26 @@ export class Autolinks implements Disposable {
214216

215217
const enrichedAutolinks = new Map<string, EnrichedAutolink>();
216218
for (const [id, link] of messageOrAutolinks) {
217-
let linkIntegration = link.provider
218-
? await this.container.integrations.get(link.provider.id as IntegrationId)
219-
: undefined;
219+
let integrationId: IntegrationId | undefined;
220+
let linkIntegration: Integration | undefined;
221+
if (link.provider != null) {
222+
// Try to make a smart choice
223+
integrationId =
224+
link.provider instanceof IntegrationBase
225+
? link.provider.id
226+
: remoteProviderIdToIntegrationId(link.provider.id);
227+
if (integrationId == null) {
228+
// Fall back to the old logic assuming that integration id might be saved as provider id.
229+
// TODO: it should be removed when we put providers and integrations in order. Conversation: https://github.com/gitkraken/vscode-gitlens/pull/3996#discussion_r1936422826
230+
integrationId = link.provider.id as IntegrationId;
231+
}
232+
try {
233+
linkIntegration = await this.container.integrations.get(integrationId);
234+
} catch (e) {
235+
Logger.error(e, `Failed to get integration for ${link.provider.id}`);
236+
linkIntegration = undefined;
237+
}
238+
}
220239
if (linkIntegration != null) {
221240
const connected = linkIntegration.maybeConnected ?? (await linkIntegration.isConnected());
222241
if (!connected || !(await linkIntegration.access())) {
@@ -226,7 +245,7 @@ export class Autolinks implements Disposable {
226245
const issueOrPullRequestPromise =
227246
remote?.provider != null &&
228247
integration != null &&
229-
link.provider?.id === integration.id &&
248+
integrationId === integration.id &&
230249
link.provider?.domain === integration.domain
231250
? integration.getIssueOrPullRequest(
232251
link.descriptor ?? remote.provider.repoDesc,

src/plus/integrations/integrationService.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,13 +1029,8 @@ export class IntegrationService implements Disposable {
10291029
}
10301030
}
10311031

1032-
export function remoteProviderIdToIntegrationId(
1033-
remoteProviderId: RemoteProviderId,
1034-
): SupportedCloudIntegrationIds | undefined {
1032+
export function remoteProviderIdToIntegrationId(remoteProviderId: string): SupportedCloudIntegrationIds | undefined {
10351033
switch (remoteProviderId) {
1036-
// TODO: Uncomment when we support these integrations
1037-
// case 'bitbucket':
1038-
// return HostingIntegrationId.Bitbucket;
10391034
case 'azure-devops':
10401035
return HostingIntegrationId.AzureDevOps;
10411036
case 'github':

0 commit comments

Comments
 (0)