Skip to content

Commit

Permalink
Connects using a different flow when cloudIntegrations are disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeibbb committed Nov 8, 2024
1 parent a43e5bc commit 64b702c
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion src/plus/startWork/startWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { createQuickPickItemOfT } from '../../quickpicks/items/common';
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
import { fromNow } from '../../system/date';
import { some } from '../../system/iterable';
import { configuration } from '../../system/vscode/configuration';

export type StartWorkItem = {
item: SearchedIssue;
Expand Down Expand Up @@ -93,7 +94,10 @@ export class StartWorkCommand extends QuickCommand<State> {

const hasConnectedIntegrations = [...context.connectedIntegrations.values()].some(c => c);
if (!hasConnectedIntegrations) {
const result = yield* this.confirmCloudIntegrationsConnectStep(state, context);
const isUsingCloudIntegrations = configuration.get('cloudIntegrations.enabled', undefined, false);
const result = isUsingCloudIntegrations
? yield* this.confirmCloudIntegrationsConnectStep(state, context)
: yield* this.confirmLocalIntegrationConnectStep(state, context);
if (result === StepResultBreak) {
return result;
}
Expand Down Expand Up @@ -124,6 +128,72 @@ export class StartWorkCommand extends QuickCommand<State> {
return state.counter < 0 ? StepResultBreak : undefined;
}

private async *confirmLocalIntegrationConnectStep(
state: StepState<State>,
context: Context,
): AsyncStepResultGenerator<{ connected: boolean | IntegrationId; resume: () => void }> {
const confirmations: (QuickPickItemOfT<IntegrationId> | DirectiveQuickPickItem)[] = [];

for (const integration of supportedStartWorkIntegrations) {
if (context.connectedIntegrations.get(integration)) {
continue;
}
switch (integration) {
case HostingIntegrationId.GitHub:
confirmations.push(
createQuickPickItemOfT(
{
label: 'Connect to GitHub...',
detail: 'Will connect to GitHub to provide access your pull requests and issues',
},
integration,
),
);
break;
default:
break;
}
}

const step = this.createConfirmStep(
`${this.title} \u00a0\u2022\u00a0 Connect an Integration`,
confirmations,
createDirectiveQuickPickItem(Directive.Cancel, false, { label: 'Cancel' }),
{
placeholder: 'Connect an integration to view their issues in Start Work',
buttons: [],
ignoreFocusOut: false,
},
);

// Note: This is a hack to allow the quickpick to stay alive after the user finishes connecting the integration.
// Otherwise it disappears.
let freeze!: () => Disposable;
step.onDidActivate = qp => {
freeze = () => freezeStep(step, qp);
};

const selection: StepSelection<typeof step> = yield step;
if (canPickStepContinue(step, state, selection)) {
const resume = freeze();
const chosenIntegrationId = selection[0].item;
const connected = await this.ensureIntegrationConnected(chosenIntegrationId);
return { connected: connected ? chosenIntegrationId : false, resume: () => resume[Symbol.dispose]() };
}

return StepResultBreak;
}

private async ensureIntegrationConnected(id: IntegrationId) {
const integration = await this.container.integrations.get(id);
let connected = integration.maybeConnected ?? (await integration.isConnected());
if (!connected) {
connected = await integration.connect('startWork');
}

return connected;
}

private async *confirmCloudIntegrationsConnectStep(
state: StepState<State>,
context: Context,
Expand Down

0 comments on commit 64b702c

Please sign in to comment.