Skip to content

Commit 8786292

Browse files
sergeibbbchivorotkiv
authored andcommitted
Connects using a different flow when cloudIntegrations are disabled.
(#3621, #3698)
1 parent c31d910 commit 8786292

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;
@@ -93,7 +94,10 @@ export class StartWorkCommand extends QuickCommand<State> {
9394

9495
const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
9596
if (!hasConnectedIntegrations) {
96-
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
97+
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
98+
const result = isUsingCloudIntegrations
99+
? yield* this.confirmCloudIntegrationsConnectStep(state, context)
100+
: yield* this.confirmLocalIntegrationConnectStep(state, context);
97101
if (result === StepResultBreak) {
98102
return result;
99103
}
@@ -124,6 +128,72 @@ export class StartWorkCommand extends QuickCommand<State> {
124128
return state.counter < 0 ? StepResultBreak : undefined;
125129
}
126130

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

0 commit comments

Comments
 (0)