Skip to content

Commit afe9b79

Browse files
committed
Connects using a different flow when cloudIntegrations are disabled.
(#3621)
1 parent 00998ee commit afe9b79

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/plus/startWork/startWork.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
2727
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
2828
import { fromNow } from '../../system/date';
2929
import { some } from '../../system/iterable';
30+
import { configuration } from '../../system/vscode/configuration';
3031

3132
export type StartWorkItem = {
3233
item: SearchedIssue;
@@ -94,7 +95,10 @@ export class StartWorkCommand extends QuickCommand<State> {
9495

9596
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
9697
if (!hasConnectedIntegrations) {
97-
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
98+
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
99+
const result = isUsingCloudIntegrations
100+
? yield* this.confirmCloudIntegrationsConnectStep(state, context)
101+
: yield* this.confirmLocalIntegrationConnectStep(state, context);
98102
if (result === StepResultBreak) {
99103
return result;
100104
}
@@ -131,6 +135,72 @@ export class StartWorkCommand extends QuickCommand<State> {
131135
return state.counter < 0 ? StepResultBreak : undefined;
132136
}
133137

138+
private async *confirmLocalIntegrationConnectStep(
139+
state: StepState<State>,
140+
context: Context,
141+
): AsyncStepResultGenerator<{ connected: boolean | IntegrationId; resume: () => void }> {
142+
const confirmations: (QuickPickItemOfT<IntegrationId> | DirectiveQuickPickItem)[] = [];
143+
144+
for (const integration of supportedStartWorkIntegrations) {
145+
if (context.connectedIntegrations.get(integration)) {
146+
continue;
147+
}
148+
switch (integration) {
149+
case HostingIntegrationId.GitHub:
150+
confirmations.push(
151+
createQuickPickItemOfT(
152+
{
153+
label: 'Connect to GitHub...',
154+
detail: 'Will connect to GitHub to provide access your pull requests and issues',
155+
},
156+
integration,
157+
),
158+
);
159+
break;
160+
default:
161+
break;
162+
}
163+
}
164+
165+
const step = this.createConfirmStep(
166+
`${this.title} \u00a0\u2022\u00a0 Connect an Integration`,
167+
confirmations,
168+
createDirectiveQuickPickItem(Directive.Cancel, false, { label: 'Cancel' }),
169+
{
170+
placeholder: 'Connect an integration to view their issues in Start Work',
171+
buttons: [],
172+
ignoreFocusOut: false,
173+
},
174+
);
175+
176+
// Note: This is a hack to allow the quickpick to stay alive after the user finishes connecting the integration.
177+
// Otherwise it disappears.
178+
let freeze!: () => Disposable;
179+
step.onDidActivate = qp => {
180+
freeze = () => freezeStep(step, qp);
181+
};
182+
183+
const selection: StepSelection<typeof step> = yield step;
184+
if (canPickStepContinue(step, state, selection)) {
185+
const resume = freeze();
186+
const chosenIntegrationId = selection[0].item;
187+
const connected = await this.ensureIntegrationConnected(chosenIntegrationId);
188+
return { connected: connected ? chosenIntegrationId : false, resume: () => resume[Symbol.dispose]() };
189+
}
190+
191+
return StepResultBreak;
192+
}
193+
194+
private async ensureIntegrationConnected(id: IntegrationId) {
195+
const integration = await this.container.integrations.get(id);
196+
let connected = integration.maybeConnected ?? (await integration.isConnected());
197+
if (!connected) {
198+
connected = await integration.connect('startWork');
199+
}
200+
201+
return connected;
202+
}
203+
134204
private async *confirmCloudIntegrationsConnectStep(
135205
state: StepState<State>,
136206
context: Context,

0 commit comments

Comments
 (0)