@@ -6,7 +6,9 @@ import { IssueIntegrationId } from '../constants.integrations';
66import type { Container } from '../container' ;
77import type { GitRemote } from '../git/models/remote' ;
88import { 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' ;
1012import { configuration } from '../system/-webview/configuration' ;
1113import { fromNow } from '../system/date' ;
1214import { 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 ,
0 commit comments