Skip to content

Commit e21b34a

Browse files
committed
Connects using a different flow when cloudIntegrations are disabled.
(#3621, #3698)
1 parent e11995a commit e21b34a

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
@@ -26,6 +26,7 @@ import { createQuickPickItemOfT } from '../../quickpicks/items/common';
2626
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
2727
import { fromNow } from '../../system/date';
2828
import { some } from '../../system/iterable';
29+
import { configuration } from '../../system/vscode/configuration';
2930

3031
export type StartWorkItem = {
3132
item: SearchedIssue;
@@ -88,7 +89,10 @@ export class StartWorkCommand extends QuickCommand<State> {
8889

8990
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
9091
if (!hasConnectedIntegrations) {
91-
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
92+
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
93+
const result = isUsingCloudIntegrations
94+
? yield* this.confirmCloudIntegrationsConnectStep(state, context)
95+
: yield* this.confirmLocalIntegrationConnectStep(state, context);
9296
if (result === StepResultBreak) {
9397
return result;
9498
}
@@ -119,6 +123,72 @@ export class StartWorkCommand extends QuickCommand<State> {
119123
return state.counter < 0 ? StepResultBreak : undefined;
120124
}
121125

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

0 commit comments

Comments
 (0)