Skip to content

Commit 93fcdc2

Browse files
committed
Creates branch suggesting a name based on selected issue
(#3621)
1 parent afe9b79 commit 93fcdc2

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/plus/startWork/startWork.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
QuickCommand,
1717
StepResultBreak,
1818
} from '../../commands/quickCommand';
19+
import { getSteps } from '../../commands/quickWizard.utils';
1920
import { proBadge } from '../../constants';
2021
import type { IntegrationId } from '../../constants.integrations';
2122
import { HostingIntegrationId } from '../../constants.integrations';
@@ -24,7 +25,7 @@ import type { SearchedIssue } from '../../git/models/issue';
2425
import type { QuickPickItemOfT } from '../../quickpicks/items/common';
2526
import { createQuickPickItemOfT, createQuickPickSeparator } from '../../quickpicks/items/common';
2627
import type { DirectiveQuickPickItem } from '../../quickpicks/items/directive';
27-
import { createDirectiveQuickPickItem, Directive } from '../../quickpicks/items/directive';
28+
import { createDirectiveQuickPickItem, Directive, isDirectiveQuickPickItem } from '../../quickpicks/items/directive';
2829
import { fromNow } from '../../system/date';
2930
import { some } from '../../system/iterable';
3031
import { configuration } from '../../system/vscode/configuration';
@@ -114,17 +115,32 @@ export class StartWorkCommand extends QuickCommand<State> {
114115

115116
assertsStartWorkStepState(state);
116117

117-
if (this.confirm(state.confirm)) {
118+
if (state.action == null && this.confirm(state.confirm)) {
118119
const result = yield* this.confirmStep(state, context);
119-
if (result === StepResultBreak) continue;
120+
if (result === StepResultBreak) {
121+
state.item = undefined!;
122+
continue;
123+
}
120124

121125
state.action = result;
122126
}
123127

124128
if (typeof state.action === 'string') {
125129
switch (state.action) {
126130
case 'start':
127-
startWork(state.item.item);
131+
yield* getSteps(
132+
this.container,
133+
{
134+
command: 'branch',
135+
state: {
136+
subcommand: 'create',
137+
repo: undefined,
138+
name: `${state.item.item.issue.id}-${state.item.item.issue.title}`,
139+
suggestNameOnly: true,
140+
},
141+
},
142+
this.pickedVia,
143+
);
128144
break;
129145
}
130146
}
@@ -311,8 +327,10 @@ export class StartWorkCommand extends QuickCommand<State> {
311327
items: items,
312328
onDidClickItemButton: (_quickpick, button, { item }) => {
313329
if (button === StartWorkQuickInputButton) {
314-
startWork(item.item);
330+
this.startWork(state, item);
331+
return true;
315332
}
333+
return false;
316334
},
317335
});
318336

@@ -364,9 +382,11 @@ export class StartWorkCommand extends QuickCommand<State> {
364382
onDidClickItemButton: (_quickpick, button, _item) => {
365383
switch (button) {
366384
case StartWorkQuickInputButton:
367-
startWork(state.item.item);
368-
break;
385+
if (isDirectiveQuickPickItem(_item)) return;
386+
this.startWork(state);
387+
return true;
369388
}
389+
return false;
370390
},
371391
},
372392
);
@@ -375,6 +395,13 @@ export class StartWorkCommand extends QuickCommand<State> {
375395
return canPickStepContinue(step, state, selection) ? selection[0].item : StepResultBreak;
376396
}
377397

398+
private startWork(state: PartialStepState<State>, item?: StartWorkItem) {
399+
state.action = 'start';
400+
if (item != null) {
401+
state.item = item;
402+
}
403+
}
404+
378405
private async getConnectedIntegrations(): Promise<Map<IntegrationId, boolean>> {
379406
const connected = new Map<IntegrationId, boolean>();
380407
await Promise.allSettled(
@@ -396,7 +423,3 @@ async function updateContextItems(container: Container, context: Context) {
396423
})) ?? [],
397424
};
398425
}
399-
400-
function startWork(_issue: SearchedIssue) {
401-
// TODO: Hack here
402-
}

0 commit comments

Comments
 (0)