@@ -35,6 +35,7 @@ import { getScopedCounter } from '../../system/counter';
3535import { fromNow } from '../../system/date' ;
3636import { some } from '../../system/iterable' ;
3737import { executeCommand } from '../../system/vscode/command' ;
38+ import { configuration } from '../../system/vscode/configuration' ;
3839
3940export type StartWorkItem = {
4041 item : SearchedIssue ;
@@ -126,7 +127,10 @@ export class StartWorkCommand extends QuickCommand<State> {
126127 this . source ,
127128 ) ;
128129 }
129- const result = yield * this . confirmCloudIntegrationsConnectStep ( state , context ) ;
130+ const isUsingCloudIntegrations = configuration . get ( 'cloudIntegrations.enabled' , undefined , false ) ;
131+ const result = isUsingCloudIntegrations
132+ ? yield * this . confirmCloudIntegrationsConnectStep ( state , context )
133+ : yield * this . confirmLocalIntegrationConnectStep ( state , context ) ;
130134 if ( result === StepResultBreak ) {
131135 return result ;
132136 }
@@ -180,6 +184,86 @@ export class StartWorkCommand extends QuickCommand<State> {
180184 return state . counter < 0 ? StepResultBreak : undefined ;
181185 }
182186
187+ private async * confirmLocalIntegrationConnectStep (
188+ state : StepState < State > ,
189+ context : Context ,
190+ ) : AsyncStepResultGenerator < { connected : boolean | IntegrationId ; resume : ( ) => void } > {
191+ const confirmations : ( QuickPickItemOfT < IntegrationId > | DirectiveQuickPickItem ) [ ] = [
192+ createDirectiveQuickPickItem ( Directive . Cancel , undefined , {
193+ label : 'Start Work lets you start work on an issue' ,
194+ detail : 'Click to learn more about Start Work' ,
195+ iconPath : new ThemeIcon ( 'rocket' ) ,
196+ onDidSelect : ( ) =>
197+ // TODO: navigate to "start-work" related place
198+ void executeCommand < OpenWalkthroughCommandArgs > ( Commands . OpenWalkthrough , {
199+ step : 'launchpad' ,
200+ source : 'launchpad' ,
201+ detail : 'info' ,
202+ } ) ,
203+ } ) ,
204+ createQuickPickSeparator ( ) ,
205+ ] ;
206+
207+ for ( const integration of supportedStartWorkIntegrations ) {
208+ if ( context . connectedIntegrations . get ( integration ) ) {
209+ continue ;
210+ }
211+ switch ( integration ) {
212+ case HostingIntegrationId . GitHub :
213+ confirmations . push (
214+ createQuickPickItemOfT (
215+ {
216+ label : 'Connect to GitHub...' ,
217+ detail : 'Will connect to GitHub to provide access your pull requests and issues' ,
218+ } ,
219+ integration ,
220+ ) ,
221+ ) ;
222+ break ;
223+ default :
224+ break ;
225+ }
226+ }
227+
228+ const step = this . createConfirmStep (
229+ `${ this . title } \u00a0\u2022\u00a0 Connect an Integration` ,
230+ confirmations ,
231+ createDirectiveQuickPickItem ( Directive . Cancel , false , { label : 'Cancel' } ) ,
232+ {
233+ placeholder : 'Connect an integration to view their issues in Start Work' ,
234+ buttons : [ ] ,
235+ ignoreFocusOut : false ,
236+ } ,
237+ ) ;
238+
239+ // Note: This is a hack to allow the quickpick to stay alive after the user finishes connecting the integration.
240+ // Otherwise it disappears.
241+ let freeze ! : ( ) => Disposable ;
242+ step . onDidActivate = qp => {
243+ freeze = ( ) => freezeStep ( step , qp ) ;
244+ } ;
245+
246+ const selection : StepSelection < typeof step > = yield step ;
247+ if ( canPickStepContinue ( step , state , selection ) ) {
248+ const resume = freeze ( ) ;
249+ const chosenIntegrationId = selection [ 0 ] . item ;
250+ const connected = await this . ensureIntegrationConnected ( chosenIntegrationId ) ;
251+ return { connected : connected ? chosenIntegrationId : false , resume : ( ) => resume [ Symbol . dispose ] ( ) } ;
252+ }
253+
254+ return StepResultBreak ;
255+ }
256+
257+ private async ensureIntegrationConnected ( id : IntegrationId ) {
258+ const integration = await this . container . integrations . get ( id ) ;
259+ let connected = integration . maybeConnected ?? ( await integration . isConnected ( ) ) ;
260+ if ( ! connected ) {
261+ connected = await integration . connect ( 'startWork' ) ;
262+ }
263+
264+ return connected ;
265+ }
266+
183267 private async * confirmCloudIntegrationsConnectStep (
184268 state : StepState < State > ,
185269 context : Context ,
0 commit comments