@@ -1076,52 +1076,60 @@ export class GitProviderService implements Disposable {
10761076 async function updateRemoteContext ( this : GitProviderService ) {
10771077 const integrations = configuration . get ( 'integrations.enabled' ) ;
10781078
1079- const telemetryEnabled = this . container . telemetry . enabled ;
10801079 const remoteProviders = new Set < string > ( ) ;
1080+ const reposWithRemotes = new Set < string > ( ) ;
1081+ const reposWithHostingIntegrations = new Set < string > ( ) ;
1082+ const reposWithHostingIntegrationsConnected = new Set < string > ( ) ;
10811083
1082- let hasRemotes = false ;
1083- let hasRemotesWithIntegrations = false ;
1084- let hasConnectedRemotes = false ;
1084+ async function scanRemotes ( repo : Repository ) {
1085+ let hasSupportedIntegration = false ;
1086+ let hasConnectedIntegration = false ;
10851087
1086- if ( hasRepositories ) {
1087- for ( const repo of this . _repositories . values ( ) ) {
1088- if ( telemetryEnabled ) {
1089- const remotes = await repo . getRemotes ( ) ;
1090- for ( const remote of remotes ) {
1091- remoteProviders . add ( remote . provider ?. id ?? 'unknown' ) ;
1092- }
1093- }
1094-
1095- if ( ! hasConnectedRemotes && integrations ) {
1096- hasConnectedRemotes = await repo . hasRemoteWithIntegration ( { includeDisconnected : false } ) ;
1097-
1098- if ( hasConnectedRemotes ) {
1099- hasRemotesWithIntegrations = true ;
1100- hasRemotes = true ;
1088+ const remotes = await repo . getRemotes ( ) ;
1089+ for ( const remote of remotes ) {
1090+ remoteProviders . add ( remote . provider ?. id ?? 'unknown' ) ;
1091+ reposWithRemotes . add ( repo . uri . toString ( ) ) ;
1092+ reposWithRemotes . add ( repo . path ) ;
1093+
1094+ // Skip if integrations are disabled or if we've already found a connected integration
1095+ if ( ! integrations || ( hasSupportedIntegration && hasConnectedIntegration ) ) continue ;
1096+
1097+ if ( remote . hasIntegration ( ) ) {
1098+ hasSupportedIntegration = true ;
1099+ reposWithHostingIntegrations . add ( repo . uri . toString ( ) ) ;
1100+ reposWithHostingIntegrations . add ( repo . path ) ;
1101+
1102+ let connected = remote . maybeIntegrationConnected ;
1103+ // If we don't know if we are connected, only check if the remote is the default or there is only one
1104+ // TODO@eamodio is the above still a valid requirement?
1105+ if ( connected == null && ( remote . default || remotes . length === 1 ) ) {
1106+ const integration = await remote . getIntegration ( ) ;
1107+ connected = await integration ?. isConnected ( ) ;
11011108 }
1102- }
1103-
1104- if ( ! hasRemotesWithIntegrations && integrations ) {
1105- hasRemotesWithIntegrations = await repo . hasRemoteWithIntegration ( { includeDisconnected : true } ) ;
11061109
1107- if ( hasRemotesWithIntegrations ) {
1108- hasRemotes = true ;
1110+ if ( connected ) {
1111+ hasConnectedIntegration = true ;
1112+ reposWithHostingIntegrationsConnected . add ( repo . uri . toString ( ) ) ;
1113+ reposWithHostingIntegrationsConnected . add ( repo . path ) ;
11091114 }
11101115 }
1111-
1112- if ( ! hasRemotes ) {
1113- hasRemotes = await repo . hasRemotes ( ) ;
1114- }
1115-
1116- if ( hasRemotes && ( ( hasRemotesWithIntegrations && hasConnectedRemotes ) || ! integrations ) ) break ;
11171116 }
11181117 }
11191118
1120- if ( telemetryEnabled ) {
1119+ if ( hasRepositories ) {
1120+ void ( await Promise . allSettled ( map ( this . _repositories . values ( ) , scanRemotes ) ) ) ;
1121+ }
1122+
1123+ if ( this . container . telemetry . enabled ) {
11211124 this . container . telemetry . setGlobalAttributes ( {
1122- 'repositories.hasRemotes' : hasRemotes ,
1123- 'repositories.hasRichRemotes' : hasRemotesWithIntegrations ,
1124- 'repositories.hasConnectedRemotes' : hasConnectedRemotes ,
1125+ 'repositories.hasRemotes' : reposWithRemotes . size !== 0 ,
1126+ 'repositories.hasRichRemotes' : reposWithHostingIntegrations . size !== 0 ,
1127+ 'repositories.hasConnectedRemotes' : reposWithHostingIntegrationsConnected . size !== 0 ,
1128+
1129+ 'repositories.withRemotes' : reposWithRemotes . size / 2 ,
1130+ 'repositories.withHostingIntegrations' : reposWithHostingIntegrations . size / 2 ,
1131+ 'repositories.withHostingIntegrationsConnected' : reposWithHostingIntegrationsConnected . size / 2 ,
1132+
11251133 'repositories.remoteProviders' : join ( remoteProviders , ',' ) ,
11261134 } ) ;
11271135 if ( this . _sendProviderContextTelemetryDebounced == null ) {
@@ -1134,9 +1142,15 @@ export class GitProviderService implements Disposable {
11341142 }
11351143
11361144 await Promise . allSettled ( [
1137- setContext ( 'gitlens:hasRemotes' , hasRemotes ) ,
1138- setContext ( 'gitlens:hasRichRemotes' , hasRemotesWithIntegrations ) ,
1139- setContext ( 'gitlens:hasConnectedRemotes' , hasConnectedRemotes ) ,
1145+ setContext ( 'gitlens:repos:withRemotes' , reposWithRemotes . size ? [ ...reposWithRemotes ] : undefined ) ,
1146+ setContext (
1147+ 'gitlens:repos:withHostingIntegrations' ,
1148+ reposWithHostingIntegrations . size ? [ ...reposWithHostingIntegrations ] : undefined ,
1149+ ) ,
1150+ setContext (
1151+ 'gitlens:repos:withHostingIntegrationsConnected' ,
1152+ reposWithHostingIntegrationsConnected . size ? [ ...reposWithHostingIntegrationsConnected ] : undefined ,
1153+ ) ,
11401154 ] ) ;
11411155 }
11421156
0 commit comments